From 86952c5456e2ae5f111b7a7f171ad41508232ebe Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sat, 12 Dec 2020 22:37:07 -0800 Subject: [PATCH] Fixed #541 - Work around to bug in espressif softap event handler --- src/graphics/Screen.cpp | 5 ++++- src/meshwifi/meshhttp.cpp | 7 ++++--- src/meshwifi/meshwifi.cpp | 19 ++++++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index bc43ae85..c112a295 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1009,12 +1009,15 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i - WL_NO_SHIELD: assigned when no WiFi shield is present; */ - if (WiFi.status() == WL_CONNECTED || isSoftAPForced()) { + if (WiFi.status() == WL_CONNECTED || isSoftAPForced() || radioConfig.preferences.wifi_ap_mode) { if (radioConfig.preferences.wifi_ap_mode || isSoftAPForced()) { display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "IP: " + String(WiFi.softAPIP().toString().c_str())); } else { display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "IP: " + String(WiFi.localIP().toString().c_str())); } + display->drawString(x + SCREEN_WIDTH - display->getStringWidth("(" + String(WiFi.softAPgetStationNum()) + "/4)"), + y + FONT_HEIGHT_SMALL * 1, "(" + String(WiFi.softAPgetStationNum()) + "/4)"); + } else if (WiFi.status() == WL_NO_SSID_AVAIL) { display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "SSID Not Found"); } else if (WiFi.status() == WL_CONNECTION_LOST) { diff --git a/src/meshwifi/meshhttp.cpp b/src/meshwifi/meshhttp.cpp index d0940d06..c09e6ac4 100644 --- a/src/meshwifi/meshhttp.cpp +++ b/src/meshwifi/meshhttp.cpp @@ -178,9 +178,10 @@ void createSSLCert() NULL); /* Task handle. */ DEBUG_MSG("Waiting for SSL Cert to be generated.\n"); - if (isCertReady) { - DEBUG_MSG(".\n"); - delayMicroseconds(1000); + while (!isCertReady) { + DEBUG_MSG("."); + delay(1000); + yield(); } DEBUG_MSG("SSL Cert Ready!\n"); } diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index da3af6a5..16ae6185 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/meshwifi/meshwifi.cpp @@ -23,6 +23,8 @@ char ourHost[16]; bool forcedSoftAP = 0; +bool APStartupComplete = 0; + bool isSoftAPForced() { return forcedSoftAP; @@ -41,6 +43,10 @@ bool isWifiAvailable() // strcpy(radioConfig.preferences.wifi_ssid, ""); // strcpy(radioConfig.preferences.wifi_password, ""); + // strcpy(radioConfig.preferences.wifi_ssid, "meshtasticAdmin"); + // strcpy(radioConfig.preferences.wifi_password, "12345678"); + // radioConfig.preferences.wifi_ap_mode = true; + if (*wifiName && *wifiPsw) { return 1; } else { @@ -239,9 +245,16 @@ static void WiFiEvent(WiFiEvent_t event) DEBUG_MSG("WiFi access point started\n"); Serial.println(WiFi.softAPIP()); - // Start web server - initWebServer(); - initApiServer(); + if (!APStartupComplete) { + // Start web server + DEBUG_MSG("... Starting network services\n"); + initWebServer(); + initApiServer(); + + APStartupComplete = true; + } else { + DEBUG_MSG("... Not starting network services\n"); + } break; case SYSTEM_EVENT_AP_STOP: