Skip to content

Commit

Permalink
Merge pull request #62 from mikevanis/master
Browse files Browse the repository at this point in the history
change connect to wifi behaviour to kick up captive portal every time
  • Loading branch information
mikevanis authored Dec 15, 2020
2 parents 397dce3 + 444b6fd commit 17e128b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 39 deletions.
4 changes: 2 additions & 2 deletions ESP32-SOCKETIO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int currentSetupStatus = setup_pending;
#define PROJECT_SLUG "ESP32-SOCKETIO"
#define VERSION "v0.2"
#define ESP32set
#define WIFICONNECTTIMEOUT 60000
#define WIFICONNECTTIMEOUT 120000
#define SSID_MAX_LENGTH 31

#include <AsyncTCP.h>
Expand Down Expand Up @@ -73,7 +73,7 @@ using namespace ace_button;
#define RGBLEDPWMSTART 120
#define FASTLONGFADE 120
unsigned long LONGFADEMINUTESMAX = 360;
#define LONGFADECHECKMILLIS 60000
#define LONGFADECHECKMILLIS 120000
unsigned long prevLongFadeVal[NUMPIXELS] = {0,0};
uint8_t hue[NUMPIXELS];
uint8_t saturation[NUMPIXELS];
Expand Down
44 changes: 7 additions & 37 deletions wifi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void connectToWifi(String credentials) {
if (ssid.size() > 0) {
for (int i = 0; i < ssid.size(); i++) {
if (isWifiValid(ssid[i])) {
wifiMulti.addAP(checkSsidForSpelling(ssid[i]).c_str(), pass[i]);
wifiMulti.addAP(checkSsidForSpelling(ssid[i]).c_str(), pass[i]);
}
}
} else {
Expand All @@ -84,10 +84,6 @@ void connectToWifi(String credentials) {
long wifiMillis = millis();
bool connectSuccess = false;

preferences.begin("scads", false);
bool hasConnected = preferences.getBool("hasConnected");
preferences.end();

while (!connectSuccess) {

uint8_t currentStatus = wifiMulti.run();
Expand Down Expand Up @@ -121,44 +117,18 @@ void connectToWifi(String credentials) {

if (currentStatus == WL_CONNECTED) {
// Connected!

if (!hasConnected) {
preferences.begin("scads", false);
preferences.putBool("hasConnected", true);
preferences.end();
hasConnected = true;
}
connectSuccess = true;
break;
}

if (millis() - wifiMillis > WIFICONNECTTIMEOUT) {
// Timeout, check if we're out of range.
while (hasConnected) {
// Out of range, keep trying
uint8_t _currentStatus = wifiMulti.run();
if (_currentStatus == WL_CONNECTED) {
digitalWrite(LED_BUILTIN, 0);
preferences.begin("scads", false);
preferences.putBool("hasConnected", true);
preferences.end();
break;
}
else {
digitalWrite(LED_BUILTIN, 1);
delay(100);
Serial.print(".");
}
yield();
}
if (!hasConnected) {
// Wipe credentials and reset
Serial.println("Wifi connect failed, Please try your details again in the captive portal");
preferences.begin("scads", false);
preferences.putString("wifi", "");
preferences.end();
ESP.restart();
}
// Wipe credentials and reset
Serial.println("Wifi connect failed, Please try your details again in the captive portal");
preferences.begin("scads", false);
preferences.putString("wifi", "");
preferences.end();
ESP.restart();
}

delay(100);
Expand Down

0 comments on commit 17e128b

Please sign in to comment.