Merge pull request #440 from mc-hamster/master

Merging from my fork into master for some cleanup, more code comments, reduce compile warnings and move the "Mode" text up a line.
This commit is contained in:
Jm Casler 2020-09-26 00:20:27 -07:00 committed by GitHub
commit 9c7aa02db8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 24 deletions

View File

@ -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;
}
}

View File

@ -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);

View File

@ -8,9 +8,10 @@
#include <WiFi.h>
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;
}

View File

@ -21,4 +21,5 @@ void handleDNSResponse();
void reconnectWiFi();
uint8_t getWifiDisconnectReason();
uint8_t getWifiDisconnectReason();