diff --git a/examples/simple_room_server/MyMesh.cpp b/examples/simple_room_server/MyMesh.cpp index 18ae2ad1..de5507da 100644 --- a/examples/simple_room_server/MyMesh.cpp +++ b/examples/simple_room_server/MyMesh.cpp @@ -782,6 +782,15 @@ void MyMesh::begin(FILESYSTEM *fs) { } } #endif + + // Wire fault-alert reporter. begin() is safe regardless of bridge state. + // Passing `this` as the callbacks lets the reporter resolve a TransportKey + // scope (alert.region override, falling back to default_scope) so alert + // floods ride the same scope as adverts/channel messages. + _alerter.begin(&_prefs, this, this); +#if defined(WITH_MQTT_BRIDGE) + _alerter.setBridge(bridge); +#endif } void MyMesh::sendFloodScoped(const TransportKey& scope, mesh::Packet* pkt, uint32_t delay_millis, uint8_t path_hash_size) { @@ -797,9 +806,6 @@ void MyMesh::sendFloodScoped(const TransportKey& scope, mesh::Packet* pkt, uint3 bool MyMesh::resolveAlertScope(TransportKey& dest) { // Same resolution policy as simple_repeater: alert.region > default_scope. - // The room server doesn't currently embed an AlertReporter, but keeping - // the override in lockstep means the callback path works the same on both - // builds and we won't get caught out if/when it does. if (_prefs.alert_region[0]) { auto r = region_map.findByNamePrefix(_prefs.alert_region); if (r && region_map.getTransportKeysFor(*r, &dest, 1) > 0 && !dest.isNull()) { @@ -1124,4 +1130,6 @@ void MyMesh::loop() { uint32_t now = millis(); uptime_millis += now - last_millis; last_millis = now; + + _alerter.onLoop(now); } diff --git a/examples/simple_room_server/MyMesh.h b/examples/simple_room_server/MyMesh.h index 874aa04c..afc4828c 100644 --- a/examples/simple_room_server/MyMesh.h +++ b/examples/simple_room_server/MyMesh.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -125,6 +126,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { #ifdef WITH_MQTT_BRIDGE MQTTBridge* bridge; #endif + AlertReporter _alerter; void addPost(ClientInfo* client, const char* postData); void pushPostToClient(ClientInfo* client, PostInfo& post); @@ -198,6 +200,9 @@ public: // CommonCLICallbacks void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override; + + void onAlertConfigChanged() override { _alerter.onConfigChanged(); } + bool sendAlertText(const char* text) override { return _alerter.sendText(text); } bool resolveAlertScope(TransportKey& dest) override; bool formatFileSystem() override; void sendSelfAdvertisement(int delay_millis, bool flood) override; @@ -254,10 +259,16 @@ public: bridge->setStatsSources(this, _radio, _cli.getBoard(), _ms); #endif bridge->begin(); +#ifdef WITH_MQTT_BRIDGE + _alerter.setBridge(bridge); +#endif } else { bridge->end(); +#ifdef WITH_MQTT_BRIDGE + _alerter.setBridge(nullptr); +#endif } }