mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-13 23:45:25 +00:00
Make sure MQTT config is updated for current connection if changed
This commit is contained in:
parent
32ad71bba6
commit
557ba659d5
@ -23,6 +23,7 @@ public:
|
||||
};
|
||||
|
||||
void setCaVerification(bool);
|
||||
void setConfig(MqttConfig& mqttConfig);
|
||||
|
||||
bool connect();
|
||||
void disconnect();
|
||||
|
||||
@ -7,6 +7,10 @@ void AmsMqttHandler::setCaVerification(bool caVerification) {
|
||||
this->caVerification = caVerification;
|
||||
}
|
||||
|
||||
void AmsMqttHandler::setConfig(MqttConfig& mqttConfig) {
|
||||
this->mqttConfig = mqttConfig;
|
||||
}
|
||||
|
||||
bool AmsMqttHandler::connect() {
|
||||
if(millis() - lastMqttRetry < 10000) {
|
||||
yield();
|
||||
@ -93,10 +97,19 @@ bool AmsMqttHandler::connect() {
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("CA verification disabled\n"));
|
||||
mqttSecureClient->setInsecure();
|
||||
}
|
||||
if(mqttClient != NULL) {
|
||||
mqttClient->stop();
|
||||
delete mqttClient;
|
||||
}
|
||||
mqttClient = mqttSecureClient;
|
||||
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf_P(PSTR("MQTT SSL setup complete (%dkb free heap)\n"), ESP.getFreeHeap());
|
||||
}
|
||||
} else if(mqttSecureClient != NULL) {
|
||||
mqttSecureClient->stop();
|
||||
delete mqttSecureClient;
|
||||
mqttSecureClient = NULL;
|
||||
mqttClient = NULL;
|
||||
}
|
||||
|
||||
if(mqttClient == NULL) {
|
||||
|
||||
@ -557,8 +557,15 @@ void loop() {
|
||||
|
||||
if (mqttEnabled || config.isMqttChanged()) {
|
||||
if(mqttHandler == NULL || !mqttHandler->connected() || config.isMqttChanged()) {
|
||||
if(mqttHandler != NULL && config.isMqttChanged()) {
|
||||
MqttConfig mqttConfig;
|
||||
if(config.getMqttConfig(mqttConfig)) {
|
||||
mqttHandler->disconnect();
|
||||
mqttHandler->setConfig(mqttConfig);
|
||||
config.ackMqttChange();
|
||||
}
|
||||
}
|
||||
MQTT_connect();
|
||||
config.ackMqttChange();
|
||||
}
|
||||
} else if(mqttHandler != NULL) {
|
||||
mqttHandler->disconnect();
|
||||
@ -1859,9 +1866,14 @@ void MQTT_connect() {
|
||||
mqttEnabled = true;
|
||||
ws.setMqttEnabled(true);
|
||||
|
||||
if(mqttHandler != NULL && mqttHandler->getFormat() != mqttConfig.payloadFormat) {
|
||||
delete mqttHandler;
|
||||
mqttHandler = NULL;
|
||||
if(mqttHandler != NULL) {
|
||||
mqttHandler->disconnect();
|
||||
if(mqttHandler->getFormat() != mqttConfig.payloadFormat) {
|
||||
delete mqttHandler;
|
||||
mqttHandler = NULL;
|
||||
} else if(config.isMqttChanged()) {
|
||||
mqttHandler->setConfig(mqttConfig);
|
||||
}
|
||||
}
|
||||
|
||||
if(mqttHandler == NULL) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user