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>
This commit is contained in:
CaCO3
2022-12-05 06:55:08 +01:00
committed by GitHub
parent 4b52e61755
commit e87b91f6eb
5 changed files with 26 additions and 22 deletions

View File

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

View File

@@ -176,7 +176,7 @@ bool MQTT_Init() {
if ((client_id.length() == 0) || (lwt_topic.length() == 0)) 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; return false;
} }

View File

@@ -162,7 +162,7 @@ void MQTThomeassistantDiscovery() {
void publishSystemData() { void publishSystemData() {
char tmp_char[50]; 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()); sprintf(tmp_char, "%ld", (long)getUpTime());
MQTTPublish(maintopic + "/" + "uptime", std::string(tmp_char), retainFlag); MQTTPublish(maintopic + "/" + "uptime", std::string(tmp_char), retainFlag);
@@ -179,7 +179,7 @@ void publishSystemData() {
void publishStaticData() { 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 + "/" + "MAC", getMac(), retainFlag);
MQTTPublish(maintopic + "/" + "IP", *getIPAddress(), retainFlag); MQTTPublish(maintopic + "/" + "IP", *getIPAddress(), retainFlag);
MQTTPublish(maintopic + "/" + "hostname", hostname, retainFlag); MQTTPublish(maintopic + "/" + "hostname", hostname, retainFlag);

View File

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

View File

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