Clean up and added comments about the esp32 sdk bug

1.2-legacy
Jm Casler 2020-09-16 22:31:07 -07:00
rodzic 493b25f23e
commit 73b47a78aa
3 zmienionych plików z 42 dodań i 46 usunięć

Wyświetl plik

@ -20,8 +20,20 @@ bool isWifiAvailable()
// Disable WiFi
void deinitWifi()
{
/*
Note from Jm (Sept 16, 2020):
A bug in the ESP32 SDK was introduced in Oct 2019 that keeps the WiFi radio from
turning back on after it's shut off. See:
https://github.com/espressif/arduino-esp32/issues/3522
Until then, WiFi should only be allowed when there's no power
saving on the 2.4g transceiver.
*/
WiFi.mode(WIFI_MODE_NULL);
DEBUG_MSG("WiFi Turned Off\n");
WiFi.printDiag(Serial);
}
@ -45,6 +57,8 @@ void initWifi()
} else {
WiFi.mode(WIFI_MODE_STA);
WiFi.onEvent(WiFiEvent);
//esp_wifi_set_ps(WIFI_PS_NONE); // Disable power saving
DEBUG_MSG("JOINING WIFI: ssid=%s\n", wifiName);
if (WiFi.begin(wifiName, wifiPsw) == WL_CONNECTED) {
@ -65,31 +79,31 @@ void WiFiEvent(WiFiEvent_t event)
switch (event) {
case SYSTEM_EVENT_WIFI_READY:
DEBUG_MSG("WiFi interface ready");
DEBUG_MSG("WiFi interface ready\n");
break;
case SYSTEM_EVENT_SCAN_DONE:
DEBUG_MSG("Completed scan for access points");
DEBUG_MSG("Completed scan for access points\n");
break;
case SYSTEM_EVENT_STA_START:
DEBUG_MSG("WiFi client started");
DEBUG_MSG("WiFi client started\n");
break;
case SYSTEM_EVENT_STA_STOP:
DEBUG_MSG("WiFi clients stopped");
DEBUG_MSG("WiFi clients stopped\n");
break;
case SYSTEM_EVENT_STA_CONNECTED:
DEBUG_MSG("Connected to access point");
DEBUG_MSG("Connected to access point\n");
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
DEBUG_MSG("Disconnected from WiFi access point");
DEBUG_MSG("Disconnected from WiFi access point\n");
// Reconnect WiFi
reconnectWiFi();
break;
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE:
DEBUG_MSG("Authentication mode of access point has changed");
DEBUG_MSG("Authentication mode of access point has changed\n");
break;
case SYSTEM_EVENT_STA_GOT_IP:
DEBUG_MSG("Obtained IP address: ");
DEBUG_MSG("Obtained IP address: \n");
Serial.println(WiFi.localIP());
// Start web server
@ -97,72 +111,56 @@ void WiFiEvent(WiFiEvent_t event)
break;
case SYSTEM_EVENT_STA_LOST_IP:
DEBUG_MSG("Lost IP address and IP address is reset to 0");
DEBUG_MSG("Lost IP address and IP address is reset to 0\n");
break;
case SYSTEM_EVENT_STA_WPS_ER_SUCCESS:
DEBUG_MSG("WiFi Protected Setup (WPS): succeeded in enrollee mode");
DEBUG_MSG("WiFi Protected Setup (WPS): succeeded in enrollee mode\n");
break;
case SYSTEM_EVENT_STA_WPS_ER_FAILED:
DEBUG_MSG("WiFi Protected Setup (WPS): failed in enrollee mode");
DEBUG_MSG("WiFi Protected Setup (WPS): failed in enrollee mode\n");
break;
case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT:
DEBUG_MSG("WiFi Protected Setup (WPS): timeout in enrollee mode");
DEBUG_MSG("WiFi Protected Setup (WPS): timeout in enrollee mode\n");
break;
case SYSTEM_EVENT_STA_WPS_ER_PIN:
DEBUG_MSG("WiFi Protected Setup (WPS): pin code in enrollee mode");
DEBUG_MSG("WiFi Protected Setup (WPS): pin code in enrollee mode\n");
break;
case SYSTEM_EVENT_AP_START:
DEBUG_MSG("WiFi access point started");
DEBUG_MSG("WiFi access point started\n");
break;
case SYSTEM_EVENT_AP_STOP:
DEBUG_MSG("WiFi access point stopped");
DEBUG_MSG("WiFi access point stopped\n");
break;
case SYSTEM_EVENT_AP_STACONNECTED:
DEBUG_MSG("Client connected");
DEBUG_MSG("Client connected\n");
break;
case SYSTEM_EVENT_AP_STADISCONNECTED:
DEBUG_MSG("Client disconnected");
DEBUG_MSG("Client disconnected\n");
break;
case SYSTEM_EVENT_AP_STAIPASSIGNED:
DEBUG_MSG("Assigned IP address to client");
DEBUG_MSG("Assigned IP address to client\n");
break;
case SYSTEM_EVENT_AP_PROBEREQRECVED:
DEBUG_MSG("Received probe request");
DEBUG_MSG("Received probe request\n");
break;
case SYSTEM_EVENT_GOT_IP6:
DEBUG_MSG("IPv6 is preferred");
DEBUG_MSG("IPv6 is preferred\n");
break;
case SYSTEM_EVENT_ETH_START:
DEBUG_MSG("Ethernet started");
DEBUG_MSG("Ethernet started\n");
break;
case SYSTEM_EVENT_ETH_STOP:
DEBUG_MSG("Ethernet stopped");
DEBUG_MSG("Ethernet stopped\n");
break;
case SYSTEM_EVENT_ETH_CONNECTED:
DEBUG_MSG("Ethernet connected");
DEBUG_MSG("Ethernet connected\n");
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
DEBUG_MSG("Ethernet disconnected");
DEBUG_MSG("Ethernet disconnected\n");
break;
case SYSTEM_EVENT_ETH_GOT_IP:
DEBUG_MSG("Obtained IP address");
DEBUG_MSG("Obtained IP address\n");
break;
default: break;
}
}
void reconnectWiFi() {
const char *wifiName = radioConfig.preferences.wifi_ssid;
const char *wifiPsw = radioConfig.preferences.wifi_password;
if (radioConfig.has_preferences) {
if (*wifiName) {
DEBUG_MSG("... Reconnecting to WiFi access point");
WiFi.mode(WIFI_MODE_STA);
WiFi.begin(wifiName, wifiPsw);
}
}
}
}

Wyświetl plik

@ -4,8 +4,6 @@
#include <functional>
#include <WiFi.h>
void reconnectWiFi();
void initWifi();
void deinitWifi();

Wyświetl plik

@ -523,12 +523,12 @@ void setBluetoothEnable(bool on)
if (firstTime) {
firstTime = 0;
} else {
reconnectWiFi();
initWifi();
}
} else {
// We have to totally teardown our bluetooth objects to prevent leaks
deinitBLE();
deinitWifi(); // shutdown wifi
deinitBLE();
Serial.printf("Shutdown BT: %u heap size\n", ESP.getFreeHeap());
// ESP_ERROR_CHECK( heap_trace_stop() );