diff --git a/include/MqttSettings.h b/include/MqttSettings.h index 47b4f0a9e..6653d75a7 100644 --- a/include/MqttSettings.h +++ b/include/MqttSettings.h @@ -10,6 +10,7 @@ class MqttSettingsClass { public: MqttSettingsClass(); void init(); + void loop(); void performReconnect(); bool getConnected(); void publish(const String& subtopic, const String& payload); diff --git a/src/MqttSettings.cpp b/src/MqttSettings.cpp index ccf6ca811..e432e061c 100644 --- a/src/MqttSettings.cpp +++ b/src/MqttSettings.cpp @@ -182,15 +182,21 @@ void MqttSettingsClass::init() createMqttClientObject(); } +void MqttSettingsClass::loop() +{ + if (nullptr == mqttClient) { return; } + mqttClient->loop(); +} + void MqttSettingsClass::createMqttClientObject() { if (mqttClient != nullptr) delete mqttClient; const CONFIG_T& config = Configuration.get(); if (config.Mqtt_Tls) { - mqttClient = static_cast(new espMqttClientSecure); + mqttClient = new espMqttClientSecure(espMqttClientTypes::UseInternalTask::NO); } else { - mqttClient = static_cast(new espMqttClient); + mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO); } } diff --git a/src/main.cpp b/src/main.cpp index 6152a61db..51a17b33e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -215,6 +215,8 @@ void loop() VeDirect.loop(); yield(); } + MqttSettings.loop(); + yield(); MqttHandleDtu.loop(); yield(); MqttHandleInverter.loop();