add heartbeat interval to mqtt settings

This commit is contained in:
MichaelDvP
2022-12-05 19:27:56 +01:00
parent 3878a3ee0b
commit 9e23710c6d
16 changed files with 54 additions and 8 deletions

View File

@@ -36,6 +36,7 @@ uint32_t Mqtt::publish_time_solar_;
uint32_t Mqtt::publish_time_mixer_;
uint32_t Mqtt::publish_time_sensor_;
uint32_t Mqtt::publish_time_other_;
uint32_t Mqtt::publish_time_heartbeat_;
bool Mqtt::mqtt_enabled_;
bool Mqtt::ha_enabled_;
uint8_t Mqtt::nested_format_;
@@ -146,6 +147,12 @@ void Mqtt::loop() {
process_queue();
}
// send heartbeat
if ((currentMillis - last_publish_heartbeat_ > 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;