Description
Basic Infos
Issue with the WPS connection
Hardware
Hardware: ESP-12
Core Version: 2.3
Description
Steps to reproduce:
- Put a WiFi router into WPS mode to accept WPS connections
- On ESP8266 device that does not have a saved WiFi connection, run WiFi.beginWPSConfig(). (Device successfully connects via WPS to a WiFi endpoint)
- Each subsequent connection it works fine if WiFi in step 1 is available to connect
- Power the WiFi endpoint off and repeat step 2 (this erases saved WiFi SSID and credentials)
- Power WiFi router back on
- Device is unable to connect because it no longer knows about the WiFi router until
Use case is :
- Device turns on and tries to connect to WiFi
2a) If device finds its saved connection, don't initiate WPS - If can't connect to its saved connection, initiate WPS automatically.
This way the wps configuration is easier for users who are trying to initialize a new device.
In the event of a power outage or temporary outage of wifi, current behavior will disable the esp8266 networking capabilities until WPS handshake is re-initiated
Settings in IDE
Module: ?Generic ESP8266 Module?
Flash Size: ?4MB/1MB?
CPU Frequency: ?80Mhz?
Flash Mode: ?qio?
Flash Frequency: ?40Mhz?
Upload Using: ?OTA / SERIAL?
Reset Method: ?ck / nodemcu?
Sketch
...
//----------------------------
//-- void initWPS(){
bool initWPS() {
// Attempt a WPS configuration
// Response codes 3 flashes for success(green) fail(red)
bool returnValue = false;
String StoredSSID = WiFi.SSID().c_str();
String StoredPSK = WiFi.psk().c_str();
// Light both LEDs
digitalWrite(RedLED, HIGH);
digitalWrite(GreenLED, HIGH);
if (!startWPSPBC()) {
// WPS Negotiation failed
digitalWrite(GreenLED, LOW);
digitalWrite(RedLED, LOW);
delay(500);
flashRed(3);
if (devMode) {
Serial.print("WiFi.status() after WPS Failure: ");
Serial.println(WiFi.status());
}
}
else {
//WPS returned success
digitalWrite(GreenLED, LOW);
digitalWrite(RedLED, LOW);
// Validate that we can connect to WiFi
delay(2000);
if (devMode) {
Serial.print("WiFi.status() after WPS Success: ");
Serial.println(WiFi.status());
}
// WL_DISCONNECTED means it is ready for a WiFi.begin() method call.
if (WiFi.status() == WL_DISCONNECTED) {
returnValue = true;
delay(200);
flashGreen(3);
}
else {
// Even though WPS says it succeeded,
// we were not able to connect
flashRed(3);
if (devMode) {
Serial.println("Failed to connect with WPS");
}
}
}
return returnValue;
}
//----------------------------
//----------------------------
//----------------------------
//-- startWPSPBC
bool startWPSPBC() {
if (devMode) {
Serial.println("WPS config start");
}
bool wpsSuccess = WiFi.beginWPSConfig();
if (wpsSuccess && WiFi.status() == WL_CONNECTED) {
if (devMode) {
Serial.printf("WPS finished. Connected successfull to SSID '%s'\n", WiFi.SSID().c_str());
} else {
wpsSuccess = false;
if (devMode) {
Serial.printf("WPS Connect Failed");
}
}
}
return wpsSuccess;
}
...
RECOMMENDED CHANGE TO ESP8266WiFiSTAClass::disconnect:
/**
-
Disconnect from the network
-
@param wifioff
-
@return one value of wl_status_t enum
*/
bool ESP8266WiFiSTAClass::disconnect(bool wifioff) {
bool ret;// from hoekma - remove to prevent losing WPS configuration
// struct station_config conf;
// *conf.ssid = 0;
// *conf.password = 0;ETS_UART_INTR_DISABLE();
// from hoekma - remove to prevent losing WPS configuration
//if(WiFi._persistent) {
// wifi_station_set_config(&conf);
//} else {
// wifi_station_set_config_current(&conf);
//}ret = wifi_station_disconnect();
ETS_UART_INTR_ENABLE();if(wifioff) {
WiFi.enableSTA(false);
}return ret;
}