V3.1.3 - Bug fix not disabling WiFi correctly

This commit is contained in:
Ray Jones 2019-09-12 06:32:21 +10:00
parent 3a810d6eea
commit d30536e939
2 changed files with 105 additions and 83 deletions

View file

@ -124,8 +124,8 @@
#define RX_DATA_TIMOUT 50 #define RX_DATA_TIMOUT 50
const int FirmwareRevision = 31; const int FirmwareRevision = 31;
const int FirmwareSubRevision = 2; const int FirmwareSubRevision = 3;
const char* FirmwareDate = "8 Sep 2019"; const char* FirmwareDate = "11 Sep 2019";
#ifdef ESP32 #ifdef ESP32
@ -1647,18 +1647,19 @@ void doStreaming()
{ {
#if USE_WIFI == 1 #if USE_WIFI == 1
doWiFiManager(); if(NVstore.getUserSettings().enableWifi) {
doWiFiManager();
#if USE_OTA == 1 #if USE_OTA == 1
DoOTA(); DoOTA();
#endif // USE_OTA #endif // USE_OTA
#if USE_WEBSERVER == 1 #if USE_WEBSERVER == 1
bHaveWebClient = doWebServer(); bHaveWebClient = doWebServer();
#endif //USE_WEBSERVER #endif //USE_WEBSERVER
#if USE_MQTT == 1 #if USE_MQTT == 1
// most MQTT is managed via callbacks, but need some sundry housekeeping // most MQTT is managed via callbacks, but need some sundry housekeeping
doMQTT(); doMQTT();
#endif #endif
}
#endif // USE_WIFI #endif // USE_WIFI

View file

@ -144,79 +144,81 @@ bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
// call from main sketch loop() // call from main sketch loop()
void doWiFiManager() void doWiFiManager()
{ {
wm.process(); if(NVstore.getUserSettings().enableWifi) {
wm.process();
if(WiFi.status() != WL_CONNECTED) { if(WiFi.status() != WL_CONNECTED) {
if(isSTA) DebugPort.println("STA lost"); if(isSTA) DebugPort.println("STA lost");
isSTA = false; isSTA = false;
if(WifiReconnectHoldoff) { if(WifiReconnectHoldoff) {
long tDelta = millis() - WifiReconnectHoldoff; long tDelta = millis() - WifiReconnectHoldoff;
if(tDelta >= 0) { if(tDelta >= 0) {
WifiReconnectHoldoff = 0; WifiReconnectHoldoff = 0;
WiFi.disconnect(); WiFi.disconnect();
WiFi.mode(WIFI_AP_STA); WiFi.mode(WIFI_AP_STA);
wifi_config_t conf; wifi_config_t conf;
esp_wifi_get_config(WIFI_IF_STA, &conf); esp_wifi_get_config(WIFI_IF_STA, &conf);
WiFi.begin((char*)conf.sta.ssid, (char*)conf.sta.password); WiFi.begin((char*)conf.sta.ssid, (char*)conf.sta.password);
}
}
else {
WifiReconnectHoldoff = millis() + 15000;
} }
} }
else { else {
WifiReconnectHoldoff = millis() + 10000; if(!isSTA) DebugPort.println("STA established");
isSTA = true;
WifiReconnectHoldoff = 0;
} }
}
else {
if(!isSTA) DebugPort.println("STA established");
isSTA = true;
WifiReconnectHoldoff = 0;
}
#if USE_PORTAL_TRIGGER_PIN == 1 #if USE_PORTAL_TRIGGER_PIN == 1
// manage handling of pin to enter WiFManager config portal // manage handling of pin to enter WiFManager config portal
// we typically use the BOOT pin for this (pins.h) // we typically use the BOOT pin for this (pins.h)
// //
// Quick Press (< 1 sec) - enable config portal // Quick Press (< 1 sec) - enable config portal
// > 1 second (< 5 sec) press - disable config portal // > 1 second (< 5 sec) press - disable config portal
// > 5 second press - erase credentials, enable config portal // > 5 second press - erase credentials, enable config portal
static bool pinDown = false; static bool pinDown = false;
static long pinTime = 0; static long pinTime = 0;
unsigned long tDelta; unsigned long tDelta;
if(digitalRead(TRIG_PIN) == LOW) { if(digitalRead(TRIG_PIN) == LOW) {
if(!pinDown) { if(!pinDown) {
pinTime = millis(); pinTime = millis();
ScreenManager.reqUpdate(); ScreenManager.reqUpdate();
} }
pinDown = true; pinDown = true;
// track hold duration - change OLED Wifi annotation according to length of press // track hold duration - change OLED Wifi annotation according to length of press
tDelta = millis() - pinTime;
if(tDelta > 5000)
wifiButtonState = 3; // we will show 'ERS' on OLED!
else if(tDelta > 1000)
wifiButtonState = 2; // we will show 'HTR' on OLED!
else
wifiButtonState = 1; // we will show 'CFG' on OLED!
}
else {
if(pinDown) {
pinDown = false;
tDelta = millis() - pinTime; tDelta = millis() - pinTime;
DebugPort.printf("Wifi config button tDelta = %ld\r\n", tDelta); if(tDelta > 5000)
// > 5 second press? wifiButtonState = 3; // we will show 'ERS' on OLED!
if(tDelta > 5000) { else if(tDelta > 1000)
wifiEnterConfigPortal(true, true); // very long press - clear credentials, reboot into portal wifiButtonState = 2; // we will show 'HTR' on OLED!
else
wifiButtonState = 1; // we will show 'CFG' on OLED!
}
else {
if(pinDown) {
pinDown = false;
tDelta = millis() - pinTime;
DebugPort.printf("Wifi config button tDelta = %ld\r\n", tDelta);
// > 5 second press?
if(tDelta > 5000) {
wifiEnterConfigPortal(true, true); // very long press - clear credentials, reboot into portal
}
// > 1 second press?
else if(tDelta > 1000) {
wifiEnterConfigPortal(false); // long press - reboot into web server
}
// > 50ms press?
else if(tDelta > 50) {
wifiEnterConfigPortal(true); // quick press - reboot into portal
}
// consider as contact bounce if < 50ms!
} }
// > 1 second press?
else if(tDelta > 1000) {
wifiEnterConfigPortal(false); // long press - reboot into web server
}
// > 50ms press?
else if(tDelta > 50) {
wifiEnterConfigPortal(true); // quick press - reboot into portal
}
// consider as contact bounce if < 50ms!
} }
}
#endif #endif
}
} }
void wifiDisable(long rebootDelay) void wifiDisable(long rebootDelay)
@ -297,18 +299,26 @@ void APstartedCallback(WiFiManager*)
const char* getWifiAPAddrStr() const char* getWifiAPAddrStr()
{ {
IPAddress IPaddr = WiFi.softAPIP(); // use stepping stone - function returns an automatic stack var - LAME! if(NVstore.getUserSettings().enableWifi) {
static char APIPaddr[16]; IPAddress IPaddr = WiFi.softAPIP(); // use stepping stone - function returns an automatic stack var - LAME!
sprintf(APIPaddr, "%d.%d.%d.%d", IPaddr[0], IPaddr[1], IPaddr[2], IPaddr[3]); static char APIPaddr[16];
return APIPaddr; sprintf(APIPaddr, "%d.%d.%d.%d", IPaddr[0], IPaddr[1], IPaddr[2], IPaddr[3]);
return APIPaddr;
}
else
return "";
} }
const char* getWifiSTAAddrStr() const char* getWifiSTAAddrStr()
{ {
IPAddress IPaddr = WiFi.localIP(); // use stepping stone - function returns an automatic stack var - LAME! if(NVstore.getUserSettings().enableWifi) {
static char STAIPaddr[16]; IPAddress IPaddr = WiFi.localIP(); // use stepping stone - function returns an automatic stack var - LAME!
sprintf(STAIPaddr, "%d.%d.%d.%d", IPaddr[0], IPaddr[1], IPaddr[2], IPaddr[3]); static char STAIPaddr[16];
return STAIPaddr; sprintf(STAIPaddr, "%d.%d.%d.%d", IPaddr[0], IPaddr[1], IPaddr[2], IPaddr[3]);
return STAIPaddr;
}
else
return "";
} }
const char* getWifiAPMACStr() const char* getWifiAPMACStr()
@ -323,20 +333,31 @@ const char* getWifiSTAMACStr()
String getSSID() String getSSID()
{ {
wifi_config_t conf; if(NVstore.getUserSettings().enableWifi) {
esp_wifi_get_config(WIFI_IF_STA, &conf); wifi_config_t conf;
return String(reinterpret_cast<const char*>(conf.sta.ssid)); esp_wifi_get_config(WIFI_IF_STA, &conf);
return String(reinterpret_cast<const char*>(conf.sta.ssid));
}
else
return "";
} }
bool isWifiConnected() bool isWifiConnected()
{ {
return WiFi.status() == WL_CONNECTED; if(NVstore.getUserSettings().enableWifi)
return WiFi.status() == WL_CONNECTED;
else
return false;
} }
bool isWifiAP() bool isWifiAP()
{ {
int mode = WiFi.getMode(); if(NVstore.getUserSettings().enableWifi) {
return !isSTA && ((mode & WIFI_MODE_AP) != 0); int mode = WiFi.getMode();
return !isSTA && ((mode & WIFI_MODE_AP) != 0);
}
else
return false;
} }
bool isWifiSTA() bool isWifiSTA()