mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-12 16:12:07 +00:00
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:
parent
0929b86d62
commit
9e9c50e6d8
2
proto
2
proto
@ -1 +1 @@
|
|||||||
Subproject commit ce422b7c448906c6fee3eef64bbd41adfbc990f0
|
Subproject commit 4e431c841015edfdde925acf5ee4ac0a2272edff
|
@ -44,7 +44,7 @@ WiFiServerPort::WiFiServerPort() : WiFiServer(MESHTASTIC_PORTNUM) {}
|
|||||||
|
|
||||||
void WiFiServerPort::init()
|
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();
|
begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,12 +37,12 @@
|
|||||||
#include "SPILock.h"
|
#include "SPILock.h"
|
||||||
#include "graphics/Screen.h"
|
#include "graphics/Screen.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "meshwifi/meshhttp.h"
|
||||||
|
#include "meshwifi/meshwifi.h"
|
||||||
#include "sleep.h"
|
#include "sleep.h"
|
||||||
#include "timing.h"
|
#include "timing.h"
|
||||||
#include <OneButton.h>
|
#include <OneButton.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include "meshwifi/meshwifi.h"
|
|
||||||
#include "meshwifi/meshhttp.h"
|
|
||||||
// #include <driver/rtc_io.h>
|
// #include <driver/rtc_io.h>
|
||||||
|
|
||||||
#ifndef NO_ESP32
|
#ifndef NO_ESP32
|
||||||
@ -395,6 +395,8 @@ void loop()
|
|||||||
userButtonAlt.tick();
|
userButtonAlt.tick();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
loopWifi();
|
||||||
|
|
||||||
// Show boot screen for first 3 seconds, then switch to normal operation.
|
// Show boot screen for first 3 seconds, then switch to normal operation.
|
||||||
static bool showingBootScreen = true;
|
static bool showingBootScreen = true;
|
||||||
if (showingBootScreen && (timing::millis() > 3000)) {
|
if (showingBootScreen && (timing::millis() > 3000)) {
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
#include "meshwifi.h"
|
#include "meshwifi.h"
|
||||||
#include "NodeDB.h"
|
#include "NodeDB.h"
|
||||||
|
#include "WiFiServerAPI.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "meshwifi/meshhttp.h"
|
#include "meshwifi/meshhttp.h"
|
||||||
#include <WiFi.h>
|
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
static void WiFiEvent(WiFiEvent_t event);
|
static void WiFiEvent(WiFiEvent_t event);
|
||||||
|
|
||||||
DNSServer dnsServer;
|
DNSServer dnsServer;
|
||||||
|
static WiFiServerPort *apiPort;
|
||||||
|
|
||||||
bool isWifiAvailable()
|
bool isWifiAvailable()
|
||||||
{
|
{
|
||||||
const char *wifiName = radioConfig.preferences.wifi_ssid;
|
const char *wifiName = radioConfig.preferences.wifi_ssid;
|
||||||
const char *wifiPsw = radioConfig.preferences.wifi_password;
|
const char *wifiPsw = radioConfig.preferences.wifi_password;
|
||||||
@ -66,7 +68,7 @@ void initWifi()
|
|||||||
|
|
||||||
if (*wifiName && *wifiPsw) {
|
if (*wifiName && *wifiPsw) {
|
||||||
if (radioConfig.preferences.wifi_ap_mode) {
|
if (radioConfig.preferences.wifi_ap_mode) {
|
||||||
|
|
||||||
IPAddress apIP(192, 168, 42, 1);
|
IPAddress apIP(192, 168, 42, 1);
|
||||||
WiFi.onEvent(WiFiEvent);
|
WiFi.onEvent(WiFiEvent);
|
||||||
|
|
||||||
@ -76,7 +78,6 @@ void initWifi()
|
|||||||
|
|
||||||
dnsServer.start(53, "*", apIP);
|
dnsServer.start(53, "*", apIP);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
WiFi.mode(WIFI_MODE_STA);
|
WiFi.mode(WIFI_MODE_STA);
|
||||||
WiFi.onEvent(WiFiEvent);
|
WiFi.onEvent(WiFiEvent);
|
||||||
@ -94,6 +95,23 @@ void initWifi()
|
|||||||
DEBUG_MSG("Not using WIFI\n");
|
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)
|
static void WiFiEvent(WiFiEvent_t event)
|
||||||
{
|
{
|
||||||
DEBUG_MSG("************ [WiFi-event] event: %d ************\n", event);
|
DEBUG_MSG("************ [WiFi-event] event: %d ************\n", event);
|
||||||
@ -129,6 +147,7 @@ static void WiFiEvent(WiFiEvent_t event)
|
|||||||
|
|
||||||
// Start web server
|
// Start web server
|
||||||
initWebServer();
|
initWebServer();
|
||||||
|
initApiServer();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_STA_LOST_IP:
|
case SYSTEM_EVENT_STA_LOST_IP:
|
||||||
@ -152,6 +171,7 @@ static void WiFiEvent(WiFiEvent_t event)
|
|||||||
|
|
||||||
// Start web server
|
// Start web server
|
||||||
initWebServer();
|
initWebServer();
|
||||||
|
initApiServer();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_AP_STOP:
|
case SYSTEM_EVENT_AP_STOP:
|
||||||
@ -189,11 +209,11 @@ static void WiFiEvent(WiFiEvent_t event)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleDNSResponse() {
|
void handleDNSResponse()
|
||||||
|
{
|
||||||
if (radioConfig.preferences.wifi_ap_mode) {
|
if (radioConfig.preferences.wifi_ap_mode) {
|
||||||
dnsServer.processNextRequest();
|
dnsServer.processNextRequest();
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,16 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#ifdef HAS_WIFI
|
#ifdef HAS_WIFI
|
||||||
#include <WiFi.h>
|
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
|
#include <WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void initWifi();
|
void initWifi();
|
||||||
void deinitWifi();
|
void deinitWifi();
|
||||||
|
|
||||||
|
/// Perform idle loop processing required by the wifi layer
|
||||||
|
void loopWifi();
|
||||||
|
|
||||||
bool isWifiAvailable();
|
bool isWifiAvailable();
|
||||||
|
|
||||||
void handleDNSResponse();
|
void handleDNSResponse();
|
||||||
|
@ -10,4 +10,7 @@ bool isWifiAvailable()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleWebResponse() {}
|
void handleWebResponse() {}
|
||||||
|
|
||||||
|
/// Perform idle loop processing required by the wifi layer
|
||||||
|
void loopWifi() {}
|
Loading…
Reference in New Issue
Block a user