khoih-prog / ESP_WiFiManager

This is an ESP32 / ESP8266 WiFi Connection Manager with fallback web configuration portal. Use this library for configuring ESP32 (including ESP32-S2 and ESP32-C3), ESP8266 modules' WiFi, etc. Credentials at runtime. You can also specify static DNS servers, personalized HostName, fixed or random AP WiFi channel. With examples supporting ArduinoJson
MIT License
371 stars 97 forks source link

Question about functioning of Configure page #11

Closed JMWilton closed 4 years ago

JMWilton commented 4 years ago

I am have been studying the source code and have a question. When you "click" on one of the hyperlinks in the networks found list, it populates the SSID field automatically. I have been studying the code and the html page and don't understand how this works. I am trying to duplicate this functionality in one of my own pages and haven't been successful. Can you provide a explanation of how to duplicate this functionality?

Thanks in advance for your help.

khoih-prog commented 4 years ago

As you know, your question has nothing to do with the working issue of the library, and I thought I'd not answer and would close the issue. Reading once more, thanks to your nice words and willingness to learn, I then think I'll try my best to help you out.

The way it's doing is:

  1. In scanWifiNetworks()

    • Scan the available network APs (SSID, RSSI, encryption (WPA/WPA2, etc.) or open).
    • Store them in a dynamically allocated indices array
    • Sort according to RSSI. Delete AP with RSSI less than minimumQuality
  2. in handleScan()

    • Go thru every item in indices array
    • Replace corresponding data in JSON_ITEM with current data from AP (SSID, RSSI, Encryption type) using String replace() function.

For example, to replace {v} in JSON_ITEM with actual WiFi.SSID const char JSON_ITEM[] PROGMEM = "{\"SSID\":\"{v}\", \"Encryption\":{i}, \"Quality\":\"{r}\"}"; item.replace("{v}", WiFi.SSID(indices[i]));

String page = F("{\"Access_Points\":["); .... for (int i = 0; i < n; i++) { ... page += item; }

server->send(200, "application/json", page);

Hope when you finish your work, you'll post the link so that I can use somehow.