Add fault alert functionality for WiFi and MQTT disconnections
Implemented a new fault alert system that broadcasts notifications over LoRa when WiFi or MQTT connections are down for a specified duration. The alerts are configurable via CLI commands, allowing operators to set private PSKs or hashtags for alert channels. Default settings for alert thresholds and intervals are established, and the system ensures that alerts do not spam the public channel. Updated relevant files to integrate this feature into the MyMesh implementations and CLI handling.
This commit is contained in:
1 parent
08847342c5
commit
80355f32ab
10 files changed
+792
-2
No files matched your search
@@ -947,6 +947,19 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
|
||||
#endif
|
||||
_prefs.radio_watchdog_minutes = 5; // 5 minutes default
|
||||
|
||||
// Alert channel defaults — disabled by default, and the channel is left
|
||||
// unconfigured so a freshly-flashed observer never broadcasts on the
|
||||
// well-known Public hashtag. Operators must explicitly pick a private
|
||||
// key (`set alert.psk`) or a hashtag (`set alert.hashtag`) before alerts
|
||||
// can fire. The sender prefix on outgoing alert messages is always the
|
||||
// node name (`set name ...`), so there's no separate `alert.name`.
|
||||
_prefs.alert_enabled = 0;
|
||||
_prefs.alert_psk_b64[0] = '\0';
|
||||
_prefs.alert_hashtag[0] = '\0';
|
||||
_prefs.alert_wifi_minutes = 30; // 30 minutes
|
||||
_prefs.alert_mqtt_minutes = 240; // 4 hours
|
||||
_prefs.alert_min_interval_min = 60; // re-arm window: 1 hour
|
||||
|
||||
// bridge defaults
|
||||
_prefs.bridge_enabled = 1; // enabled
|
||||
_prefs.bridge_delay = 500; // milliseconds
|
||||
@@ -1074,6 +1087,12 @@ void MyMesh::begin(FILESYSTEM *fs) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Wire fault-alert reporter. begin() is safe regardless of bridge state.
|
||||
_alerter.begin(&_prefs, this);
|
||||
#if defined(WITH_MQTT_BRIDGE)
|
||||
_alerter.setBridge(bridge);
|
||||
#endif
|
||||
|
||||
radio_driver.setParams(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
|
||||
radio_driver.setTxPower(_prefs.tx_power_dbm);
|
||||
|
||||
@@ -1425,6 +1444,8 @@ void MyMesh::loop() {
|
||||
uptime_millis += now - last_millis;
|
||||
last_millis = now;
|
||||
|
||||
_alerter.onLoop(now);
|
||||
|
||||
#ifdef WITH_SNMP
|
||||
// Push radio stats to SNMP agent every 2 seconds
|
||||
if (_snmp_agent.isRunning()) {
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#endif
|
||||
|
||||
#include <helpers/AdvertDataHelpers.h>
|
||||
#include <helpers/AlertReporter.h>
|
||||
#include <helpers/ArduinoHelpers.h>
|
||||
#include <helpers/ClientACL.h>
|
||||
#include <helpers/CommonCLI.h>
|
||||
@@ -130,6 +131,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
||||
#ifdef WITH_SNMP
|
||||
MeshSNMPAgent _snmp_agent;
|
||||
#endif
|
||||
AlertReporter _alerter;
|
||||
|
||||
void putNeighbour(const mesh::Identity& id, uint32_t timestamp, float snr);
|
||||
uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood);
|
||||
@@ -211,6 +213,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 formatFileSystem() override;
|
||||
void sendSelfAdvertisement(int delay_millis, bool flood) override;
|
||||
void updateAdvertTimer() override;
|
||||
@@ -265,10 +270,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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -675,6 +675,15 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
|
||||
_prefs.gps_interval = 0;
|
||||
_prefs.advert_loc_policy = ADVERT_LOC_PREFS;
|
||||
|
||||
// Alert channel defaults (same as repeater; off by default and unconfigured).
|
||||
// Operator must pick `set alert.psk` or `set alert.hashtag` before alerts fire.
|
||||
_prefs.alert_enabled = 0;
|
||||
_prefs.alert_psk_b64[0] = '\0';
|
||||
_prefs.alert_hashtag[0] = '\0';
|
||||
_prefs.alert_wifi_minutes = 30;
|
||||
_prefs.alert_mqtt_minutes = 240;
|
||||
_prefs.alert_min_interval_min = 60;
|
||||
|
||||
// bridge defaults (same as repeater)
|
||||
_prefs.bridge_enabled = 1; // enabled
|
||||
_prefs.bridge_delay = 500; // milliseconds
|
||||
|
||||
Reference in new issue
Block a user