mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
add heartbeat interval to mqtt settings
This commit is contained in:
@@ -238,6 +238,22 @@ const MqttSettingsForm: FC = () => {
|
|||||||
{LL.MQTT_PUBLISH_INTERVALS()} (0=auto)
|
{LL.MQTT_PUBLISH_INTERVALS()} (0=auto)
|
||||||
</Typography>
|
</Typography>
|
||||||
<Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start">
|
<Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start">
|
||||||
|
<Grid item xs={6} sm={4}>
|
||||||
|
<ValidatedTextField
|
||||||
|
fieldErrors={fieldErrors}
|
||||||
|
name="publish_time_heartbeat"
|
||||||
|
label={LL.MQTT_INT_HEARTBEAT()}
|
||||||
|
InputProps={{
|
||||||
|
endAdornment: <InputAdornment position="end">{LL.SECONDS()}</InputAdornment>
|
||||||
|
}}
|
||||||
|
fullWidth
|
||||||
|
variant="outlined"
|
||||||
|
value={numberValue(data.publish_time_heartbeat)}
|
||||||
|
type="number"
|
||||||
|
onChange={updateFormValue}
|
||||||
|
margin="normal"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
<Grid item xs={6} sm={4}>
|
<Grid item xs={6} sm={4}>
|
||||||
<ValidatedTextField
|
<ValidatedTextField
|
||||||
fieldErrors={fieldErrors}
|
fieldErrors={fieldErrors}
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ const de: Translation = {
|
|||||||
MQTT_INT_THERMOSTATS: 'Thermostate',
|
MQTT_INT_THERMOSTATS: 'Thermostate',
|
||||||
MQTT_INT_SOLAR: 'Solarmodule',
|
MQTT_INT_SOLAR: 'Solarmodule',
|
||||||
MQTT_INT_MIXER: 'Mischermodule',
|
MQTT_INT_MIXER: 'Mischermodule',
|
||||||
|
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Standard',
|
DEFAULT: 'Standard',
|
||||||
MQTT_CLEAN_SESSION: 'Setze `Clean Session`',
|
MQTT_CLEAN_SESSION: 'Setze `Clean Session`',
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ const en: Translation = {
|
|||||||
MQTT_INT_THERMOSTATS: 'Thermostats',
|
MQTT_INT_THERMOSTATS: 'Thermostats',
|
||||||
MQTT_INT_SOLAR: 'Solar Modules',
|
MQTT_INT_SOLAR: 'Solar Modules',
|
||||||
MQTT_INT_MIXER: 'Mixer Modules',
|
MQTT_INT_MIXER: 'Mixer Modules',
|
||||||
|
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Default',
|
DEFAULT: 'Default',
|
||||||
MQTT_CLEAN_SESSION: 'Set Clean Session',
|
MQTT_CLEAN_SESSION: 'Set Clean Session',
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ const nl: Translation = {
|
|||||||
MQTT_INT_THERMOSTATS: 'Thermostaten',
|
MQTT_INT_THERMOSTATS: 'Thermostaten',
|
||||||
MQTT_INT_SOLAR: 'Solar Modules',
|
MQTT_INT_SOLAR: 'Solar Modules',
|
||||||
MQTT_INT_MIXER: 'Mixer Modules',
|
MQTT_INT_MIXER: 'Mixer Modules',
|
||||||
|
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Default',
|
DEFAULT: 'Default',
|
||||||
MQTT_CLEAN_SESSION: 'Clean Session aan',
|
MQTT_CLEAN_SESSION: 'Clean Session aan',
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ const no: Translation = {
|
|||||||
MQTT_INT_THERMOSTATS: 'Termostat',
|
MQTT_INT_THERMOSTATS: 'Termostat',
|
||||||
MQTT_INT_SOLAR: 'Solpaneler',
|
MQTT_INT_SOLAR: 'Solpaneler',
|
||||||
MQTT_INT_MIXER: 'Blandeventil',
|
MQTT_INT_MIXER: 'Blandeventil',
|
||||||
|
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Standard',
|
DEFAULT: 'Standard',
|
||||||
MQTT_CLEAN_SESSION: 'Benytt Clean Session',
|
MQTT_CLEAN_SESSION: 'Benytt Clean Session',
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ const pl: BaseTranslation = {
|
|||||||
MQTT_INT_THERMOSTATS: 'Termostaty',
|
MQTT_INT_THERMOSTATS: 'Termostaty',
|
||||||
MQTT_INT_SOLAR: 'Panele solarne',
|
MQTT_INT_SOLAR: 'Panele solarne',
|
||||||
MQTT_INT_MIXER: 'Mieszacze',
|
MQTT_INT_MIXER: 'Mieszacze',
|
||||||
|
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
||||||
MQTT_QUEUE: 'Kolejka MQTT',
|
MQTT_QUEUE: 'Kolejka MQTT',
|
||||||
DEFAULT: '{{Pozostałe|Domyślna|}}',
|
DEFAULT: '{{Pozostałe|Domyślna|}}',
|
||||||
MQTT_CLEAN_SESSION: 'Ustawiaj flagę "Clean session"',
|
MQTT_CLEAN_SESSION: 'Ustawiaj flagę "Clean session"',
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ const se: Translation = {
|
|||||||
MQTT_INT_THERMOSTATS: 'Termostater',
|
MQTT_INT_THERMOSTATS: 'Termostater',
|
||||||
MQTT_INT_SOLAR: 'Solpaneler',
|
MQTT_INT_SOLAR: 'Solpaneler',
|
||||||
MQTT_INT_MIXER: 'Blandarventiler',
|
MQTT_INT_MIXER: 'Blandarventiler',
|
||||||
|
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Standard',
|
DEFAULT: 'Standard',
|
||||||
MQTT_CLEAN_SESSION: 'Använd "Clean Session"-flaggan',
|
MQTT_CLEAN_SESSION: 'Använd "Clean Session"-flaggan',
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export interface MqttSettings {
|
|||||||
publish_time_mixer: number;
|
publish_time_mixer: number;
|
||||||
publish_time_other: number;
|
publish_time_other: number;
|
||||||
publish_time_sensor: number;
|
publish_time_sensor: number;
|
||||||
|
publish_time_heartbeat: number;
|
||||||
mqtt_qos: number;
|
mqtt_qos: number;
|
||||||
mqtt_retain: boolean;
|
mqtt_retain: boolean;
|
||||||
ha_enabled: boolean;
|
ha_enabled: boolean;
|
||||||
|
|||||||
@@ -11,5 +11,9 @@ export const MQTT_SETTINGS_VALIDATOR = new Schema({
|
|||||||
keep_alive: [
|
keep_alive: [
|
||||||
{ required: true, message: 'Keep alive is required' },
|
{ required: true, message: 'Keep alive is required' },
|
||||||
{ type: 'number', min: 1, max: 86400, message: 'Keep alive must be between 1 and 86400' }
|
{ type: 'number', min: 1, max: 86400, message: 'Keep alive must be between 1 and 86400' }
|
||||||
|
],
|
||||||
|
publish_time_heartbeat: [
|
||||||
|
{ required: true, message: 'Heartbeat is required' },
|
||||||
|
{ type: 'number', min: 10, max: 86400, message: 'Heartbeat must be between 10 and 86400' }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
|
|||||||
root["publish_time_mixer"] = settings.publish_time_mixer;
|
root["publish_time_mixer"] = settings.publish_time_mixer;
|
||||||
root["publish_time_other"] = settings.publish_time_other;
|
root["publish_time_other"] = settings.publish_time_other;
|
||||||
root["publish_time_sensor"] = settings.publish_time_sensor;
|
root["publish_time_sensor"] = settings.publish_time_sensor;
|
||||||
|
root["publish_time_heartbeat"] = settings.publish_time_heartbeat;
|
||||||
root["mqtt_qos"] = settings.mqtt_qos;
|
root["mqtt_qos"] = settings.mqtt_qos;
|
||||||
root["mqtt_retain"] = settings.mqtt_retain;
|
root["mqtt_retain"] = settings.mqtt_retain;
|
||||||
root["ha_enabled"] = settings.ha_enabled;
|
root["ha_enabled"] = settings.ha_enabled;
|
||||||
@@ -194,6 +195,7 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
|||||||
newSettings.publish_time_mixer = root["publish_time_mixer"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
newSettings.publish_time_mixer = root["publish_time_mixer"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
||||||
newSettings.publish_time_other = root["publish_time_other"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
newSettings.publish_time_other = root["publish_time_other"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
||||||
newSettings.publish_time_sensor = root["publish_time_sensor"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
newSettings.publish_time_sensor = root["publish_time_sensor"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
||||||
|
newSettings.publish_time_heartbeat = root["publish_time_heartbeat"] | EMSESP_DEFAULT_PUBLISH_HEARTBEAT;
|
||||||
|
|
||||||
newSettings.ha_enabled = root["ha_enabled"] | EMSESP_DEFAULT_HA_ENABLED;
|
newSettings.ha_enabled = root["ha_enabled"] | EMSESP_DEFAULT_HA_ENABLED;
|
||||||
newSettings.nested_format = root["nested_format"] | EMSESP_DEFAULT_NESTED_FORMAT;
|
newSettings.nested_format = root["nested_format"] | EMSESP_DEFAULT_NESTED_FORMAT;
|
||||||
@@ -282,6 +284,11 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
|||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newSettings.publish_time_heartbeat != settings.publish_time_heartbeat) {
|
||||||
|
emsesp::EMSESP::mqtt_.set_publish_time_heartbeat(newSettings.publish_time_heartbeat);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
emsesp::EMSESP::mqtt_.reset_mqtt();
|
emsesp::EMSESP::mqtt_.reset_mqtt();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ class MqttSettings {
|
|||||||
uint16_t publish_time_mixer;
|
uint16_t publish_time_mixer;
|
||||||
uint16_t publish_time_other;
|
uint16_t publish_time_other;
|
||||||
uint16_t publish_time_sensor;
|
uint16_t publish_time_sensor;
|
||||||
|
uint16_t publish_time_heartbeat;
|
||||||
uint8_t mqtt_qos;
|
uint8_t mqtt_qos;
|
||||||
bool mqtt_retain;
|
bool mqtt_retain;
|
||||||
bool ha_enabled;
|
bool ha_enabled;
|
||||||
|
|||||||
@@ -157,6 +157,10 @@
|
|||||||
#define EMSESP_DEFAULT_PUBLISH_TIME 10
|
#define EMSESP_DEFAULT_PUBLISH_TIME 10
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef EMSESP_DEFAULT_PUBLISH_HEARTBEAT
|
||||||
|
#define EMSESP_DEFAULT_PUBLISH_HEARTBEAT 60
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef EMSESP_DEFAULT_NESTED_FORMAT
|
#ifndef EMSESP_DEFAULT_NESTED_FORMAT
|
||||||
#define EMSESP_DEFAULT_NESTED_FORMAT 1
|
#define EMSESP_DEFAULT_NESTED_FORMAT 1
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
12
src/mqtt.cpp
12
src/mqtt.cpp
@@ -36,6 +36,7 @@ uint32_t Mqtt::publish_time_solar_;
|
|||||||
uint32_t Mqtt::publish_time_mixer_;
|
uint32_t Mqtt::publish_time_mixer_;
|
||||||
uint32_t Mqtt::publish_time_sensor_;
|
uint32_t Mqtt::publish_time_sensor_;
|
||||||
uint32_t Mqtt::publish_time_other_;
|
uint32_t Mqtt::publish_time_other_;
|
||||||
|
uint32_t Mqtt::publish_time_heartbeat_;
|
||||||
bool Mqtt::mqtt_enabled_;
|
bool Mqtt::mqtt_enabled_;
|
||||||
bool Mqtt::ha_enabled_;
|
bool Mqtt::ha_enabled_;
|
||||||
uint8_t Mqtt::nested_format_;
|
uint8_t Mqtt::nested_format_;
|
||||||
@@ -146,6 +147,12 @@ void Mqtt::loop() {
|
|||||||
process_queue();
|
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
|
// dallas publish on change
|
||||||
if (!publish_time_sensor_) {
|
if (!publish_time_sensor_) {
|
||||||
EMSESP::publish_sensor_values(false);
|
EMSESP::publish_sensor_values(false);
|
||||||
@@ -430,6 +437,7 @@ void Mqtt::load_settings() {
|
|||||||
publish_time_mixer_ = mqttSettings.publish_time_mixer * 1000;
|
publish_time_mixer_ = mqttSettings.publish_time_mixer * 1000;
|
||||||
publish_time_other_ = mqttSettings.publish_time_other * 1000;
|
publish_time_other_ = mqttSettings.publish_time_other * 1000;
|
||||||
publish_time_sensor_ = mqttSettings.publish_time_sensor * 1000;
|
publish_time_sensor_ = mqttSettings.publish_time_sensor * 1000;
|
||||||
|
publish_time_heartbeat_ = mqttSettings.publish_time_heartbeat * 1000;
|
||||||
});
|
});
|
||||||
|
|
||||||
// create basename from base
|
// 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
|
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) {
|
bool Mqtt::get_publish_onchange(uint8_t device_type) {
|
||||||
if (publish_single_ && !ha_enabled_) {
|
if (publish_single_ && !ha_enabled_) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ class Mqtt {
|
|||||||
void set_publish_time_mixer(uint16_t publish_time);
|
void set_publish_time_mixer(uint16_t publish_time);
|
||||||
void set_publish_time_other(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_sensor(uint16_t publish_time);
|
||||||
|
void set_publish_time_heartbeat(uint16_t publish_time);
|
||||||
bool get_publish_onchange(uint8_t device_type);
|
bool get_publish_onchange(uint8_t device_type);
|
||||||
|
|
||||||
enum Operation : uint8_t { PUBLISH, SUBSCRIBE, UNSUBSCRIBE };
|
enum Operation : uint8_t { PUBLISH, SUBSCRIBE, UNSUBSCRIBE };
|
||||||
@@ -288,6 +289,7 @@ class Mqtt {
|
|||||||
uint32_t last_publish_mixer_ = 0;
|
uint32_t last_publish_mixer_ = 0;
|
||||||
uint32_t last_publish_other_ = 0;
|
uint32_t last_publish_other_ = 0;
|
||||||
uint32_t last_publish_sensor_ = 0;
|
uint32_t last_publish_sensor_ = 0;
|
||||||
|
uint32_t last_publish_heartbeat_ = 0;
|
||||||
uint32_t last_publish_queue_ = 0;
|
uint32_t last_publish_queue_ = 0;
|
||||||
|
|
||||||
static bool connecting_;
|
static bool connecting_;
|
||||||
@@ -311,6 +313,7 @@ class Mqtt {
|
|||||||
static uint32_t publish_time_mixer_;
|
static uint32_t publish_time_mixer_;
|
||||||
static uint32_t publish_time_other_;
|
static uint32_t publish_time_other_;
|
||||||
static uint32_t publish_time_sensor_;
|
static uint32_t publish_time_sensor_;
|
||||||
|
static uint32_t publish_time_heartbeat_;
|
||||||
static bool mqtt_enabled_;
|
static bool mqtt_enabled_;
|
||||||
static bool ha_enabled_;
|
static bool ha_enabled_;
|
||||||
static uint8_t nested_format_;
|
static uint8_t nested_format_;
|
||||||
|
|||||||
@@ -512,12 +512,6 @@ void System::loop() {
|
|||||||
led_monitor(); // check status and report back using the LED
|
led_monitor(); // check status and report back using the LED
|
||||||
system_check(); // check system health
|
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
|
#ifndef EMSESP_STANDALONE
|
||||||
|
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_DEBUG)
|
||||||
|
|||||||
@@ -250,7 +250,6 @@ class System {
|
|||||||
static constexpr uint32_t HEALTHCHECK_LED_FLASH_DUARATION = 150;
|
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_BUS = (1 << 0); // 1
|
||||||
static constexpr uint8_t HEALTHCHECK_NO_NETWORK = (1 << 1); // 2
|
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
|
static constexpr uint8_t LED_ON = HIGH; // LED on
|
||||||
|
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
@@ -263,7 +262,6 @@ class System {
|
|||||||
int8_t wifi_quality(int8_t dBm);
|
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
|
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;
|
uint32_t last_system_check_ = 0;
|
||||||
|
|
||||||
bool upload_status_ = false; // true if we're in the middle of a OTA firmware upload
|
bool upload_status_ = false; // true if we're in the middle of a OTA firmware upload
|
||||||
|
|||||||
Reference in New Issue
Block a user