feat: abstract MQTT network transport

This commit is contained in:
agessaman committed 2026-09-01 16:31:28 -07:00
1 parent f8fc35a11a
commit 03c0ad81fe
19 files changed
+731 -306

No files matched your search

+22 -4
View File
@@ -1,6 +1,11 @@
#include "MyMesh.h"
#include <algorithm>
#include <climits>
#include <helpers/RxReservePacketManager.h>
#include <helpers/NetworkInterface.h>
#if defined(ESP_PLATFORM) && !defined(NETWORK_USE_ETHERNET)
#include <WiFi.h>
#endif
#if defined(WITH_MQTT_NEIGHBORS)
#include <helpers/MQTTConnectionPolicy.h> // kSyncedClockEpoch
#endif
@@ -1020,11 +1025,13 @@ void MyMesh::begin(FILESYSTEM *fs) {
#if defined(WITH_WEBCONFIG) && !defined(WEBCONFIG_NO_AUTO_AP)
// First-boot setup portal: raised only when no WiFi has ever been configured,
// so an OTA onto a deployed (configured) node can never open an AP.
#if !defined(NETWORK_USE_ETHERNET)
if (_cli.getObserverPrefs()->wifi_ssid[0] == 0) {
char wc_reply[160];
startWebConfig(false, wc_reply);
Serial.println(wc_reply);
}
#endif
#endif
}
@@ -1269,6 +1276,11 @@ void MyMesh::formatPacketStatsReply(char *reply) {
#ifdef WITH_WEBCONFIG
bool MyMesh::startWebConfig(bool force_ap, char* reply) {
#if defined(NETWORK_USE_ETHERNET)
(void)force_ap;
strcpy(reply, "Err: webconfig unavailable on Ethernet observer; use serial CLI");
return true;
#else
if (_webconfig && (_webconfig->isRunning() || _webconfig->isStopping())) {
strcpy(reply, _webconfig->isStopping() ? "Err: webconfig still stopping, retry shortly"
: "Err: webconfig already running");
@@ -1292,6 +1304,7 @@ bool MyMesh::startWebConfig(bool force_ap, char* reply) {
_webconfig->startLanMode(reply); // reports "WiFi not connected" if down
}
return true;
#endif
}
bool MyMesh::stopWebConfig(char* reply) {
@@ -1325,12 +1338,17 @@ void MyMesh::onConfigBatchEnd() {
void MyMesh::buildStatsJson(char* buf, size_t buf_size) {
char ip[20] = "";
int wifi_rssi = 0;
if (WiFi.status() == WL_CONNECTED) {
strncpy(ip, WiFi.localIP().toString().c_str(), sizeof(ip) - 1);
wifi_rssi = WiFi.RSSI();
} else if (_webconfig && _webconfig->mode() == WebConfigServer::MODE_SETUP) {
NetworkInterface& network = activeNetworkInterface();
if (network.isConnected()) {
strncpy(ip, network.localIP().toString().c_str(), sizeof(ip) - 1);
const int signal = network.rssi();
wifi_rssi = signal == INT_MIN ? 0 : signal;
}
#if !defined(NETWORK_USE_ETHERNET)
else if (_webconfig && _webconfig->mode() == WebConfigServer::MODE_SETUP) {
strncpy(ip, WiFi.softAPIP().toString().c_str(), sizeof(ip) - 1);
}
#endif
int pos = snprintf(buf, buf_size,
"{\"uptime_s\":%lu,\"batt_mv\":%u,"
"\"heap_free\":%lu,\"heap_min\":%lu,\"heap_max_alloc\":%lu,"