diff --git a/interface/src/framework/mqtt/MqttSettingsForm.tsx b/interface/src/framework/mqtt/MqttSettingsForm.tsx index b5956b034..5e6cdbeca 100644 --- a/interface/src/framework/mqtt/MqttSettingsForm.tsx +++ b/interface/src/framework/mqtt/MqttSettingsForm.tsx @@ -238,6 +238,22 @@ const MqttSettingsForm: FC = () => { {LL.MQTT_PUBLISH_INTERVALS()} (0=auto) + + {LL.SECONDS()} + }} + fullWidth + variant="outlined" + value={numberValue(data.publish_time_heartbeat)} + type="number" + onChange={updateFormValue} + margin="normal" + /> + publish_time_heartbeat_)) { + last_publish_heartbeat_ = currentMillis; + EMSESP::system_.send_heartbeat(); // send heartbeat + } + // dallas publish on change if (!publish_time_sensor_) { EMSESP::publish_sensor_values(false); @@ -430,6 +437,7 @@ void Mqtt::load_settings() { publish_time_mixer_ = mqttSettings.publish_time_mixer * 1000; publish_time_other_ = mqttSettings.publish_time_other * 1000; publish_time_sensor_ = mqttSettings.publish_time_sensor * 1000; + publish_time_heartbeat_ = mqttSettings.publish_time_heartbeat * 1000; }); // create basename from base @@ -512,6 +520,10 @@ void Mqtt::set_publish_time_sensor(uint16_t publish_time) { publish_time_sensor_ = publish_time * 1000; // convert to milliseconds } +void Mqtt::set_publish_time_heartbeat(uint16_t publish_time) { + publish_time_heartbeat_ = publish_time * 1000; // convert to milliseconds +} + bool Mqtt::get_publish_onchange(uint8_t device_type) { if (publish_single_ && !ha_enabled_) { return false; diff --git a/src/mqtt.h b/src/mqtt.h index 65e4fcad7..848c87989 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -65,6 +65,7 @@ class Mqtt { void set_publish_time_mixer(uint16_t publish_time); void set_publish_time_other(uint16_t publish_time); void set_publish_time_sensor(uint16_t publish_time); + void set_publish_time_heartbeat(uint16_t publish_time); bool get_publish_onchange(uint8_t device_type); enum Operation : uint8_t { PUBLISH, SUBSCRIBE, UNSUBSCRIBE }; @@ -288,6 +289,7 @@ class Mqtt { uint32_t last_publish_mixer_ = 0; uint32_t last_publish_other_ = 0; uint32_t last_publish_sensor_ = 0; + uint32_t last_publish_heartbeat_ = 0; uint32_t last_publish_queue_ = 0; static bool connecting_; @@ -311,6 +313,7 @@ class Mqtt { static uint32_t publish_time_mixer_; static uint32_t publish_time_other_; static uint32_t publish_time_sensor_; + static uint32_t publish_time_heartbeat_; static bool mqtt_enabled_; static bool ha_enabled_; static uint8_t nested_format_; diff --git a/src/system.cpp b/src/system.cpp index 1fbfe9aa9..2b6ab7440 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -512,12 +512,6 @@ void System::loop() { led_monitor(); // check status and report back using the LED system_check(); // check system health - // send out heartbeat - uint32_t currentMillis = uuid::get_uptime(); - if (!last_heartbeat_ || (currentMillis - last_heartbeat_ > SYSTEM_HEARTBEAT_INTERVAL)) { - last_heartbeat_ = currentMillis; - send_heartbeat(); - } #ifndef EMSESP_STANDALONE #if defined(EMSESP_DEBUG) diff --git a/src/system.h b/src/system.h index f8ee51dc2..3f4169306 100644 --- a/src/system.h +++ b/src/system.h @@ -250,7 +250,6 @@ class System { static constexpr uint32_t HEALTHCHECK_LED_FLASH_DUARATION = 150; static constexpr uint8_t HEALTHCHECK_NO_BUS = (1 << 0); // 1 static constexpr uint8_t HEALTHCHECK_NO_NETWORK = (1 << 1); // 2 - static constexpr uint32_t SYSTEM_HEARTBEAT_INTERVAL = 60000; // in milliseconds, how often the MQTT heartbeat is sent (1 min) static constexpr uint8_t LED_ON = HIGH; // LED on #ifndef EMSESP_STANDALONE @@ -263,7 +262,6 @@ class System { int8_t wifi_quality(int8_t dBm); uint8_t healthcheck_ = HEALTHCHECK_NO_NETWORK | HEALTHCHECK_NO_BUS; // start with all flags set, no wifi and no ems bus connection - uint32_t last_heartbeat_ = 0; uint32_t last_system_check_ = 0; bool upload_status_ = false; // true if we're in the middle of a OTA firmware upload