Skip to content

Commit

Permalink
added restart on adding yoyo code, added logic to catch reentering th…
Browse files Browse the repository at this point in the history
…e same wifi ssid but different password, fixed finding local scad network
  • Loading branch information
andysheen committed Sep 16, 2020
1 parent f705bdb commit 69fc42d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions ESP32-SOCKETIO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
int BUTTON_BUILTIN = 0;

bool disconnected = false;
bool readyToReset = false;

unsigned long wificheckMillis;
unsigned long wifiCheckTime = 5000;
Expand Down
29 changes: 20 additions & 9 deletions JSONHandling.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -165,27 +176,27 @@ 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;
DynamicJsonDocument addresses(capacity);
deserializeJson(addresses, _macAddressJson);
JsonArray macs = addresses["mac"];

if(macs.size() > clientID) {
if (macs.size() > clientID) {
remoteMacAddress = macs[clientID].as<String>();
}
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 != "") {
Expand All @@ -195,7 +206,7 @@ int getNumberOfMacAddresses() {
numberOfMacAddresses = addresses["mac"].size();
}

return(numberOfMacAddresses);
return (numberOfMacAddresses);
}

String getScanAsJsonString() {
Expand Down
11 changes: 8 additions & 3 deletions captivePortal.ino
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,26 @@ class CaptiveRequestHandler : public AsyncWebHandler {
String remote_pass = json["remote_pass"].as<String>();
String remote_mac = json["remote_mac"].as<String>();

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);
remote_ssid = checkSsidForSpelling(remote_ssid);
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();
}
Expand Down
4 changes: 2 additions & 2 deletions wifi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 69fc42d

Please sign in to comment.