From b8a55a1f8cbf2abf4b2ee3ccce441c28d7a55eab Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 2 Dec 2019 23:20:00 +0100 Subject: [PATCH 1/3] increase ws buffer sizes - https://github.com/proddy/EMS-ESP/issues/250 --- src/MyESP.cpp | 33 +++++++++++++++++---------------- src/MyESP.h | 8 +++++--- src/ems-esp.cpp | 30 +++++++++++++++--------------- src/version.h | 2 +- 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/MyESP.cpp b/src/MyESP.cpp index a01222dc6..c48ae5d62 100644 --- a/src/MyESP.cpp +++ b/src/MyESP.cpp @@ -1472,8 +1472,8 @@ void MyESP::_heartbeatCheck(bool force) { uint32_t free_memory = ESP.getFreeHeap(); uint8_t mem_available = 100 * free_memory / total_memory; // as a % - StaticJsonDocument<200> doc; - JsonObject rootHeartbeat = doc.to(); + StaticJsonDocument doc; + JsonObject rootHeartbeat = doc.to(); rootHeartbeat["version"] = _app_version; rootHeartbeat["IP"] = WiFi.localIP().toString(); @@ -2312,11 +2312,13 @@ void MyESP::_onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, A // handle ws from browser void MyESP::_procMsg(AsyncWebSocketClient * client, size_t sz) { // We should always get a JSON object from browser, so parse it - StaticJsonDocument<500> doc; - char json[sz + 1]; + StaticJsonDocument doc; + char json[sz + 1]; memcpy(json, (char *)(client->_tempObject), sz); json[sz] = '\0'; + // Serial.printf("[%s]", json); + JsonObject root = doc.to(); // create empty object DeserializationError error = deserializeJson(doc, json); // Deserialize the JSON document if (error) { @@ -2410,8 +2412,7 @@ bool MyESP::_fs_sendConfig() { // send custom status via ws void MyESP::_sendCustomStatus() { - // StaticJsonDocument<300> doc; - DynamicJsonDocument doc(MYESP_JSON_MAXSIZE); + DynamicJsonDocument doc(MYESP_JSON_MAXSIZE_LARGE); JsonObject root = doc.to(); @@ -2427,7 +2428,7 @@ void MyESP::_sendCustomStatus() { (_web_callback_f)(root); } - char buffer[MYESP_JSON_MAXSIZE]; + char buffer[MYESP_JSON_MAXSIZE_LARGE]; size_t len = serializeJson(root, buffer); #ifdef MYESP_DEBUG @@ -2536,9 +2537,9 @@ void MyESP::_printScanResult(int networksFound) { } } - StaticJsonDocument<400> doc; - JsonObject root = doc.to(); - root["command"] = "ssidlist"; + StaticJsonDocument doc; + JsonObject root = doc.to(); + root["command"] = "ssidlist"; JsonArray list = doc.createNestedArray("list"); for (int i = 0; i <= 5 && i < networksFound; ++i) { @@ -2548,7 +2549,7 @@ void MyESP::_printScanResult(int networksFound) { item["rssi"] = WiFi.RSSI(indices[i]); } - char buffer[400]; + char buffer[MYESP_JSON_MAXSIZE_MEDIUM]; size_t len = serializeJson(root, buffer); _ws->textAll(buffer, len); } @@ -2750,12 +2751,12 @@ void MyESP::_addMQTTLog(const char * topic, const char * payload, const MYESP_MQ // send UTC time via ws void MyESP::_sendTime() { - StaticJsonDocument<100> doc; - JsonObject root = doc.to(); - root["command"] = "gettime"; - root["epoch"] = now(); + StaticJsonDocument doc; + JsonObject root = doc.to(); + root["command"] = "gettime"; + root["epoch"] = now(); - char buffer[100]; + char buffer[MYESP_JSON_MAXSIZE_SMALL]; size_t len = serializeJson(root, buffer); _ws->textAll(buffer, len); } diff --git a/src/MyESP.h b/src/MyESP.h index 899a35a96..b79bd64c6 100644 --- a/src/MyESP.h +++ b/src/MyESP.h @@ -103,9 +103,11 @@ extern struct rst_info resetInfo; #define MQTT_DISCONNECT_EVENT 1 #define MQTT_MESSAGE_EVENT 2 -#define MYESP_JSON_MAXSIZE 2000 // for large Dynamic json files -#define MYESP_MQTTLOG_MAX 60 // max number of log entries for MQTT publishes and subscribes -#define MYESP_JSON_LOG_MAXSIZE 300 // max size of an JSON log entry +#define MYESP_JSON_MAXSIZE_LARGE 2000 // for large Dynamic json files +#define MYESP_JSON_MAXSIZE_MEDIUM 800 // for medium Dynamic json files +#define MYESP_JSON_MAXSIZE_SMALL 200 // for smaller Static json documents + +#define MYESP_MQTTLOG_MAX 60 // max number of log entries for MQTT publishes and subscribes #define MYESP_MQTT_PAYLOAD_ON '1' // for MQTT switch on #define MYESP_MQTT_PAYLOAD_OFF '0' // for MQTT switch off diff --git a/src/ems-esp.cpp b/src/ems-esp.cpp index 69cd55363..067986665 100644 --- a/src/ems-esp.cpp +++ b/src/ems-esp.cpp @@ -515,8 +515,8 @@ void publishSensorValues(bool force) { return; // no sensors attached } - StaticJsonDocument<200> doc; - JsonObject sensors = doc.to(); + StaticJsonDocument doc; + JsonObject sensors = doc.to(); bool hasdata = false; char label[8] = {0}; @@ -539,7 +539,7 @@ void publishSensorValues(bool force) { CRC32 crc; uint32_t fchecksum; - char data[200] = {0}; + char data[MYESP_JSON_MAXSIZE_SMALL] = {0}; serializeJson(doc, data, sizeof(data)); size_t jsonSize = measureJson(doc); @@ -1038,10 +1038,10 @@ bool LoadSaveCallback(MYESP_FSACTION_t action, JsonObject settings) { // Publish shower data bool do_publishShowerData() { - StaticJsonDocument<200> doc; - JsonObject rootShower = doc.to(); - rootShower[TOPIC_SHOWER_TIMER] = EMSESP_Settings.shower_timer ? "1" : "0"; - rootShower[TOPIC_SHOWER_ALERT] = EMSESP_Settings.shower_alert ? "1" : "0"; + StaticJsonDocument doc; + JsonObject rootShower = doc.to(); + rootShower[TOPIC_SHOWER_TIMER] = EMSESP_Settings.shower_timer ? "1" : "0"; + rootShower[TOPIC_SHOWER_ALERT] = EMSESP_Settings.shower_alert ? "1" : "0"; // only publish shower duration if there is a value char s[50] = {0}; @@ -1486,8 +1486,8 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) { // check first for generic commands if (strcmp(topic, TOPIC_GENERIC_CMD) == 0) { // convert JSON and get the command - StaticJsonDocument<100> doc; - DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document + StaticJsonDocument doc; + DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document if (error) { myDebug_P(PSTR("[MQTT] Invalid command from topic %s, payload %s, error %s"), topic, message, error.c_str()); return; @@ -1505,8 +1505,8 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) { // check for shower commands if (strcmp(topic, TOPIC_SHOWER_DATA) == 0) { - StaticJsonDocument<100> doc; - DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document + StaticJsonDocument doc; + DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document if (error) { myDebug_P(PSTR("[MQTT] Invalid command from topic %s, payload %s, error %s"), topic, message, error.c_str()); return; @@ -1532,8 +1532,8 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) { // check for boiler commands if (strcmp(topic, TOPIC_BOILER_CMD) == 0) { // convert JSON and get the command - StaticJsonDocument<100> doc; - DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document + StaticJsonDocument doc; + DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document if (error) { myDebug_P(PSTR("[MQTT] Invalid command from topic %s, payload %s, error %s"), topic, message, error.c_str()); return; @@ -1619,8 +1619,8 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) { // check for generic thermostat commands if (strcmp(topic, TOPIC_THERMOSTAT_CMD) == 0) { // convert JSON and get the command - StaticJsonDocument<100> doc; - DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document + StaticJsonDocument doc; + DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document if (error) { myDebug_P(PSTR("[MQTT] Invalid command from topic %s, payload %s, error %s"), topic, message, error.c_str()); return; diff --git a/src/version.h b/src/version.h index 3abff063c..332d9f39b 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define APP_VERSION "1.9.4b21" +#define APP_VERSION "1.9.4b22" From c20c4998e98b37cf48bfebc135603269281cf3cf Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 3 Dec 2019 20:30:14 +0100 Subject: [PATCH 2/3] esnure heating and tap water mqtt messages are sent immediately --- src/ems-esp.cpp | 13 ++++--------- src/ems.cpp | 2 ++ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/ems-esp.cpp b/src/ems-esp.cpp index 067986665..4b4ec77f4 100644 --- a/src/ems-esp.cpp +++ b/src/ems-esp.cpp @@ -706,12 +706,12 @@ void publishEMSValues(bool force) { // see if the heating or hot tap water has changed, if so send // last_boilerActive stores heating in bit 1 and tap water in bit 2 - if ((last_boilerActive != ((EMS_Boiler.tapwaterActive << 1) + EMS_Boiler.heatingActive)) || force) { + if ((last_boilerActive != ((EMS_Boiler.tapwaterActive << 1) | EMS_Boiler.heatingActive)) || force) { myDebugLog("Publishing hot water and heating states via MQTT"); myESP.mqttPublish(TOPIC_BOILER_TAPWATER_ACTIVE, EMS_Boiler.tapwaterActive == 1 ? "1" : "0"); myESP.mqttPublish(TOPIC_BOILER_HEATING_ACTIVE, EMS_Boiler.heatingActive == 1 ? "1" : "0"); - last_boilerActive = ((EMS_Boiler.tapwaterActive << 1) + EMS_Boiler.heatingActive); // remember last state + last_boilerActive = ((EMS_Boiler.tapwaterActive << 1) | EMS_Boiler.heatingActive); // remember last state } // handle the thermostat values @@ -2030,13 +2030,8 @@ void loop() { do_regularUpdates(); publishEMSValues(true); publishSensorValues(true); - _need_first_publish = false; // reset flag - } - - // publish all the values to MQTT - // but only if the values have changed and publish_time is on automatic mode - // always publish when we get the first results, regardless of any publish_time setting - if (EMSESP_Settings.publish_time == 0) { + _need_first_publish = false; // reset flag, so only do this once + } else { publishEMSValues(false); publishSensorValues(false); } diff --git a/src/ems.cpp b/src/ems.cpp index 28d5138b1..4f608fb39 100644 --- a/src/ems.cpp +++ b/src/ems.cpp @@ -1272,6 +1272,8 @@ void _checkActive() { if (EMS_Boiler.selFlowTemp != EMS_VALUE_INT_NOTSET && EMS_Boiler.burnGas != EMS_VALUE_INT_NOTSET) { EMS_Boiler.heatingActive = ((EMS_Boiler.selFlowTemp >= EMS_BOILER_SELFLOWTEMP_HEATING) && (EMS_Boiler.burnGas == EMS_VALUE_INT_ON)); } + + EMS_Sys_Status.emsRefreshed = true; // triggers a send the values back via MQTT } /** From 1150c197e2f23c640210ffddb75288ad90f3966e Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 4 Dec 2019 23:30:35 +0100 Subject: [PATCH 3/3] add uuid-* libs - https://github.com/proddy/EMS-ESP/issues/251 --- platformio.ini | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index da681e846..636663a2f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -45,13 +45,16 @@ lib_deps = https://github.com/PaulStoffregen/OneWire https://github.com/me-no-dev/ESPAsyncWebServer https://github.com/bakercp/CRC32 - https://github.com/nomis/mcu-uuid-syslog + https://github.com/me-no-dev/ESPAsyncUDP JustWifi@2.0.2 ; https://github.com/xoseperez/justwifi AsyncMqttClient@0.8.2 ; https://github.com/marvinroger/async-mqtt-client EEPROM_Rotate@0.9.2 ; https://github.com/xoseperez/eeprom_rotate ArduinoJson@6.13.0 ; https://github.com/bblanchon/ArduinoJson - ESPAsyncTCP@1.2.2 ; https://github.com/me-no-dev/ESPAsyncTCP - https://github.com/me-no-dev/ESPAsyncUDP + ESPAsyncTCP@1.2.2 ; https://github.com/me-no-dev/ESPAsyncTCP + uuid-common@^1.1.0 + uuid-log@^2.1.1 + uuid-syslog@^2.0.4 ; https://github.com/nomis/mcu-uuid-syslog + upload_speed = 921600 monitor_speed = 115200