diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index 46051166..8c5d0a2a 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/meshwifi/meshwifi.cpp @@ -5,6 +5,12 @@ #include "NodeDB.h" #include "meshwifi/meshhttp.h" +void deinitWifi() +{ + WiFi.mode(WIFI_MODE_NULL); + DEBUG_MSG("WiFi Turned Off\n"); +} + void initWifi() { strcpy(radioConfig.preferences.wifi_ssid, WiFi_SSID_NAME); @@ -68,6 +74,7 @@ void WiFiEvent(WiFiEvent_t event) // Start web server initWebServer(); + break; case SYSTEM_EVENT_STA_LOST_IP: DEBUG_MSG("Lost IP address and IP address is reset to 0"); diff --git a/src/meshwifi/meshwifi.h b/src/meshwifi/meshwifi.h index 97903397..a20a114a 100644 --- a/src/meshwifi/meshwifi.h +++ b/src/meshwifi/meshwifi.h @@ -8,5 +8,7 @@ void reconnectWiFi(); void initWifi(); +void deinitWifi(); + void WiFiEvent(WiFiEvent_t event); diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index 059b2ec2..f5595c5a 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -518,6 +518,8 @@ void setBluetoothEnable(bool on) // ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) ); reinitBluetooth(); + // Don't try to reconnect wifi before bluetooth is configured. + // WiFi is initialized from main.cpp in setup() . if (firstTime) { firstTime = 0; } else { @@ -526,7 +528,8 @@ void setBluetoothEnable(bool on) } else { // We have to totally teardown our bluetooth objects to prevent leaks deinitBLE(); - //WiFi.mode(WIFI_MODE_NULL); // shutdown wifi + WiFi.mode(WIFI_MODE_NULL); // shutdown wifi + Serial.printf("Shutdown BT: %u heap size\n", ESP.getFreeHeap()); // ESP_ERROR_CHECK( heap_trace_stop() ); // heap_trace_dump();