EXPERIMENTAL features to report back the status of the connection. If e.g. a false password is entered, this is reported back to the portal page, so the user can correct his failure without having to reconnect. Also a successful connection is reported back.
Attention: not tested on an ESP8266 yet, only on a ESP32 (although I do not expect too many issues)
To try this you should:
erase your browser history (if you tried this portal before), because otherwise the HTML may be loaded from browser history
upload the modified '/data' directory to SPIFFS
Start basic_rest_api_reporter.ino
Connect with the Access Point with SSID ESP32 (or ESP8266)
If this works, comment this line in setup():
persWM.resetSettings();
Beause calling resetSettings() will clear any previously entered WiFi credentials. If you do not call this, the WiFi credentials are saved in non volatile memory. If the library can connect to a previously configured WiFi network it will not show the portal at all!
After a successful connection to a WiFi network is made, the ESP32 / ESP8266 will remain in dual mode (STA and AP). You can close the AP by calling PersWiFiManager::closeAp(), or, from the browser, do a GET at wifi/closeap.
Reporting the status of the WiFi connection back to the browser client is done with a json at wifi/report. This JSON has more data than only the connection status:
{ connection: true or false, SSID: the SSID of the WiFi network the ESP32 / ESP8266 is connected to (if connection == true), APSSID: the SSID of the ESP32 / ESP8266 itself, if in AP mode, IP: the IP address assigned to the ESP32 / ESP8266, if connected to a WiFi network }
Attention: connection: is always present, the other fields may be undefined
I am still somewhat unsatisfied with leaving the AP mode activated after connecting to a WiFi network, but:
If I close it, I can not report back the status. Also the client still has HTML with buttons, but it will not respond anymore because the server is 'gone'
I could forward to the same page, but now on the WiFi network (since the ESP32 / ESP8266 is connected). However, the telephone or other device that is being used for passingthe WiFi credentials may itself NOT be connected to that WiFi network. Also timing before moving to 'the other page' is crucial, and probably not consistent between clients / devices / browsers
So for now I leave it up to you when to close the AP, maybe after some 5 minutes?
If it fails, it sets up an Access Point (AP mode), for the number of minutes passed to the library with ::begin(). After this number of minutes, the AP mode is closed
If the ESP connects to the WiFi network successfully AND the client disconnects from the ESP AP, AP mode is also closed
Some other changes:
server.begin() is moved to library
::stop() is added. This stops both the DNS server and the web server
::onApClose() is added. This call back function gets called after AP mode is closed
EXPERIMENTAL features to report back the status of the connection. If e.g. a false password is entered, this is reported back to the portal page, so the user can correct his failure without having to reconnect. Also a successful connection is reported back.
Attention: not tested on an ESP8266 yet, only on a ESP32 (although I do not expect too many issues)
To try this you should:
This will take you to the modfied AP portal.
If this works, comment this line in setup():
persWM.resetSettings();
Beause calling resetSettings() will clear any previously entered WiFi credentials. If you do not call this, the WiFi credentials are saved in non volatile memory. If the library can connect to a previously configured WiFi network it will not show the portal at all!After a successful connection to a WiFi network is made, the ESP32 / ESP8266 will remain in dual mode (STA and AP). You can close the AP by calling PersWiFiManager::closeAp(), or, from the browser, do a GET at wifi/closeap.
Reporting the status of the WiFi connection back to the browser client is done with a json at wifi/report. This JSON has more data than only the connection status:
{ connection: true or false, SSID: the SSID of the WiFi network the ESP32 / ESP8266 is connected to (if connection == true), APSSID: the SSID of the ESP32 / ESP8266 itself, if in AP mode, IP: the IP address assigned to the ESP32 / ESP8266, if connected to a WiFi network }
Attention: connection: is always present, the other fields may be undefined
I am still somewhat unsatisfied with leaving the AP mode activated after connecting to a WiFi network, but: