diff --git a/ESP32-SOCKETIO.ino b/ESP32-SOCKETIO.ino index ff8f4cf..f41a39a 100644 --- a/ESP32-SOCKETIO.ino +++ b/ESP32-SOCKETIO.ino @@ -9,6 +9,7 @@ int BUTTON_BUILTIN = 0; bool disconnected = false; +bool readyToReset = false; unsigned long wificheckMillis; unsigned long wifiCheckTime = 5000; diff --git a/JSONHandling.ino b/JSONHandling.ino index ac90d85..1db4b6e 100644 --- a/JSONHandling.ino +++ b/JSONHandling.ino @@ -131,9 +131,20 @@ void addToWiFiJSON(String newSSID, String newPassword) { inList = false; for ( int i = 0; i < ssids.size(); i++) { if (ssids[i] == newSSID) { - inList = true; Serial.println("wifi credentials already in list"); - break; + if (passwords[i] == newPassword) { + inList = true; + Serial.println("password same too"); + break; + } else { + inList = true; + Serial.println("password will be updated"); + passwords[i] = newPassword; + wifilist = ""; + serializeJson(addresses, wifilist); + preferences.putString("wifi", wifilist); + break; + } } } if (inList == false) { @@ -165,7 +176,7 @@ void addToWiFiJSON(String newSSID, String newPassword) { String getRemoteMacAddress(int clientID) { String remoteMacAddress = ""; - + //Return a specific mac address from the JSON array String _macAddressJson = getJSONMac(); const size_t capacity = JSON_ARRAY_SIZE(6) + JSON_OBJECT_SIZE(1) + 10; @@ -173,19 +184,19 @@ String getRemoteMacAddress(int clientID) { deserializeJson(addresses, _macAddressJson); JsonArray macs = addresses["mac"]; - if(macs.size() > clientID) { + if (macs.size() > clientID) { remoteMacAddress = macs[clientID].as(); } - - return(remoteMacAddress); + + return (remoteMacAddress); } int getNumberOfMacAddresses() { int numberOfMacAddresses = 0; - + //Returns the number of mac address in JSON array preferences.begin("scads", false); - String macCredentials = preferences.getString("mac", ""); + String macCredentials = preferences.getString("mac", ""); preferences.end(); if (macCredentials != "") { @@ -195,7 +206,7 @@ int getNumberOfMacAddresses() { numberOfMacAddresses = addresses["mac"].size(); } - return(numberOfMacAddresses); + return (numberOfMacAddresses); } String getScanAsJsonString() { diff --git a/captivePortal.ino b/captivePortal.ino index bb96109..23fbfd9 100644 --- a/captivePortal.ino +++ b/captivePortal.ino @@ -107,7 +107,10 @@ class CaptiveRequestHandler : public AsyncWebHandler { String remote_pass = json["remote_pass"].as(); String remote_mac = json["remote_mac"].as(); - if (remote_mac != "") addToMacAddressJSON(remote_mac); + if (remote_mac != "") { + addToMacAddressJSON(remote_mac); + readyToReset = true; + } if (remote_pass != "" && remote_ssid != "" && local_ssid != "" && local_pass != "") { local_ssid = checkSsidForSpelling(local_ssid); @@ -115,13 +118,15 @@ class CaptiveRequestHandler : public AsyncWebHandler { addToWiFiJSON(local_ssid, local_pass); addToWiFiJSON(remote_ssid, remote_pass); sendWifiCredentials(); - socket_server.textAll("RESTART"); - softReset(); + readyToReset = true; } else if (local_pass != "" && local_ssid != "" && remote_ssid == "" && remote_pass == "") { local_ssid = checkSsidForSpelling(local_ssid); addToWiFiJSON(local_ssid, local_pass); sendWifiCredentials(); + readyToReset = true; + } + if (readyToReset) { socket_server.textAll("RESTART"); softReset(); } diff --git a/wifi.ino b/wifi.ino index 7ecac55..d7fcf93 100644 --- a/wifi.ino +++ b/wifi.ino @@ -21,8 +21,8 @@ boolean scanAndConnectToLocalSCADS() { Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*"); delay(10); scads_ssid = WiFi.SSID(i); - if (scads_ssid.indexOf("SCADS-") > -1) { - Serial.println("Found SCAD"); + if (scads_ssid.indexOf("Yo-Yo-") > -1) { + Serial.println("Found YOYO"); foundLocalSCADS = true; wifiMulti.addAP(scads_ssid.c_str(), scads_pass.c_str()); while ((wifiMulti.run() != WL_CONNECTED)) {