From 0442630a80c60230e99b72e0bafb1448e3457902 Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Thu, 21 Mar 2024 20:12:45 +0100 Subject: [PATCH 1/2] Add sanity check for map report interval and position precision --- src/mqtt/MQTT.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index e29786dcb4..fea5258e77 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -195,8 +195,10 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE) } if (moduleConfig.mqtt.map_reporting_enabled && moduleConfig.mqtt.has_map_report_settings) { - map_position_precision = moduleConfig.mqtt.map_report_settings.position_precision; - map_publish_interval_secs = moduleConfig.mqtt.map_report_settings.publish_interval_secs; + if (moduleConfig.mqtt.map_report_settings.position_precision > 0) + map_position_precision = moduleConfig.mqtt.map_report_settings.position_precision; + if (moduleConfig.mqtt.map_report_settings.publish_interval_secs > 0) + map_publish_interval_secs = moduleConfig.mqtt.map_report_settings.publish_interval_secs; } #ifdef HAS_NETWORKING From 952b757538f94f35169593f5a97ef2c5569bfb0a Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Thu, 21 Mar 2024 21:03:59 +0100 Subject: [PATCH 2/2] Use new `Default::` methods --- src/mqtt/MQTT.cpp | 10 +++++----- src/mqtt/MQTT.h | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index fea5258e77..390d0e2064 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -195,10 +195,10 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE) } if (moduleConfig.mqtt.map_reporting_enabled && moduleConfig.mqtt.has_map_report_settings) { - if (moduleConfig.mqtt.map_report_settings.position_precision > 0) - map_position_precision = moduleConfig.mqtt.map_report_settings.position_precision; - if (moduleConfig.mqtt.map_report_settings.publish_interval_secs > 0) - map_publish_interval_secs = moduleConfig.mqtt.map_report_settings.publish_interval_secs; + map_position_precision = Default::getConfiguredOrDefault(moduleConfig.mqtt.map_report_settings.position_precision, + default_map_position_precision); + map_publish_interval_msecs = Default::getConfiguredOrDefaultMs( + moduleConfig.mqtt.map_report_settings.publish_interval_secs, default_map_publish_interval_secs); } #ifdef HAS_NETWORKING @@ -542,7 +542,7 @@ void MQTT::perhapsReportToMap() if (!moduleConfig.mqtt.map_reporting_enabled || !(moduleConfig.mqtt.proxy_to_client_enabled || isConnectedDirectly())) return; - if (millis() - last_report_to_map < map_publish_interval_secs * 1000) { + if (millis() - last_report_to_map < map_publish_interval_msecs) { return; } else { if (map_position_precision == 0 || (localPosition.latitude_i == 0 && localPosition.longitude_i == 0)) { diff --git a/src/mqtt/MQTT.h b/src/mqtt/MQTT.h index 41b1601e79..f2eb6b1204 100644 --- a/src/mqtt/MQTT.h +++ b/src/mqtt/MQTT.h @@ -89,9 +89,11 @@ class MQTT : private concurrency::OSThread std::string mapTopic = "/2/map/"; // For protobuf-encoded MapReport messages // For map reporting (only applies when enabled) + const uint32_t default_map_position_precision = 14; // defaults to max. offset of ~1459m + const uint32_t default_map_publish_interval_secs = 60 * 15; // defaults to 15 minutes uint32_t last_report_to_map = 0; - uint32_t map_position_precision = 14; // defaults to max. offset of ~1459m - uint32_t map_publish_interval_secs = 60 * 15; // defaults to 15 minutes + uint32_t map_position_precision = default_map_position_precision; + uint32_t map_publish_interval_msecs = default_map_publish_interval_secs * 1000; /** return true if we have a channel that wants uplink/downlink or map reporting is enabled */