Suggest SSID name when configuring Wifi Details
This commit is contained in:
parent
810c9b881c
commit
a68a207fa1
@ -45,6 +45,27 @@ void WebSendError(const char *error) {
|
||||
server.send(500, "text/plain", error);
|
||||
}
|
||||
|
||||
void WebBuildSSIDList(String &datalist){
|
||||
int n = WiFi.scanNetworks();
|
||||
datalist = "<datalist id=\"scan_ssid\">";
|
||||
// sort by RSSI
|
||||
int indices[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
indices[i] = i;
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
|
||||
std::swap(indices[i], indices[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < n; ++i){
|
||||
datalist += "<option value=\""+WiFi.SSID(indices[i])+"\">";
|
||||
}
|
||||
datalist += "</datalist>";
|
||||
}
|
||||
|
||||
void WebHandleSetup() {
|
||||
uint8_t mode;
|
||||
char *confSsid = "";
|
||||
@ -61,13 +82,17 @@ void WebHandleSetup() {
|
||||
uint32_t dns = 0;
|
||||
uint32_t dns2 = 0;
|
||||
|
||||
String ssidlist;
|
||||
WebBuildSSIDList(ssidlist);
|
||||
|
||||
EepromReadConfig(mode, &confSsid, &confPassword, &confHost, &mqttServer, &mqttUser, &mqttPasswd, mqttPort, ip_config, ip, gw, mask, dns, dns2);
|
||||
|
||||
server.send(200, "text/html", "<form action=\"/save\" method=\"get\">"
|
||||
"<fieldset>"
|
||||
"<legend>Wifi configuration:</legend>"
|
||||
"<div><label for=\"ssid\">Wifi SSID :</label> <br/><input type=\"text\" name=\"ssid\" value=\"" + String(confSsid) + "\" /></div>"
|
||||
"<div><label for=\"password\">Wifi Password :</label><br/><input type=\"password\" name=\"password\" /> </div>"
|
||||
"<div><label for=\"ssid\">Wifi SSID :</label> <br/><input list=\"scan_ssid\" type=\"text\" name=\"ssid\" value=\"" + String(confSsid) + "\" /></div>"
|
||||
"" + ssidlist + ""
|
||||
"<div><label for=\"password\">Wifi Password :</label><br/><input type=\"password\" name=\"password\" style=\"border-color:red\" /> </div>"
|
||||
"<div><label for=\"host\">Hostname :</label><br/><input type=\"text\" name=\"host\" value=\"" + String(confHost) + "\" /> </div>"
|
||||
"</fieldset>"
|
||||
"<fieldset>"
|
||||
@ -83,7 +108,7 @@ void WebHandleSetup() {
|
||||
"<legend>MQTT:</legend>"
|
||||
"<div><label for=\"mqttServer\">Server :</label><br/><input type=\"text\" name=\"mqttServer\" value=\"" + String(mqttServer) + "\" /> </div>"
|
||||
"<div><label for=\"mqttUser\">Username :</label><br/><input type=\"text\" name=\"mqttUser\" value=\"" + String(mqttUser) + "\" /> </div>"
|
||||
"<div><label for=\"mqttPasswd\">Password :</label><br/><input type=\"password\" name=\"mqttPasswd\" /> </div>"
|
||||
"<div><label for=\"mqttPasswd\">Password :</label><br/><input type=\"password\" name=\"mqttPasswd\" style=\"border-color:red\" /> </div>"
|
||||
"<div><label for=\"mqttPort\">Port :</label><br/><input type=\"text\" name=\"mqttPort\" value=\"" + String(mqttPort) + "\" /> </div>"
|
||||
"</fieldset>"
|
||||
"<div class=\"button\"> <button type=\"submit\">Save</button></div>"
|
||||
|
Loading…
Reference in New Issue
Block a user