diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index 868096f0..8d5351af 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -15,6 +15,9 @@ static const char *TAG = "class_flow_MQTT"; + +extern ClassFlowControll tfliteflow; + void ClassFlowMQTT::SetInitialParameter(void) { uri = ""; @@ -37,6 +40,7 @@ void ClassFlowMQTT::SetInitialParameter(void) previousElement = NULL; ListFlowControll = NULL; disabled = false; + keepAlive = 25*60; } ClassFlowMQTT::ClassFlowMQTT() @@ -51,16 +55,20 @@ ClassFlowMQTT::ClassFlowMQTT(std::vector* lfc) ListFlowControll = lfc; for (int i = 0; i < ListFlowControll->size(); ++i) { + // ESP_LOGW(TAG, "LCF: %s", ((*ListFlowControll)[i])->name().c_str()); + if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0) { flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i]; } - if (((*ListFlowControll)[i])->name().compare("ClassFlowControll") == 0) +// TODO this does not work since ClassFlowControll is not in the list! + /* if (((*ListFlowControll)[i])->name().compare("ClassFlowControll") == 0) { ClassFlowControll *cfc = (ClassFlowControll*) (*ListFlowControll)[i]; - keepAlive = cfc->getAutoInterval()* 2.5; // Allow at least than 2 failed rounds before we are threated as disconnected - } + this->keepAlive = cfc->getAutoInterval()* 2.5; // Allow at least than 2 failed rounds before we are threated as disconnected + ESP_LOGW(TAG, "KEEPALIVE: %d", this->keepAlive); + }*/ } } @@ -130,9 +138,8 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph) } } - MQTT_Configure(uri, clientname, user, password, maintopic + "/connection", keepAlive); - - ESP_LOGD(TAG, "MQTT maintopic: %s", maintopic.c_str()); + ESP_LOGW(TAG, "KEEPALIVE: %d", keepAlive); + MQTT_Configure(uri, clientname, user, password, maintopic, "/connection", keepAlive); if (!MQTT_Init()) { if (!MQTT_Init()) { // Retry diff --git a/code/components/jomjol_mqtt/interface_mqtt.cpp b/code/components/jomjol_mqtt/interface_mqtt.cpp index bbe7da3c..e1cc08ae 100644 --- a/code/components/jomjol_mqtt/interface_mqtt.cpp +++ b/code/components/jomjol_mqtt/interface_mqtt.cpp @@ -115,15 +115,16 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_ } -void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _lwt, int _keepalive){ +void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _maintopic, std::string _lwt, int _keepalive){ #ifdef __HIDE_PASSWORD LogFile.WriteToFile(ESP_LOG_INFO, "MQTT Configuration: uri: " + _mqttURI + ", clientname: " + _clientid + - ", user: " + _user + ", password: XXXXXXXX, last-will-topic: " + _lwt + ", timeout: " + std::to_string(_keepalive)); + ", user: " + _user + ", password: XXXXXXXX, last-will-topic: " + _maintopic + _lwt + ", keepAlive: " + std::to_string(_keepalive)); #else LogFile.WriteToFile(ESP_LOG_INFO, "MQTT Configuration: uri: " + _mqttURI + ", clientname: " + _clientid + - ", user: " + _user + ", password: " + _password + ", last-will-topic: " + _lwt + ", timeout: " + std::to_string(_keepalive)); + ", user: " + _user + ", password: " + _password + ", last-will-topic: " + _maintopic + _lwt + ", keepAlive: " + std::to_string(_keepalive)); #endif + uri = _mqttURI; client_id = _clientid; lwt_topic = _lwt; @@ -133,6 +134,9 @@ void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _us user = _user; password = _password; } + + + LogFile.WriteToFile(ESP_LOG_INFO, "MQTT maintopic: %s", _maintopic.c_str()); } bool MQTT_Init() { diff --git a/code/components/jomjol_mqtt/interface_mqtt.h b/code/components/jomjol_mqtt/interface_mqtt.h index db0e6971..fa1227ee 100644 --- a/code/components/jomjol_mqtt/interface_mqtt.h +++ b/code/components/jomjol_mqtt/interface_mqtt.h @@ -5,7 +5,7 @@ #include #include -void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _lwt, int _keepalive); +void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _maintopic, std::string _lwt, int _keepalive); bool MQTT_Init(); void MQTTdestroy_client();