CaCO3 hace 3 años
padre
commit
ca45d0a278

+ 13 - 6
code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp

@@ -15,6 +15,9 @@
 
 
 static const char *TAG = "class_flow_MQTT";
 static const char *TAG = "class_flow_MQTT";
 
 
+
+extern ClassFlowControll tfliteflow;
+
 void ClassFlowMQTT::SetInitialParameter(void)
 void ClassFlowMQTT::SetInitialParameter(void)
 {
 {
     uri = "";
     uri = "";
@@ -37,6 +40,7 @@ void ClassFlowMQTT::SetInitialParameter(void)
     previousElement = NULL;
     previousElement = NULL;
     ListFlowControll = NULL; 
     ListFlowControll = NULL; 
     disabled = false;
     disabled = false;
+    keepAlive = 25*60;
 }       
 }       
 
 
 ClassFlowMQTT::ClassFlowMQTT()
 ClassFlowMQTT::ClassFlowMQTT()
@@ -51,16 +55,20 @@ ClassFlowMQTT::ClassFlowMQTT(std::vector<ClassFlow*>* lfc)
     ListFlowControll = lfc;
     ListFlowControll = lfc;
     for (int i = 0; i < ListFlowControll->size(); ++i)
     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)
         if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0)
         {
         {
             flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i];
             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];
             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()) {
         if (!MQTT_Init()) { // Retry
         if (!MQTT_Init()) { // Retry

+ 7 - 3
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
 #ifdef __HIDE_PASSWORD
     LogFile.WriteToFile(ESP_LOG_INFO, "MQTT Configuration: uri: " + _mqttURI + ", clientname: " + _clientid + 
     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
 #else
     LogFile.WriteToFile(ESP_LOG_INFO, "MQTT Configuration: uri: " + _mqttURI + ", clientname: " + _clientid + 
     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
 #endif
 
 
+
     uri = _mqttURI;
     uri = _mqttURI;
     client_id = _clientid;
     client_id = _clientid;
     lwt_topic = _lwt;
     lwt_topic = _lwt;
@@ -133,6 +134,9 @@ void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _us
         user = _user;
         user = _user;
         password = _password;
         password = _password;
     }
     }
+
+
+    LogFile.WriteToFile(ESP_LOG_INFO, "MQTT maintopic: %s", _maintopic.c_str());
 }
 }
 
 
 bool MQTT_Init() {
 bool MQTT_Init() {

+ 1 - 1
code/components/jomjol_mqtt/interface_mqtt.h

@@ -5,7 +5,7 @@
 #include <map>
 #include <map>
 #include <functional>
 #include <functional>
 
 
-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();
 bool MQTT_Init();
 void MQTTdestroy_client();
 void MQTTdestroy_client();