diff --git a/proto b/proto index ce422b7c..4e431c84 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit ce422b7c448906c6fee3eef64bbd41adfbc990f0 +Subproject commit 4e431c841015edfdde925acf5ee4ac0a2272edff diff --git a/src/esp32/WiFiServerAPI.cpp b/src/esp32/WiFiServerAPI.cpp index b5d55560..974b0f3c 100644 --- a/src/esp32/WiFiServerAPI.cpp +++ b/src/esp32/WiFiServerAPI.cpp @@ -44,7 +44,7 @@ WiFiServerPort::WiFiServerPort() : WiFiServer(MESHTASTIC_PORTNUM) {} void WiFiServerPort::init() { - DEBUG_MSG("Listening on TCP port %d\n", MESHTASTIC_PORTNUM); + DEBUG_MSG("API server sistening on TCP port %d\n", MESHTASTIC_PORTNUM); begin(); } diff --git a/src/main.cpp b/src/main.cpp index b0d133f2..bb4b12e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,12 +37,12 @@ #include "SPILock.h" #include "graphics/Screen.h" #include "main.h" +#include "meshwifi/meshhttp.h" +#include "meshwifi/meshwifi.h" #include "sleep.h" #include "timing.h" #include #include -#include "meshwifi/meshwifi.h" -#include "meshwifi/meshhttp.h" // #include #ifndef NO_ESP32 @@ -395,6 +395,8 @@ void loop() userButtonAlt.tick(); #endif + loopWifi(); + // Show boot screen for first 3 seconds, then switch to normal operation. static bool showingBootScreen = true; if (showingBootScreen && (timing::millis() > 3000)) { diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index e31065ef..1e86e4d6 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/meshwifi/meshwifi.cpp @@ -1,5 +1,6 @@ #include "meshwifi.h" #include "NodeDB.h" +#include "WiFiServerAPI.h" #include "configuration.h" #include "main.h" #include "meshwifi/meshhttp.h" @@ -9,6 +10,7 @@ static void WiFiEvent(WiFiEvent_t event); DNSServer dnsServer; +static WiFiServerPort *apiPort; bool isWifiAvailable() { @@ -96,6 +98,23 @@ void initWifi() DEBUG_MSG("Not using WIFI\n"); } +/// Perform idle loop processing required by the wifi layer +void loopWifi() +{ + // FIXME, once we have coroutines - just use a coroutine instead of this nasty loopWifi() + if (apiPort) + apiPort->loop(); +} + +static void initApiServer() +{ + // Start API server on port 4403 + if (!apiPort) { + apiPort = new WiFiServerPort(); + apiPort->init(); + } +} + static void WiFiEvent(WiFiEvent_t event) { DEBUG_MSG("************ [WiFi-event] event: %d ************\n", event); @@ -131,6 +150,7 @@ static void WiFiEvent(WiFiEvent_t event) // Start web server initWebServer(); + initApiServer(); break; case SYSTEM_EVENT_STA_LOST_IP: @@ -154,6 +174,7 @@ static void WiFiEvent(WiFiEvent_t event) // Start web server initWebServer(); + initApiServer(); break; case SYSTEM_EVENT_AP_STOP: diff --git a/src/meshwifi/meshwifi.h b/src/meshwifi/meshwifi.h index bcafa700..8898c0ad 100644 --- a/src/meshwifi/meshwifi.h +++ b/src/meshwifi/meshwifi.h @@ -11,6 +11,10 @@ void initWifi(); void deinitWifi(); + +/// Perform idle loop processing required by the wifi layer +void loopWifi(); + bool isWifiAvailable(); void handleDNSResponse(); diff --git a/src/nrf52/wifi-nrf52.cpp b/src/nrf52/wifi-nrf52.cpp index e4885add..30321e5e 100644 --- a/src/nrf52/wifi-nrf52.cpp +++ b/src/nrf52/wifi-nrf52.cpp @@ -10,4 +10,7 @@ bool isWifiAvailable() return false; } -void handleWebResponse() {} \ No newline at end of file +void handleWebResponse() {} + +/// Perform idle loop processing required by the wifi layer +void loopWifi() {} \ No newline at end of file