Răsfoiți Sursa

MQTT improvements (#1487)

* removed no longer used code

* updated logs

* increased heap memory. this most likely was the reason that the MQTT init failed, see https://github.com/jomjol/AI-on-the-edge-device/issues/1455#issuecomment-1336450501

Co-authored-by: CaCO3 <caco@ruinelli.ch>
CaCO3 3 ani în urmă
părinte
comite
e87b91f6eb

+ 17 - 15
code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp

@@ -306,21 +306,23 @@ bool ClassFlowMQTT::doFlow(string zwtime)
             MQTTPublish(namenumber + "json", json, SetRetainFlag);
         }
     }
-    else
-    {
-        for (int i = 0; i < ListFlowControll->size(); ++i)
-        {
-            zw = (*ListFlowControll)[i]->getReadout();
-            if (zw.length() > 0)
-            {
-                if (result.length() == 0)
-                    result = zw;
-                else
-                    result = result + "\t" + zw;
-            }
-        }
-        MQTTPublish(topic, result, SetRetainFlag);
-    }
+    
+    /* Disabled because this is no longer a use case */
+    // else
+    // {
+    //     for (int i = 0; i < ListFlowControll->size(); ++i)
+    //     {
+    //         zw = (*ListFlowControll)[i]->getReadout();
+    //         if (zw.length() > 0)
+    //         {
+    //             if (result.length() == 0)
+    //                 result = zw;
+    //             else
+    //                 result = result + "\t" + zw;
+    //         }
+    //     }
+    //     MQTTPublish(topic, result, SetRetainFlag);
+    // }
     
     OldValue = result;
     

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

@@ -176,7 +176,7 @@ bool MQTT_Init() {
 
     if ((client_id.length() == 0) || (lwt_topic.length() == 0))
     {
-        LogFile.WriteToFile(ESP_LOG_ERROR, TAG, std::string("Init with no Client_ID or Topic. Abort Init!"));
+        LogFile.WriteToFile(ESP_LOG_ERROR, TAG, std::string("Init with no Client_ID (" + client_id + ") or Last Will Topic (" + lwt_topic + "). Abort Init!"));
         return false;
     }
     

+ 2 - 2
code/components/jomjol_mqtt/server_mqtt.cpp

@@ -162,7 +162,7 @@ void MQTThomeassistantDiscovery() {
 void publishSystemData() {
     char tmp_char[50];
 
-    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Publishing system MQTT topics...");
+    LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Publishing system MQTT topics...");
 
     sprintf(tmp_char, "%ld", (long)getUpTime());
     MQTTPublish(maintopic + "/" + "uptime", std::string(tmp_char), retainFlag);
@@ -179,7 +179,7 @@ void publishSystemData() {
 
 
 void publishStaticData() {
-    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Publishing static MQTT topics...");
+    LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Publishing static MQTT topics...");
     MQTTPublish(maintopic + "/" + "MAC", getMac(), retainFlag);
     MQTTPublish(maintopic + "/" + "IP", *getIPAddress(), retainFlag);
     MQTTPublish(maintopic + "/" + "hostname", hostname, retainFlag);

+ 5 - 3
code/components/jomjol_tfliteclass/server_tflite.cpp

@@ -736,7 +736,7 @@ void task_autodoFlow(void *pvParameter)
     while (auto_isrunning)
     {
         LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "----------------------------------------------------------------"); // Clear separation between runs
-        std::string _zw = "task_autodoFlow - next round - Round #" + std::to_string(++countRounds);
+        std::string _zw = "task_autodoFlow - Starting Round #" + std::to_string(++countRounds);
         LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw); 
         fr_start = esp_timer_get_time();
 
@@ -760,13 +760,15 @@ void task_autodoFlow(void *pvParameter)
             LogFile.RemoveOldDataLog();
         }
         
-        LogFile.WriteToFile(ESP_LOG_INFO, TAG, "task_autodoFlow - round #" + std::to_string(countRounds) + " done");
         //CPU Temp
         float cputmp = temperatureRead();
         std::stringstream stream;
         stream << std::fixed << std::setprecision(1) << cputmp;
         string zwtemp = "CPU Temperature: " + stream.str();
-        LogFile.WriteToFile(ESP_LOG_INFO, TAG, zwtemp); 
+        LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, zwtemp); 
+
+        LogFile.WriteToFile(ESP_LOG_INFO, TAG, "task_autodoFlow - round #" + std::to_string(countRounds) + " completed");
+
         fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000;
         if (auto_intervall > fr_delta_ms)
         {

+ 1 - 1
code/sdkconfig.defaults

@@ -34,7 +34,7 @@ CONFIG_SPIRAM_BOOT_INIT=y
 CONFIG_SPIRAM_USE_MALLOC=y
 CONFIG_SPIRAM_MEMTEST=y
 CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384
-CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=32768
+CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=40960
 CONFIG_SPIRAM_CACHE_WORKAROUND=y
 
 CONFIG_ESP_INT_WDT_TIMEOUT_MS=300