mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-22 15:38:16 +03:00
Use PSRAM for MQTT publishing and make it scheduled (#2113)
* Run the Homeassistant Discovery directly after connecting to the broker. Before it was delayed 10s and happened while the first round alredy was in progress * schedule sending HA discovery and static topics * Allow setting QOS for MQTT topics * . * . * change MQTT QOS1 expiration time from (default) 30 to 5s * add logging of heap change on MQTT topic sendings * wait for MQTT transmission timeout after publishing * use QOS0 for Homeassistant Discovery topics. the messages then could possibly get lost but we save a lot of heap * . * use PSRAM for the MQTT outbox * use QOS1 for HA discovery again * . * . * disable delay, not needed with PSRAM * . * consolidated scheduledSendingOf_DiscoveryAndStaticTopics into sendingOf_DiscoveryAndStaticTopics_scheduled * Send Homeasstsiatnt Discovery and static data in MQTT step instead of when the wifi gets connected * "WIFI roaming" by channel scan (AP switching at low RSSI) (#2120) * Activate 802.11kv wifi mesh roaming * Activate roaming by scanning * Revert stack reducation * move Wifi, LWIP and BSSI to PSRAm * added State Class "measurement" to rate_per_time_unit (#2116) Co-authored-by: CaCO3 <caco@ruinelli.ch> * use QOS0 for Homeassistant Discovery topics. the messages then could possibly get lost but we save a lot of heap * use QOS0 for Homeassistant Discovery topics. the messages then could possibly get lost but we save a lot of heap # Conflicts: # code/components/jomjol_mqtt/server_mqtt.cpp # Conflicts: # code/components/jomjol_mqtt/server_mqtt.cpp * . * . * move to next PR * Update code/components/jomjol_mqtt/server_mqtt.cpp * Update code/components/jomjol_mqtt/server_mqtt.cpp --------- Co-authored-by: CaCO3 <caco@ruinelli.ch> Co-authored-by: Slider0007 <115730895+Slider0007@users.noreply.github.com>
This commit is contained in:
@@ -277,7 +277,7 @@ void ClassFlowControll::InitFlow(std::string config)
|
||||
aktstatusWithTime = aktstatus;
|
||||
|
||||
//#ifdef ENABLE_MQTT
|
||||
//MQTTPublish(mqttServer_getMainTopic() + "/" + "status", "Initialization", false); // Right now, not possible -> MQTT Service is going to be started later
|
||||
//MQTTPublish(mqttServer_getMainTopic() + "/" + "status", "Initialization", 1, false); // Right now, not possible -> MQTT Service is going to be started later
|
||||
//#endif //ENABLE_MQTT
|
||||
|
||||
string line;
|
||||
@@ -352,7 +352,7 @@ void ClassFlowControll::doFlowTakeImageOnly(string time)
|
||||
aktstatus = TranslateAktstatus(FlowControll[i]->name());
|
||||
aktstatusWithTime = aktstatus + " (" + zw_time + ")";
|
||||
#ifdef ENABLE_MQTT
|
||||
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, false);
|
||||
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, 1, false);
|
||||
#endif //ENABLE_MQTT
|
||||
|
||||
FlowControll[i]->doFlow(time);
|
||||
@@ -366,6 +366,7 @@ bool ClassFlowControll::doFlow(string time)
|
||||
bool result = true;
|
||||
std::string zw_time;
|
||||
int repeat = 0;
|
||||
int qos = 1;
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
LogFile.WriteHeapInfo("ClassFlowControll::doFlow - Start");
|
||||
@@ -386,7 +387,7 @@ bool ClassFlowControll::doFlow(string time)
|
||||
aktstatusWithTime = aktstatus + " (" + zw_time + ")";
|
||||
//LogFile.WriteToFile(ESP_LOG_INFO, TAG, aktstatusWithTime);
|
||||
#ifdef ENABLE_MQTT
|
||||
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, false);
|
||||
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, qos, false);
|
||||
#endif //ENABLE_MQTT
|
||||
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
@@ -420,7 +421,7 @@ bool ClassFlowControll::doFlow(string time)
|
||||
aktstatusWithTime = aktstatus + " (" + zw_time + ")";
|
||||
//LogFile.WriteToFile(ESP_LOG_INFO, TAG, aktstatusWithTime);
|
||||
#ifdef ENABLE_MQTT
|
||||
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, false);
|
||||
MQTTPublish(mqttServer_getMainTopic() + "/" + "status", aktstatus, qos, false);
|
||||
#endif //ENABLE_MQTT
|
||||
|
||||
return result;
|
||||
|
||||
@@ -225,8 +225,12 @@ bool ClassFlowMQTT::doFlow(string zwtime)
|
||||
std::string resultchangabs = "";
|
||||
string zw = "";
|
||||
string namenumber = "";
|
||||
int qos = 1;
|
||||
|
||||
success = publishSystemData();
|
||||
/* Send the the Homeassistant Discovery and the Static Topics in case they where scheduled */
|
||||
sendDiscovery_and_static_Topics();
|
||||
|
||||
success = publishSystemData(qos);
|
||||
|
||||
if (flowpostprocessing && getMQTTisConnected())
|
||||
{
|
||||
@@ -252,13 +256,13 @@ bool ClassFlowMQTT::doFlow(string zwtime)
|
||||
|
||||
|
||||
if (result.length() > 0)
|
||||
success |= MQTTPublish(namenumber + "value", result, SetRetainFlag);
|
||||
success |= MQTTPublish(namenumber + "value", result, qos, SetRetainFlag);
|
||||
|
||||
if (resulterror.length() > 0)
|
||||
success |= MQTTPublish(namenumber + "error", resulterror, SetRetainFlag);
|
||||
success |= MQTTPublish(namenumber + "error", resulterror, qos, SetRetainFlag);
|
||||
|
||||
if (resultrate.length() > 0) {
|
||||
success |= MQTTPublish(namenumber + "rate", resultrate, SetRetainFlag);
|
||||
success |= MQTTPublish(namenumber + "rate", resultrate, qos, SetRetainFlag);
|
||||
|
||||
std::string resultRatePerTimeUnit;
|
||||
if (getTimeUnit() == "h") { // Need conversion to be per hour
|
||||
@@ -267,22 +271,22 @@ bool ClassFlowMQTT::doFlow(string zwtime)
|
||||
else { // Keep per minute
|
||||
resultRatePerTimeUnit = resultrate;
|
||||
}
|
||||
success |= MQTTPublish(namenumber + "rate_per_time_unit", resultRatePerTimeUnit, SetRetainFlag);
|
||||
success |= MQTTPublish(namenumber + "rate_per_time_unit", resultRatePerTimeUnit, qos, SetRetainFlag);
|
||||
}
|
||||
|
||||
if (resultchangabs.length() > 0) {
|
||||
success |= MQTTPublish(namenumber + "changeabsolut", resultchangabs, SetRetainFlag); // Legacy API
|
||||
success |= MQTTPublish(namenumber + "rate_per_digitalization_round", resultchangabs, SetRetainFlag);
|
||||
success |= MQTTPublish(namenumber + "changeabsolut", resultchangabs, qos, SetRetainFlag); // Legacy API
|
||||
success |= MQTTPublish(namenumber + "rate_per_digitalization_round", resultchangabs, qos, SetRetainFlag);
|
||||
}
|
||||
|
||||
if (resultraw.length() > 0)
|
||||
success |= MQTTPublish(namenumber + "raw", resultraw, SetRetainFlag);
|
||||
success |= MQTTPublish(namenumber + "raw", resultraw, qos, SetRetainFlag);
|
||||
|
||||
if (resulttimestamp.length() > 0)
|
||||
success |= MQTTPublish(namenumber + "timestamp", resulttimestamp, SetRetainFlag);
|
||||
success |= MQTTPublish(namenumber + "timestamp", resulttimestamp, qos, SetRetainFlag);
|
||||
|
||||
std::string json = flowpostprocessing->getJsonFromNumber(i, "\n");
|
||||
success |= MQTTPublish(namenumber + "json", json, SetRetainFlag);
|
||||
success |= MQTTPublish(namenumber + "json", json, qos, SetRetainFlag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +304,7 @@ bool ClassFlowMQTT::doFlow(string zwtime)
|
||||
// result = result + "\t" + zw;
|
||||
// }
|
||||
// }
|
||||
// success |= MQTTPublish(topic, result, SetRetainFlag);
|
||||
// success |= MQTTPublish(topic, result, qos, SetRetainFlag);
|
||||
// }
|
||||
|
||||
OldValue = result;
|
||||
|
||||
Reference in New Issue
Block a user