diff --git a/src/esp32/WiFiServerAPI.cpp b/src/esp32/WiFiServerAPI.cpp index 109340bff..aa5963882 100644 --- a/src/esp32/WiFiServerAPI.cpp +++ b/src/esp32/WiFiServerAPI.cpp @@ -33,7 +33,7 @@ void WiFiServerAPI::loop() if (client.connected()) { StreamAPI::loop(); } else { - DEBUG_MSG("Client dropped connection, closing UDP server\n"); + DEBUG_MSG("Client dropped connection, closing TCP server\n"); delete this; } } diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 14a202458..0706ddb44 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -942,7 +942,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i } else if (getWifiDisconnectReason() == 200) { display->drawString(x, y + FONT_HEIGHT * 1, "BEACON_TIMEOUT"); } else if (getWifiDisconnectReason() == 201) { - display->drawString(x, y + FONT_HEIGHT * 1, "NO_AP_FOUND"); + display->drawString(x, y + FONT_HEIGHT * 1, "AP Not Found"); } else if (getWifiDisconnectReason() == 202) { display->drawString(x, y + FONT_HEIGHT * 1, "AUTH_FAIL"); } else if (getWifiDisconnectReason() == 203) { @@ -950,7 +950,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i } else if (getWifiDisconnectReason() == 204) { display->drawString(x, y + FONT_HEIGHT * 1, "HANDSHAKE_TIMEOUT"); } else if (getWifiDisconnectReason() == 205) { - display->drawString(x, y + FONT_HEIGHT * 1, "CONNECTION_FAIL"); + display->drawString(x, y + FONT_HEIGHT * 1, "Connection Failed"); } else { display->drawString(x, y + FONT_HEIGHT * 1, "Unknown Status"); } @@ -992,8 +992,10 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat display->drawString(x, y, String("USB")); } - // TODO: Display status of the BT radio - // display->drawString(x + SCREEN_WIDTH - display->getStringWidth("BT On"), y, "BT On"); + display->drawString(x + SCREEN_WIDTH - display->getStringWidth("Mode " + String(channelSettings.modem_config)), + y, "Mode " + String(channelSettings.modem_config)); + + // Line 2 uint32_t currentMillis = millis(); @@ -1009,8 +1011,6 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat display->drawString(x, y + FONT_HEIGHT * 1, String(days) + "d " + (hours < 10 ? "0" : "") + String(hours) + ":" + (minutes < 10 ? "0" : "") + String(minutes) + ":" + (seconds < 10 ? "0" : "") + String(seconds)); - display->drawString(x + SCREEN_WIDTH - display->getStringWidth("Mode " + String(channelSettings.modem_config)), - y + FONT_HEIGHT * 1, "Mode " + String(channelSettings.modem_config)); // Line 4 drawGPScoordinates(display, x, y + FONT_HEIGHT * 3, gpsStatus); diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index 84a9a5a57..0c775b5c8 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/meshwifi/meshwifi.cpp @@ -8,9 +8,10 @@ #include static void WiFiEvent(WiFiEvent_t event); -// static void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info); +// DNS Server for the Captive Portal DNSServer dnsServer; + static WiFiServerPort *apiPort; uint8_t wifiDisconnectReason = 0; @@ -60,18 +61,6 @@ void initWifi() const char *wifiName = radioConfig.preferences.wifi_ssid; const char *wifiPsw = radioConfig.preferences.wifi_password; - /* - if (0) { - radioConfig.preferences.wifi_ap_mode = 1; - strcpy(radioConfig.preferences.wifi_ssid, "MeshTest2"); - strcpy(radioConfig.preferences.wifi_password, "12345678"); - } else { - radioConfig.preferences.wifi_ap_mode = 0; - strcpy(radioConfig.preferences.wifi_ssid, "meshtastic"); - strcpy(radioConfig.preferences.wifi_password, "meshtastic!"); - } - */ - if (*wifiName && *wifiPsw) { if (radioConfig.preferences.wifi_ap_mode) { @@ -89,11 +78,20 @@ void initWifi() WiFi.onEvent(WiFiEvent); // esp_wifi_set_ps(WIFI_PS_NONE); // Disable power saving - WiFiEventId_t eventID = WiFi.onEvent( + //WiFiEventId_t eventID = WiFi.onEvent( + WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) { Serial.print("\nWiFi lost connection. Reason: "); Serial.println(info.disconnected.reason); - // wifiDisconnectReason = info.disconnected.reason; + + /* + If we are disconnected from the AP for some reason, + save the error code. + + For a reference to the codes: + https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#wi-fi-reason-code + */ + wifiDisconnectReason = info.disconnected.reason; }, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED); @@ -125,6 +123,8 @@ static void initApiServer() apiPort->init(); } } + +// Called by the Espressif SDK to static void WiFiEvent(WiFiEvent_t event) { DEBUG_MSG("************ [WiFi-event] event: %d ************\n", event); @@ -249,7 +249,7 @@ void reconnectWiFi() } } -uint8_t getWifiDisconnectReason() +uint8_t getWifiDisconnectReason() { return wifiDisconnectReason; } \ No newline at end of file diff --git a/src/meshwifi/meshwifi.h b/src/meshwifi/meshwifi.h index d38b2a41e..f22d69a63 100644 --- a/src/meshwifi/meshwifi.h +++ b/src/meshwifi/meshwifi.h @@ -21,4 +21,5 @@ void handleDNSResponse(); void reconnectWiFi(); -uint8_t getWifiDisconnectReason(); \ No newline at end of file +uint8_t getWifiDisconnectReason(); +