MQTT on interval

This commit is contained in:
Gunnar Skjold
2024-04-21 10:21:39 +02:00
parent efacbd4b31
commit 3f1861deda
11 changed files with 125 additions and 47 deletions

View File

@@ -92,7 +92,10 @@ struct MqttConfig {
char password[256];
uint8_t payloadFormat;
bool ssl;
}; // 676
uint8_t magic;
bool stateUpdate;
uint16_t stateUpdateInterval;
}; // 680
struct WebConfig {
uint8_t security;

View File

@@ -147,6 +147,11 @@ bool AmsConfiguration::getMqttConfig(MqttConfig& config) {
EEPROM.begin(EEPROM_SIZE);
EEPROM.get(CONFIG_MQTT_START, config);
EEPROM.end();
if(config.magic != 0x7B) {
config.stateUpdate = false;
config.stateUpdateInterval = 10;
config.magic = 0x7B;
}
return true;
} else {
clearMqtt(config);
@@ -166,6 +171,8 @@ bool AmsConfiguration::setMqttConfig(MqttConfig& config) {
mqttChanged |= strcmp(config.password, existing.password) != 0;
mqttChanged |= config.payloadFormat != existing.payloadFormat;
mqttChanged |= config.ssl != existing.ssl;
mqttChanged |= config.stateUpdate != existing.stateUpdate;
mqttChanged |= config.stateUpdateInterval != existing.stateUpdateInterval;
} else {
mqttChanged = true;
}
@@ -195,6 +202,9 @@ void AmsConfiguration::clearMqtt(MqttConfig& config) {
memset(config.password, 0, 256);
config.payloadFormat = 0;
config.ssl = false;
config.magic = 0x7B;
config.stateUpdate = false;
config.stateUpdateInterval = 10;
}
void AmsConfiguration::setMqttChanged() {