Enhance MQTTBridge and related components for improved status reporting and stats collection

- Added support for automatic stats collection in MQTTBridge, allowing for detailed status messages including battery voltage, uptime, error flags, and air time metrics.
- Updated MQTTMessageBuilder to accommodate additional stats in the status message, increasing buffer size for JSON documents.
- Modified CommonCLI to display MQTT status interval in minutes and adjusted command handling for setting the interval.
- Introduced new methods in MQTTBridge for setting stats sources
This commit is contained in:
agessaman committed 2026-01-02 13:36:41 -08:00
1 parent 7df28557b6
commit e4ff06cbfd
6 files changed
+273 -42

No files matched your search

+11 -7
View File
@@ -471,7 +471,9 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
} else if (memcmp(config, "mqtt.tx", 7) == 0) {
sprintf(reply, "> %s", _prefs->mqtt_tx_enabled ? "on" : "off");
} else if (memcmp(config, "mqtt.interval", 13) == 0) {
sprintf(reply, "> %d", (uint32_t)_prefs->mqtt_status_interval);
// Display interval in minutes (rounded)
uint32_t minutes = (_prefs->mqtt_status_interval + 29999) / 60000; // Round up
sprintf(reply, "> %u minutes (%lu ms)", minutes, _prefs->mqtt_status_interval);
} else if (memcmp(config, "mqtt.server", 11) == 0) {
sprintf(reply, "> %s", _prefs->mqtt_server);
} else if (memcmp(config, "mqtt.port", 9) == 0) {
@@ -714,14 +716,16 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
_prefs->mqtt_tx_enabled = memcmp(&config[8], "on", 2) == 0;
savePrefs();
strcpy(reply, "OK");
} else if (memcmp(config, "mqtt.interval ", 15) == 0) {
uint32_t interval = _atoi(&config[15]);
if (interval >= 1000 && interval <= 3600000) { // 1 second to 1 hour
_prefs->mqtt_status_interval = interval;
} else if (memcmp(config, "mqtt.interval ", 14) == 0) {
uint32_t minutes = _atoi(&config[14]);
if (minutes >= 1 && minutes <= 60) { // 1 minute to 60 minutes
_prefs->mqtt_status_interval = minutes * 60000; // Convert minutes to milliseconds
savePrefs();
strcpy(reply, "OK");
// Restart bridge to pick up new interval value
_callbacks->restartBridge();
sprintf(reply, "OK - interval set to %u minutes (%lu ms), bridge restarted", minutes, _prefs->mqtt_status_interval);
} else {
strcpy(reply, "Error: interval must be between 1000-3600000 ms");
strcpy(reply, "Error: interval must be between 1-60 minutes");
}
} else if (memcmp(config, "wifi.ssid ", 10) == 0) {
StrHelper::strncpy(_prefs->wifi_ssid, &config[10], sizeof(_prefs->wifi_ssid));