From f129b458adc5c159f1de47057e057f50255087c2 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sat, 12 Sep 2020 21:43:41 -0700 Subject: [PATCH 1/9] Initial Checkin for WiFi and HTTP Server Framework --- src/configuration.h | 15 +++ src/graphics/Screen.cpp | 38 +++++++ src/graphics/Screen.h | 4 + src/main.cpp | 11 ++ src/main.h | 4 +- src/mesh/NodeDB.cpp | 6 + src/meshwifi/meshwifi.cpp | 212 +++++++++++++++++++++++++++++++++++ src/meshwifi/meshwifi.h | 22 ++++ src/nimble/BluetoothUtil.cpp | 33 +----- 9 files changed, 314 insertions(+), 31 deletions(-) create mode 100644 src/meshwifi/meshwifi.cpp create mode 100644 src/meshwifi/meshwifi.h diff --git a/src/configuration.h b/src/configuration.h index e70f1fda4..e2098fd0d 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -397,3 +397,18 @@ along with this program. If not, see . #define GPS_POWER_CTRL_CH 3 #define LORA_POWER_CTRL_CH 2 + +// ----------------------------------------------------------------------------- +// WiFi Configuration +// ----------------------------------------------------------------------------- +// +// Set WiFi credentials using the API (Does this work?) +// meshtastic --setpref WiFi_SSID_NAME yournetwork +// meshtastic --setpref WiFi_SSID_PASSWORD yourpassword +// +// WiFi_Mode +// 0 = Disabled +// 1 = Enabled +#define WiFi_MODE 0 +#define WiFi_SSID_NAME "meshtastic" +#define WiFi_SSID_PASSWORD "meshtastic!" \ No newline at end of file diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 5229f5660..4a6418b9e 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -32,6 +32,7 @@ along with this program. If not, see . #include "main.h" #include "mesh-pb-constants.h" #include "utils.h" +#include using namespace meshtastic; /** @todo remove */ @@ -708,6 +709,12 @@ void Screen::drawDebugInfoSettingsTrampoline(OLEDDisplay *display, OLEDDisplayUi screen->debugInfo.drawFrameSettings(display, state, x, y); } +void Screen::drawDebugInfoWiFiTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) +{ + Screen *screen = reinterpret_cast(state->userData); + screen->debugInfo.drawFrameWiFi(display, state, x, y); +} + // restore our regular frame list void Screen::setFrames() @@ -739,6 +746,11 @@ void Screen::setFrames() // call a method on debugInfoScreen object (for more details) normalFrames[numframes++] = &Screen::drawDebugInfoSettingsTrampoline; +#if WiFi_MODE + // call a method on debugInfoScreen object (for more details) + normalFrames[numframes++] = &Screen::drawDebugInfoWiFiTrampoline; +#endif + ui.setFrames(normalFrames, numframes); ui.enableAllIndicators(); @@ -827,6 +839,32 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 } // Jm +void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) +{ + displayedNodeNum = 0; // Not currently showing a node pane + + display->setFont(ArialMT_Plain_10); + + // The coordinates define the left starting point of the text + display->setTextAlignment(TEXT_ALIGN_LEFT); + + if ( WiFi.status() != WL_CONNECTED ) { + display->drawString(x, y, String("WiFi - Not Connected")); + } else { + display->drawString(x, y, String("WiFi - Connected")); + } + + display->drawString(x, y + FONT_HEIGHT * 1, WiFi.localIP().toString().c_str()); + + /* Display a heartbeat pixel that blinks every time the frame is redrawn */ +#ifdef SHOW_REDRAWS + if (heartbeat) + display->setPixel(0, 0); + heartbeat = !heartbeat; +#endif +} + + void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { displayedNodeNum = 0; // Not currently showing a node pane diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index c9ab85449..8f5a6de2a 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -17,6 +17,7 @@ #include "concurrency/PeriodicTask.h" #include "power.h" #include +#include namespace graphics { @@ -46,6 +47,7 @@ class DebugInfo /// Renders the debug screen. void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y); void drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y); + void drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y); std::string channelName; @@ -220,6 +222,8 @@ class Screen : public concurrency::PeriodicTask static void drawDebugInfoSettingsTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y); + static void drawDebugInfoWiFiTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y); + /// Queue of commands to execute in doTask. TypedQueue cmdQueue; /// Whether we are using a display diff --git a/src/main.cpp b/src/main.cpp index f7af6d232..13b28debf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -41,6 +41,7 @@ #include "timing.h" #include #include +#include "meshwifi/meshwifi.h" // #include #ifndef NO_ESP32 @@ -325,6 +326,11 @@ void setup() } #endif +#if WiFi_MODE + // Initialize Wifi + initWifi(); +#endif + if (!rIf) recordCriticalError(ErrNoRadio); else @@ -416,5 +422,10 @@ void loop() // feel slow msecstosleep = 10; +#if WiFi_MODE + // TODO: This should go into a thread handled by FreeRTOS. + handleWebResponse(); +#endif + delay(msecstosleep); } diff --git a/src/main.h b/src/main.h index fb64d9ff0..39b1364f6 100644 --- a/src/main.h +++ b/src/main.h @@ -10,6 +10,8 @@ extern bool ssd1306_found; extern bool isCharging; extern bool isUSBPowered; + + // Global Screen singleton. extern graphics::Screen screen; //extern Observable newPowerStatus; //TODO: move this to main-esp32.cpp somehow or a helper class @@ -23,4 +25,4 @@ const char *getDeviceName(); void getMacAddr(uint8_t *dmac); -void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(); \ No newline at end of file +void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 93d0787d3..22d4675a3 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -15,6 +15,7 @@ #include "mesh-pb-constants.h" #include #include +#include "meshwifi/meshwifi.h" NodeDB nodeDB; @@ -399,6 +400,11 @@ void NodeDB::updateFrom(const MeshPacket &mp) updateTextMessage = true; powerFSM.trigger(EVENT_RECEIVED_TEXT_MSG); notifyObservers(true); // Force an update whether or not our node counts have changed + +// Only update the WebUI if WiFi is enabled +#if WiFi_MODE != 0 + notifyWebUI(); +#endif } } break; diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp new file mode 100644 index 000000000..254c852d9 --- /dev/null +++ b/src/meshwifi/meshwifi.cpp @@ -0,0 +1,212 @@ +#include "meshwifi.h" +#include +#include "configuration.h" +#include "main.h" +#include "NodeDB.h" +#include + +WebServer webserver(80); + +String something = ""; +String sender = ""; + +void initWebServer() { + webserver.onNotFound(handleNotFound); + webserver.on("/", handleJSONChatHistory); + webserver.on("/json/chat/history", handleJSONChatHistory); + //webserver.on("/", []() { + //webserver.send(200, "text/plain", "everything is awesome!"); + //}); + webserver.begin(); + +} + +void initWifi() +{ + strcpy(radioConfig.preferences.wifi_ssid, WiFi_SSID_NAME); + strcpy(radioConfig.preferences.wifi_password, WiFi_SSID_PASSWORD); + if (radioConfig.has_preferences) { + const char *wifiName = radioConfig.preferences.wifi_ssid; + + if (*wifiName) { + const char *wifiPsw = radioConfig.preferences.wifi_password; + if (radioConfig.preferences.wifi_ap_mode) { + DEBUG_MSG("STARTING WIFI AP: ssid=%s, ok=%d\n", wifiName, WiFi.softAP(wifiName, wifiPsw)); + } else { + WiFi.mode(WIFI_MODE_STA); + WiFi.onEvent(WiFiEvent); + + DEBUG_MSG("JOINING WIFI: ssid=%s\n", wifiName); + if (WiFi.begin(wifiName, wifiPsw) == WL_CONNECTED) { + DEBUG_MSG("MY IP ADDRESS: %s\n", WiFi.localIP().toString().c_str()); + } else { + DEBUG_MSG("Started Joining WIFI\n"); + } + } + } + } else + DEBUG_MSG("Not using WIFI\n"); +} + +void WiFiEvent(WiFiEvent_t event) +{ + DEBUG_MSG("************ [WiFi-event] event: %d ************\n", event); + + switch (event) { + case SYSTEM_EVENT_WIFI_READY: + DEBUG_MSG("WiFi interface ready"); + break; + case SYSTEM_EVENT_SCAN_DONE: + DEBUG_MSG("Completed scan for access points"); + break; + case SYSTEM_EVENT_STA_START: + DEBUG_MSG("WiFi client started"); + break; + case SYSTEM_EVENT_STA_STOP: + DEBUG_MSG("WiFi clients stopped"); + break; + case SYSTEM_EVENT_STA_CONNECTED: + DEBUG_MSG("Connected to access point"); + break; + case SYSTEM_EVENT_STA_DISCONNECTED: + DEBUG_MSG("Disconnected from WiFi access point"); + + // Reconnect WiFi + reconnectWiFi(); + break; + case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: + DEBUG_MSG("Authentication mode of access point has changed"); + break; + case SYSTEM_EVENT_STA_GOT_IP: + DEBUG_MSG("Obtained IP address: "); + Serial.println(WiFi.localIP()); + + // Start web server + initWebServer(); + break; + case SYSTEM_EVENT_STA_LOST_IP: + DEBUG_MSG("Lost IP address and IP address is reset to 0"); + break; + case SYSTEM_EVENT_STA_WPS_ER_SUCCESS: + DEBUG_MSG("WiFi Protected Setup (WPS): succeeded in enrollee mode"); + break; + case SYSTEM_EVENT_STA_WPS_ER_FAILED: + DEBUG_MSG("WiFi Protected Setup (WPS): failed in enrollee mode"); + break; + case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT: + DEBUG_MSG("WiFi Protected Setup (WPS): timeout in enrollee mode"); + break; + case SYSTEM_EVENT_STA_WPS_ER_PIN: + DEBUG_MSG("WiFi Protected Setup (WPS): pin code in enrollee mode"); + break; + case SYSTEM_EVENT_AP_START: + DEBUG_MSG("WiFi access point started"); + break; + case SYSTEM_EVENT_AP_STOP: + DEBUG_MSG("WiFi access point stopped"); + break; + case SYSTEM_EVENT_AP_STACONNECTED: + DEBUG_MSG("Client connected"); + break; + case SYSTEM_EVENT_AP_STADISCONNECTED: + DEBUG_MSG("Client disconnected"); + break; + case SYSTEM_EVENT_AP_STAIPASSIGNED: + DEBUG_MSG("Assigned IP address to client"); + break; + case SYSTEM_EVENT_AP_PROBEREQRECVED: + DEBUG_MSG("Received probe request"); + break; + case SYSTEM_EVENT_GOT_IP6: + DEBUG_MSG("IPv6 is preferred"); + break; + case SYSTEM_EVENT_ETH_START: + DEBUG_MSG("Ethernet started"); + break; + case SYSTEM_EVENT_ETH_STOP: + DEBUG_MSG("Ethernet stopped"); + break; + case SYSTEM_EVENT_ETH_CONNECTED: + DEBUG_MSG("Ethernet connected"); + break; + case SYSTEM_EVENT_ETH_DISCONNECTED: + DEBUG_MSG("Ethernet disconnected"); + break; + case SYSTEM_EVENT_ETH_GOT_IP: + DEBUG_MSG("Obtained IP address"); + break; + default: break; + } +} + +void handleJSONChatHistory() { + + String out = ""; + out += "{\n"; + out += " \"data\" : {\n"; + out += " \"chat\" : "; + out += "["; + out += "\"" + sender + "\""; + out += ","; + out += "\"" + something + "\""; + out += "]\n"; + + + + out += "\n"; + out += " }\n"; + out += "}\n"; + + webserver.send ( 200, "application/json", out ); + return; + + +} + +void handleWebResponse() { + webserver.handleClient(); +} + + +void handleNotFound() { + String message = "File Not Found\n\n"; + message += "URI: "; + message += webserver.uri(); + message += "\nMethod: "; + message += (webserver.method() == HTTP_GET) ? "GET" : "POST"; + message += "\nArguments: "; + message += webserver.args(); + message += "\n"; + + for (uint8_t i = 0; i < webserver.args(); i++) { + message += " " + webserver.argName(i) + ": " + webserver.arg(i) + "\n"; + } + + webserver.send(404, "text/plain", message); + /* + */ +} + +void reconnectWiFi() { + if ( WiFi.status() != WL_CONNECTED ) { + DEBUG_MSG("... Reconnecting to WiFi access point"); + WiFi.begin( ); + } + +} + + +void notifyWebUI() { + DEBUG_MSG("************ Got a message! ************\n"); + MeshPacket &mp = devicestate.rx_text_message; + NodeInfo *node = nodeDB.getNode(mp.from); + sender = (node && node->has_user) ? node->user.long_name : "???"; + + static char tempBuf[256]; // mesh.options says this is MeshPacket.encrypted max_size + assert(mp.decoded.which_payload == SubPacket_data_tag); + snprintf(tempBuf, sizeof(tempBuf), "%s", mp.decoded.data.payload.bytes); + + + something = tempBuf; + +} \ No newline at end of file diff --git a/src/meshwifi/meshwifi.h b/src/meshwifi/meshwifi.h new file mode 100644 index 000000000..e6b456e22 --- /dev/null +++ b/src/meshwifi/meshwifi.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include + +void handleNotFound(); + +void reconnectWiFi(); + +void initWifi(); + +void initWebServer(); + +void handleWebResponse(); + +void notifyWebUI(); + +void handleJSONChatHistory(); + +void WiFiEvent(WiFiEvent_t event); + diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index 490bc13d4..20b5aace4 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -1,10 +1,9 @@ #include "BluetoothUtil.h" #include "BluetoothSoftwareUpdate.h" #include "NimbleBluetoothAPI.h" -#include "NodeDB.h" // FIXME - we shouldn't really douch this here - we are using it only because we currently do wifi setup when ble gets turned on #include "PhoneAPI.h" #include "PowerFSM.h" -#include "WiFi.h" +#include #include "configuration.h" #include "esp_bt.h" #include "host/util/util.h" @@ -503,32 +502,6 @@ void reinitBluetooth() nimble_port_freertos_init(ble_host_task); } -void initWifi() -{ - // Note: Wifi is not yet supported ;-) - strcpy(radioConfig.preferences.wifi_ssid, ""); - strcpy(radioConfig.preferences.wifi_password, ""); - if (radioConfig.has_preferences) { - const char *wifiName = radioConfig.preferences.wifi_ssid; - - if (*wifiName) { - const char *wifiPsw = radioConfig.preferences.wifi_password; - if (radioConfig.preferences.wifi_ap_mode) { - DEBUG_MSG("STARTING WIFI AP: ssid=%s, ok=%d\n", wifiName, WiFi.softAP(wifiName, wifiPsw)); - } else { - WiFi.mode(WIFI_MODE_STA); - DEBUG_MSG("JOINING WIFI: ssid=%s\n", wifiName); - if (WiFi.begin(wifiName, wifiPsw) == WL_CONNECTED) { - DEBUG_MSG("MY IP ADDRESS: %s\n", WiFi.localIP().toString().c_str()); - } else { - DEBUG_MSG("Started Joining WIFI\n"); - } - } - } - } else - DEBUG_MSG("Not using WIFI\n"); -} - bool bluetoothOn; // Enable/disable bluetooth. @@ -542,11 +515,11 @@ void setBluetoothEnable(bool on) Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap()); // ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) ); reinitBluetooth(); - initWifi(); + //initWifi(); } 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(); From e508306395b7f55f35d082e9a213f3db311638c9 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 13 Sep 2020 16:58:36 -0700 Subject: [PATCH 2/9] Refactoring to break out HTTP from WiFi --- src/graphics/Screen.cpp | 6 +++ src/main.cpp | 12 +++++- src/mesh/NodeDB.cpp | 7 +-- src/meshwifi/meshhttp.cpp | 89 +++++++++++++++++++++++++++++++++++++++ src/meshwifi/meshhttp.h | 16 +++++++ src/meshwifi/meshwifi.cpp | 82 +----------------------------------- src/meshwifi/meshwifi.h | 10 ----- 7 files changed, 127 insertions(+), 95 deletions(-) create mode 100644 src/meshwifi/meshhttp.cpp create mode 100644 src/meshwifi/meshhttp.h diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 4a6418b9e..e14e4078e 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -841,6 +841,9 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 // Jm void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { + const char *wifiName = radioConfig.preferences.wifi_ssid; + const char *wifiPsw = radioConfig.preferences.wifi_password; + displayedNodeNum = 0; // Not currently showing a node pane display->setFont(ArialMT_Plain_10); @@ -856,6 +859,9 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i display->drawString(x, y + FONT_HEIGHT * 1, WiFi.localIP().toString().c_str()); + display->drawString(x, y + FONT_HEIGHT * 2, wifiName); + display->drawString(x, y + FONT_HEIGHT * 3, wifiPsw); + /* Display a heartbeat pixel that blinks every time the frame is redrawn */ #ifdef SHOW_REDRAWS if (heartbeat) diff --git a/src/main.cpp b/src/main.cpp index 13b28debf..5c5a3a0e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,7 @@ #include #include #include "meshwifi/meshwifi.h" +#include "meshwifi/meshhttp.h" // #include #ifndef NO_ESP32 @@ -426,6 +427,15 @@ void loop() // TODO: This should go into a thread handled by FreeRTOS. handleWebResponse(); #endif - +/* + const char *wifiName = radioConfig.preferences.wifi_ssid; + const char *wifiPsw = radioConfig.preferences.wifi_password; + Serial.print("-------------------"); + Serial.print(wifiName); + Serial.print(" "); + Serial.println(wifiPsw); + Serial.println("+++++++++++++++++++"); + Serial.println(""); +*/ delay(msecstosleep); } diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 22d4675a3..07a97acfb 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -401,10 +401,11 @@ void NodeDB::updateFrom(const MeshPacket &mp) powerFSM.trigger(EVENT_RECEIVED_TEXT_MSG); notifyObservers(true); // Force an update whether or not our node counts have changed +// This is going into the wifidev feature branch // Only update the WebUI if WiFi is enabled -#if WiFi_MODE != 0 - notifyWebUI(); -#endif +//#if WiFi_MODE != 0 +// notifyWebUI(); +//#endif } } break; diff --git a/src/meshwifi/meshhttp.cpp b/src/meshwifi/meshhttp.cpp new file mode 100644 index 000000000..b70b8fc29 --- /dev/null +++ b/src/meshwifi/meshhttp.cpp @@ -0,0 +1,89 @@ +#include +#include +#include "configuration.h" +#include "main.h" +#include "NodeDB.h" +#include "meshwifi.h" +#include "meshhttp.h" + + +WebServer webserver(80); + +String something = ""; +String sender = ""; + + +void handleWebResponse() { + webserver.handleClient(); +} + +void initWebServer() { + webserver.onNotFound(handleNotFound); + //webserver.on("/", handleJSONChatHistory); + //webserver.on("/json/chat/history", handleJSONChatHistory); + webserver.on("/", []() { + webserver.send(200, "text/plain", "Everything is awesome!"); + }); + webserver.begin(); + +} + + +void handleJSONChatHistory() { + + String out = ""; + out += "{\n"; + out += " \"data\" : {\n"; + out += " \"chat\" : "; + out += "["; + out += "\"" + sender + "\""; + out += ","; + out += "\"" + something + "\""; + out += "]\n"; + + + + out += "\n"; + out += " }\n"; + out += "}\n"; + + webserver.send ( 200, "application/json", out ); + return; + +} + +void handleNotFound() { + String message = "File Not Found\n\n"; + message += "URI: "; + message += webserver.uri(); + message += "\nMethod: "; + message += (webserver.method() == HTTP_GET) ? "GET" : "POST"; + message += "\nArguments: "; + message += webserver.args(); + message += "\n"; + + for (uint8_t i = 0; i < webserver.args(); i++) { + message += " " + webserver.argName(i) + ": " + webserver.arg(i) + "\n"; + } + + webserver.send(404, "text/plain", message); + /* + */ +} + + + +void notifyWebUI() { + DEBUG_MSG("************ Got a message! ************\n"); + MeshPacket &mp = devicestate.rx_text_message; + NodeInfo *node = nodeDB.getNode(mp.from); + sender = (node && node->has_user) ? node->user.long_name : "???"; + + static char tempBuf[256]; // mesh.options says this is MeshPacket.encrypted max_size + assert(mp.decoded.which_payload == SubPacket_data_tag); + snprintf(tempBuf, sizeof(tempBuf), "%s", mp.decoded.data.payload.bytes); + + + something = tempBuf; + +} \ No newline at end of file diff --git a/src/meshwifi/meshhttp.h b/src/meshwifi/meshhttp.h new file mode 100644 index 000000000..cbff51db7 --- /dev/null +++ b/src/meshwifi/meshhttp.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include +#include + +void initWebServer(); + +void handleNotFound(); + +void handleWebResponse(); + +void handleJSONChatHistory(); + +void notifyWebUI(); + diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index 254c852d9..ea7df5c73 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/meshwifi/meshwifi.cpp @@ -3,23 +3,7 @@ #include "configuration.h" #include "main.h" #include "NodeDB.h" -#include - -WebServer webserver(80); - -String something = ""; -String sender = ""; - -void initWebServer() { - webserver.onNotFound(handleNotFound); - webserver.on("/", handleJSONChatHistory); - webserver.on("/json/chat/history", handleJSONChatHistory); - //webserver.on("/", []() { - //webserver.send(200, "text/plain", "everything is awesome!"); - //}); - webserver.begin(); - -} +#include "meshwifi/meshhttp.h" void initWifi() { @@ -139,54 +123,6 @@ void WiFiEvent(WiFiEvent_t event) } } -void handleJSONChatHistory() { - - String out = ""; - out += "{\n"; - out += " \"data\" : {\n"; - out += " \"chat\" : "; - out += "["; - out += "\"" + sender + "\""; - out += ","; - out += "\"" + something + "\""; - out += "]\n"; - - - - out += "\n"; - out += " }\n"; - out += "}\n"; - - webserver.send ( 200, "application/json", out ); - return; - - -} - -void handleWebResponse() { - webserver.handleClient(); -} - - -void handleNotFound() { - String message = "File Not Found\n\n"; - message += "URI: "; - message += webserver.uri(); - message += "\nMethod: "; - message += (webserver.method() == HTTP_GET) ? "GET" : "POST"; - message += "\nArguments: "; - message += webserver.args(); - message += "\n"; - - for (uint8_t i = 0; i < webserver.args(); i++) { - message += " " + webserver.argName(i) + ": " + webserver.arg(i) + "\n"; - } - - webserver.send(404, "text/plain", message); - /* - */ -} - void reconnectWiFi() { if ( WiFi.status() != WL_CONNECTED ) { DEBUG_MSG("... Reconnecting to WiFi access point"); @@ -194,19 +130,3 @@ void reconnectWiFi() { } } - - -void notifyWebUI() { - DEBUG_MSG("************ Got a message! ************\n"); - MeshPacket &mp = devicestate.rx_text_message; - NodeInfo *node = nodeDB.getNode(mp.from); - sender = (node && node->has_user) ? node->user.long_name : "???"; - - static char tempBuf[256]; // mesh.options says this is MeshPacket.encrypted max_size - assert(mp.decoded.which_payload == SubPacket_data_tag); - snprintf(tempBuf, sizeof(tempBuf), "%s", mp.decoded.data.payload.bytes); - - - something = tempBuf; - -} \ No newline at end of file diff --git a/src/meshwifi/meshwifi.h b/src/meshwifi/meshwifi.h index e6b456e22..97903397f 100644 --- a/src/meshwifi/meshwifi.h +++ b/src/meshwifi/meshwifi.h @@ -4,19 +4,9 @@ #include #include -void handleNotFound(); - void reconnectWiFi(); void initWifi(); -void initWebServer(); - -void handleWebResponse(); - -void notifyWebUI(); - -void handleJSONChatHistory(); - void WiFiEvent(WiFiEvent_t event); From f5c939fb10469d31fcdc922345878c1e2703fabb Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 13 Sep 2020 22:22:49 -0700 Subject: [PATCH 3/9] Fix to turn WiFi back on after the bluetooth radio is reenabled. --- src/main.cpp | 11 +---------- src/meshwifi/meshwifi.cpp | 17 +++++++++++++---- src/nimble/BluetoothUtil.cpp | 9 ++++++++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5c5a3a0e1..81038030d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -427,15 +427,6 @@ void loop() // TODO: This should go into a thread handled by FreeRTOS. handleWebResponse(); #endif -/* - const char *wifiName = radioConfig.preferences.wifi_ssid; - const char *wifiPsw = radioConfig.preferences.wifi_password; - Serial.print("-------------------"); - Serial.print(wifiName); - Serial.print(" "); - Serial.println(wifiPsw); - Serial.println("+++++++++++++++++++"); - Serial.println(""); -*/ + delay(msecstosleep); } diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index ea7df5c73..460511664 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/meshwifi/meshwifi.cpp @@ -32,6 +32,7 @@ void initWifi() DEBUG_MSG("Not using WIFI\n"); } + void WiFiEvent(WiFiEvent_t event) { DEBUG_MSG("************ [WiFi-event] event: %d ************\n", event); @@ -124,9 +125,17 @@ void WiFiEvent(WiFiEvent_t event) } void reconnectWiFi() { - if ( WiFi.status() != WL_CONNECTED ) { - DEBUG_MSG("... Reconnecting to WiFi access point"); - WiFi.begin( ); - } + 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); + } + } } diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index 20b5aace4..059b2ec22 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -12,6 +12,7 @@ #include "services/gap/ble_svc_gap.h" #include "services/gatt/ble_svc_gatt.h" #include +#include "meshwifi/meshwifi.h" static bool pinShowing; @@ -503,6 +504,7 @@ void reinitBluetooth() } bool bluetoothOn; +bool firstTime = 1; // Enable/disable bluetooth. void setBluetoothEnable(bool on) @@ -515,7 +517,12 @@ void setBluetoothEnable(bool on) Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap()); // ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) ); reinitBluetooth(); - //initWifi(); + + if (firstTime) { + firstTime = 0; + } else { + reconnectWiFi(); + } } else { // We have to totally teardown our bluetooth objects to prevent leaks deinitBLE(); From 066d9d48a41b814b0b87637d51e617252c6a91ff Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Mon, 14 Sep 2020 20:27:49 -0700 Subject: [PATCH 4/9] New method to deinit the wifi stack. --- src/meshwifi/meshwifi.cpp | 7 +++++++ src/meshwifi/meshwifi.h | 2 ++ src/nimble/BluetoothUtil.cpp | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index 460511664..8c5d0a2ae 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 97903397f..a20a114aa 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 059b2ec22..f5595c5a9 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(); From 3fcd4a61aaf5ccc6b6a00459f0dc6e03eee1fae2 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Tue, 15 Sep 2020 20:24:03 -0700 Subject: [PATCH 5/9] commenting out the strcpy to manually set the wifi info. --- src/meshwifi/meshwifi.cpp | 4 ++-- src/nimble/BluetoothUtil.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index 8c5d0a2ae..19a52bf51 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/meshwifi/meshwifi.cpp @@ -13,8 +13,8 @@ void deinitWifi() void initWifi() { - strcpy(radioConfig.preferences.wifi_ssid, WiFi_SSID_NAME); - strcpy(radioConfig.preferences.wifi_password, WiFi_SSID_PASSWORD); + //strcpy(radioConfig.preferences.wifi_ssid, WiFi_SSID_NAME); + //strcpy(radioConfig.preferences.wifi_password, WiFi_SSID_PASSWORD); if (radioConfig.has_preferences) { const char *wifiName = radioConfig.preferences.wifi_ssid; diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index f5595c5a9..00e7deea1 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -528,7 +528,7 @@ void setBluetoothEnable(bool on) } else { // We have to totally teardown our bluetooth objects to prevent leaks deinitBLE(); - WiFi.mode(WIFI_MODE_NULL); // shutdown wifi + deinitWifi(); // shutdown wifi Serial.printf("Shutdown BT: %u heap size\n", ESP.getFreeHeap()); // ESP_ERROR_CHECK( heap_trace_stop() ); From 27ad8472c14f7975a4665708ab04949c88dbde3c Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Tue, 15 Sep 2020 20:24:58 -0700 Subject: [PATCH 6/9] remove ssid info from configuration.h --- src/configuration.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index e2098fd0d..63d1dbfc4 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -409,6 +409,4 @@ along with this program. If not, see . // WiFi_Mode // 0 = Disabled // 1 = Enabled -#define WiFi_MODE 0 -#define WiFi_SSID_NAME "meshtastic" -#define WiFi_SSID_PASSWORD "meshtastic!" \ No newline at end of file +#define WiFi_MODE 1 From 493b25f23ee31266ec35afa33bc0ba053cbd1cef Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Wed, 16 Sep 2020 20:15:00 -0700 Subject: [PATCH 7/9] Final checkin of WiFi and basic HTTP server --- src/configuration.h | 13 ------------- src/graphics/Screen.cpp | 9 +++++---- src/main.cpp | 4 ---- src/meshwifi/meshhttp.cpp | 8 ++++++-- src/meshwifi/meshwifi.cpp | 20 ++++++++++++++++++++ src/meshwifi/meshwifi.h | 1 + 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index 63d1dbfc4..e70f1fda4 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -397,16 +397,3 @@ along with this program. If not, see . #define GPS_POWER_CTRL_CH 3 #define LORA_POWER_CTRL_CH 2 - -// ----------------------------------------------------------------------------- -// WiFi Configuration -// ----------------------------------------------------------------------------- -// -// Set WiFi credentials using the API (Does this work?) -// meshtastic --setpref WiFi_SSID_NAME yournetwork -// meshtastic --setpref WiFi_SSID_PASSWORD yourpassword -// -// WiFi_Mode -// 0 = Disabled -// 1 = Enabled -#define WiFi_MODE 1 diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index e14e4078e..29637934e 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -33,6 +33,7 @@ along with this program. If not, see . #include "mesh-pb-constants.h" #include "utils.h" #include +#include "meshwifi/meshwifi.h" using namespace meshtastic; /** @todo remove */ @@ -746,10 +747,10 @@ void Screen::setFrames() // call a method on debugInfoScreen object (for more details) normalFrames[numframes++] = &Screen::drawDebugInfoSettingsTrampoline; -#if WiFi_MODE - // call a method on debugInfoScreen object (for more details) - normalFrames[numframes++] = &Screen::drawDebugInfoWiFiTrampoline; -#endif + if (isWifiAvailable()) { + // call a method on debugInfoScreen object (for more details) + normalFrames[numframes++] = &Screen::drawDebugInfoWiFiTrampoline; + } ui.setFrames(normalFrames, numframes); ui.enableAllIndicators(); diff --git a/src/main.cpp b/src/main.cpp index 81038030d..cc0c9a0c3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -327,10 +327,8 @@ void setup() } #endif -#if WiFi_MODE // Initialize Wifi initWifi(); -#endif if (!rIf) recordCriticalError(ErrNoRadio); @@ -423,10 +421,8 @@ void loop() // feel slow msecstosleep = 10; -#if WiFi_MODE // TODO: This should go into a thread handled by FreeRTOS. handleWebResponse(); -#endif delay(msecstosleep); } diff --git a/src/meshwifi/meshhttp.cpp b/src/meshwifi/meshhttp.cpp index b70b8fc29..f52cade57 100644 --- a/src/meshwifi/meshhttp.cpp +++ b/src/meshwifi/meshhttp.cpp @@ -3,8 +3,8 @@ #include "configuration.h" #include "main.h" #include "NodeDB.h" -#include "meshwifi.h" -#include "meshhttp.h" +#include "meshwifi/meshwifi.h" +#include "meshwifi/meshhttp.h" WebServer webserver(80); @@ -14,6 +14,10 @@ String sender = ""; void handleWebResponse() { + if (isWifiAvailable() == 0) { + return; + } + webserver.handleClient(); } diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index 19a52bf51..72d6e09f8 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/meshwifi/meshwifi.cpp @@ -5,14 +5,34 @@ #include "NodeDB.h" #include "meshwifi/meshhttp.h" +bool isWifiAvailable() +{ + const char *wifiName = radioConfig.preferences.wifi_ssid; + const char *wifiPsw = radioConfig.preferences.wifi_password; + + if (*wifiName && *wifiPsw) { + return 1; + } else { + return 0; + } +} + +// Disable WiFi void deinitWifi() { WiFi.mode(WIFI_MODE_NULL); DEBUG_MSG("WiFi Turned Off\n"); } + +// Startup WiFi void initWifi() { + + if (isWifiAvailable() == 0) { + return; + } + //strcpy(radioConfig.preferences.wifi_ssid, WiFi_SSID_NAME); //strcpy(radioConfig.preferences.wifi_password, WiFi_SSID_PASSWORD); if (radioConfig.has_preferences) { diff --git a/src/meshwifi/meshwifi.h b/src/meshwifi/meshwifi.h index a20a114aa..2413a2a22 100644 --- a/src/meshwifi/meshwifi.h +++ b/src/meshwifi/meshwifi.h @@ -12,3 +12,4 @@ void deinitWifi(); void WiFiEvent(WiFiEvent_t event); +bool isWifiAvailable(); \ No newline at end of file From 73b47a78aa78433526f8f30e0a14add4fdf9baea Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Wed, 16 Sep 2020 22:31:07 -0700 Subject: [PATCH 8/9] Clean up and added comments about the esp32 sdk bug --- src/meshwifi/meshwifi.cpp | 82 ++++++++++++++++++------------------ src/meshwifi/meshwifi.h | 2 - src/nimble/BluetoothUtil.cpp | 4 +- 3 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index 72d6e09f8..dff6ffeeb 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/meshwifi/meshwifi.cpp @@ -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); - } - } -} +} \ No newline at end of file diff --git a/src/meshwifi/meshwifi.h b/src/meshwifi/meshwifi.h index 2413a2a22..044839ab6 100644 --- a/src/meshwifi/meshwifi.h +++ b/src/meshwifi/meshwifi.h @@ -4,8 +4,6 @@ #include #include -void reconnectWiFi(); - void initWifi(); void deinitWifi(); diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index 00e7deea1..a78b0098f 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -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() ); From 64710a6a04f60130da18e7da5e00a14c19789836 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Wed, 16 Sep 2020 23:16:11 -0700 Subject: [PATCH 9/9] renamed reconnectWiFi to initWifi --- src/meshwifi/meshwifi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index dff6ffeeb..14ac8a2a7 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/meshwifi/meshwifi.cpp @@ -97,7 +97,7 @@ void WiFiEvent(WiFiEvent_t event) DEBUG_MSG("Disconnected from WiFi access point\n"); // Reconnect WiFi - reconnectWiFi(); + initWifi(); break; case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: DEBUG_MSG("Authentication mode of access point has changed\n");