Add API server on port 4403 (kinda a WIP, seems to work but I haven't

finished the python client code)
This commit is contained in:
geeksville
2020-09-19 12:54:49 -07:00
parent 0929b86d62
commit 9e9c50e6d8
6 changed files with 41 additions and 12 deletions

View File

@@ -1,16 +1,18 @@
#include "meshwifi.h"
#include "NodeDB.h"
#include "WiFiServerAPI.h"
#include "configuration.h"
#include "main.h"
#include "meshwifi/meshhttp.h"
#include <WiFi.h>
#include <DNSServer.h>
#include <WiFi.h>
static void WiFiEvent(WiFiEvent_t event);
DNSServer dnsServer;
static WiFiServerPort *apiPort;
bool isWifiAvailable()
bool isWifiAvailable()
{
const char *wifiName = radioConfig.preferences.wifi_ssid;
const char *wifiPsw = radioConfig.preferences.wifi_password;
@@ -66,7 +68,7 @@ void initWifi()
if (*wifiName && *wifiPsw) {
if (radioConfig.preferences.wifi_ap_mode) {
IPAddress apIP(192, 168, 42, 1);
WiFi.onEvent(WiFiEvent);
@@ -76,7 +78,6 @@ void initWifi()
dnsServer.start(53, "*", apIP);
} else {
WiFi.mode(WIFI_MODE_STA);
WiFi.onEvent(WiFiEvent);
@@ -94,6 +95,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);
@@ -129,6 +147,7 @@ static void WiFiEvent(WiFiEvent_t event)
// Start web server
initWebServer();
initApiServer();
break;
case SYSTEM_EVENT_STA_LOST_IP:
@@ -152,6 +171,7 @@ static void WiFiEvent(WiFiEvent_t event)
// Start web server
initWebServer();
initApiServer();
break;
case SYSTEM_EVENT_AP_STOP:
@@ -189,11 +209,11 @@ static void WiFiEvent(WiFiEvent_t event)
break;
default:
break;
}
}
void handleDNSResponse() {
void handleDNSResponse()
{
if (radioConfig.preferences.wifi_ap_mode) {
dnsServer.processNextRequest();
}