1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-25 20:02:37 +03:00

add basic WPS function

This commit is contained in:
Markus Sattler 2015-07-04 10:30:11 +02:00
parent 36a4131f35
commit 1aa8e8e6c8
4 changed files with 102 additions and 8 deletions

View File

@ -20,6 +20,7 @@
*/
#include "ESP8266WiFi.h"
extern "C" {
#include "c_types.h"
#include "ets_sys.h"
@ -155,7 +156,7 @@ void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress s
_useStaticIp = true;
}
int ESP8266WiFiClass::disconnect()
int ESP8266WiFiClass::disconnect(bool wifioff)
{
struct station_config conf;
*conf.ssid = 0;
@ -164,6 +165,19 @@ int ESP8266WiFiClass::disconnect()
wifi_station_set_config(&conf);
wifi_station_disconnect();
ETS_UART_INTR_ENABLE();
if(wifioff) {
_useClientMode = false;
if(_useApMode) {
// turn on AP
mode(WIFI_AP);
} else {
// turn wifi off
mode(WIFI_OFF);
}
}
return 0;
}
@ -601,6 +615,77 @@ bool ESP8266WiFiClass::hostname(String aHostname) {
return hostname((char*) aHostname.c_str());
}
//--------------------------------------------------------------
void wifi_wps_status_cb(WPS_CB_STATUS_t status)
{
DEBUGV("wps cb status: %d\r\n", status);
switch (status) {
case WPS_CB_ST_SUCCESS:
if(!wifi_wps_disable()) {
DEBUGV("wps disable faild\n");
}
wifi_station_connect();
break;
case WPS_CB_ST_FAILED:
DEBUGV("wps FAILD\n");
break;
case WPS_CB_ST_TIMEOUT:
DEBUGV("wps TIMEOUT\n");
break;
}
// todo user function to get status
esp_schedule(); // resume the beginWPSConfig function
}
bool ESP8266WiFiClass::beginWPSConfig(void) {
_useClientMode = true;
if(_useApMode) {
// turn on AP+STA mode
mode(WIFI_AP_STA);
} else {
// turn on STA mode
mode(WIFI_STA);
}
disconnect();
DEBUGV("wps begin: %d\n", wps_type);
if(!wifi_wps_disable()) {
DEBUGV("wps disable faild\n");
return false;
}
// so far only WPS_TYPE_PBC is supported (SDK 1.2.0)
if(!wifi_wps_enable(WPS_TYPE_PBC)) {
DEBUGV("wps enable faild\n");
return false;
}
if(!wifi_set_wps_cb(&wifi_wps_status_cb)) {
DEBUGV("wps cb faild\n");
return false;
}
if(!wifi_wps_start()) {
DEBUGV("wps start faild\n");
return false;
}
esp_yield();
// will return here when wifi_wps_status_cb fires
return true;
}
//--------------------------------------------------------------
void ESP8266WiFiClass::beginSmartConfig()
{
if (_smartConfigStarted)
@ -655,6 +740,8 @@ void ESP8266WiFiClass::_smartConfigCallback(uint32_t st, void* result)
}
}
//--------------------------------------------------------------
void ESP8266WiFiClass::_eventCallback(void* arg)
{
System_Event_t* event = reinterpret_cast<System_Event_t*>(arg);

View File

@ -109,7 +109,7 @@ public:
*
* return: one value of wl_status_t enum
*/
int disconnect(void);
int disconnect(bool wifioff = false);
/*
* Get the station interface MAC address.
@ -313,6 +313,13 @@ public:
bool hostname(const char* aHostname);
bool hostname(String aHostname);
/**
* WPS config
* so far only WPS_TYPE_PBC is supported (SDK 1.2.0)
*/
bool beginWPSConfig(void);
/*
* Output WiFi settings to an object derived from Print interface (like Serial).
*

View File

@ -24,7 +24,7 @@ compiler.S.flags=-c -g -x assembler-with-cpp -MMD
compiler.c.elf.flags=-g -Os -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-T{build.flash_ld}" -Wl,-wrap,system_restart_local -Wl,-wrap,register_chipv6_phy
compiler.c.elf.cmd=xtensa-lx106-elf-gcc
compiler.c.elf.libs=-lm -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig -lwps
compiler.c.elf.libs=-lm -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig -lwps -lcrypto
compiler.cpp.cmd=xtensa-lx106-elf-g++
compiler.cpp.flags=-c -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD

View File

@ -427,20 +427,20 @@ typedef enum wps_type {
WPS_TYPE_PBC,
WPS_TYPE_PIN,
WPS_TYPE_DISPLAY,
WPS_TYPE_MAX,
WPS_TYPE_MAX
} WPS_TYPE_t;
enum wps_cb_status {
typedef enum wps_cb_status {
WPS_CB_ST_SUCCESS = 0,
WPS_CB_ST_FAILED,
WPS_CB_ST_TIMEOUT,
};
WPS_CB_ST_TIMEOUT
} WPS_CB_STATUS_t;
bool wifi_wps_enable(WPS_TYPE_t wps_type);
bool wifi_wps_disable(void);
bool wifi_wps_start(void);
typedef void (*wps_st_cb_t)(int status);
typedef void (*wps_st_cb_t)(WPS_CB_STATUS_t status);
bool wifi_set_wps_cb(wps_st_cb_t cb);
#endif