Files
MeshCore/test/fixtures/webconfig_station_owner.cpp
mikecarper 6b3f7df4d0 Suspend failed ESP32 MQTT and NTP uplinks for power saving
Share one bounded WiFi outage and recovery schedule across MQTT, automatic NTP, Companion station ownership and WebConfig. Preserve enabled settings and foreground access while allowing normal sleep after confirmed physical shutdown.

Honor failed SDK client stops before handing off WiFi, protect clean teardown and reconfiguration, and retry transient ESP-NOW channel restoration without repeated disconnects. Add production-method, SDK failure and real sleep regressions to CI.

Validation: native MQTT/NTP/clock/reconnect suites; production power and wrapper failure tests; browser, room HTTP, OTA and combined bridge regressions; Full Heltec V4 repeater, room and companion builds with capability, flash and linked-memory checks.
2026-10-12 14:57:01 -07:00

72 lines
2.4 KiB
C++

#include <cassert>
#include <cstring>
#include <new>
#include <helpers/WirelessControl.h>
struct Worker {
bool running = false, stopping = false;
bool isRunning() const { return running; }
bool isStopping() const { return stopping; }
};
struct Board {
bool isOTAUpdateRunning() const { return false; }
const char* getManufacturerName() const { return "Station G2"; }
} board;
struct CLI {
Board* getBoard() { return &board; }
void* getObserverPrefs() { return this; }
};
struct WebConfigServer {
bool owns, constructor_owns;
WebConfigServer(void*, void*, bool owner, const unsigned char*,
const char*, const char*, const char*, const char*, bool canonical)
: owns(owner), constructor_owns(owner) { assert(canonical); }
bool isRunning() const { return false; }
bool isStopping() const { return false; }
void updateWiFiOwnership(bool owner) { owns = owner; }
void requestNetworkAccess() {}
bool startAutoMode(char* reply) { strcpy(reply, "starting"); return true; }
bool startSetupMode(char* reply) { strcpy(reply, "setup"); return true; }
};
struct MyMesh {
Worker* @WORKER@ = nullptr;
CLI _cli;
WebConfigServer* _webconfig = nullptr;
bool _unconfigured_setup_espnow_suspended = false;
bool isMqttBridgeRunning() const { return @WORKER@ && @WORKER@->isRunning(); }
bool isMqttBridgeStopping() const { return @WORKER@ && @WORKER@->isStopping(); }
struct { unsigned char pub_key[32] = {}; } self_id;
const char* getFirmwareVer() const { return "test"; }
const char* getBuildDate() const { return "test"; }
const char* getRole() const { return "test"; }
bool startWebConfig(bool force_ap, char* reply);
bool startWebConfigImpl(bool force_ap, char* reply, bool automatic_setup);
void suspendUnconfiguredSetupBridges();
void refresh() {
@REFRESH@
}
};
@START@
@SUSPEND@
int main() {
MyMesh mesh;
Worker worker;
mesh.@WORKER@ = &worker;
char reply[160] = {};
mesh.startWebConfig(false, reply);
assert(mesh._webconfig->constructor_owns && mesh._webconfig->owns);
worker.running = true;
mesh.refresh();
assert(!mesh._webconfig->owns);
worker.running = false;
worker.stopping = true;
mesh.refresh();
assert(!mesh._webconfig->owns);
worker.stopping = false;
mesh.refresh();
assert(mesh._webconfig->owns);
mesh.@WORKER@ = nullptr;
mesh.refresh();
assert(mesh._webconfig->owns);
delete mesh._webconfig;
}