tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.52k stars 1.96k forks source link

WPS WorkaRound #367

Open Melcos1970 opened 7 years ago

Melcos1970 commented 7 years ago

I have made a small change to WiFiManager.cpp and .h to get a mid-term solution to the problem with WPS. It's not the best way, but now you can use WPS if you are going to .. I have no idea how to add suggestions to github, but I want to post them here so can add them if you want to use them. The solution is actually simple .. I just add a button extra that makes a WPS call.

Changed: Const char HTTP_PORTAL_OPTIONS [] PROGMEM = "<form action = \" / wifi \ "method = \" get \ ">

bkrajendra commented 7 years ago

The main problem with WPS that i found is that it does not retain its password on reset. Did you get this issue?

Melcos1970 commented 7 years ago

No not with WiFiManager.. My problem is if the WPS fail to connect and the go back til normal state, that is why i make a reboot after using WPS.

tablatronix commented 7 years ago

I know this is old but can you post your code in code blocks please use three ticks open and close

MarcUbb commented 1 year ago

Hey, I think I found a solution to the WPS problem! The problem is that the device doesnt wait for the WPS setup (which can take some time) to be completed. Therefore I simply put a while loop that checks if the setup was completed like so: (includes a timeout after 30s)

WiFi.mode(WIFI_STA);
bool wpsSuccess = WiFi.beginWPSConfig();
if(wpsSuccess) {
  String newSSID = WiFi.SSID();
  if(newSSID.length() > 0) {
    DEBUG_WM(F("WPS Success"));
    unsigned long start = millis();
    while (WiFi.status() != WL_CONNECTED && millis() - start < 30000) {
      yield();
    }
    if (WiFi.status() == WL_CONNECTED) {
      DEBUG_WM(F("WPS Connected"));
      connect = true;
      ESP.reset();
    } else {
      DEBUG_WM(F("WPS Failed"));
      connect = false;
    }
  } else {
    DEBUG_WM(F("WPS Failed"));
    connect = false;
  }
}

Just put this code instead of:

WiFi.mode (WIFI_STA);
delay (1000);
startWPS ();
delay (5000);
ESP.reset ();
delay (2000);

and it should work (at least on my machine)

tablatronix commented 1 year ago

Does anyone still use WPS, isnt it a vulnerability