From c55babd41545a042dcdce40bca98bf9754799ae5 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 30 May 2021 18:47:39 +0200 Subject: [PATCH] Fix ESP32 compile error --- tasmota/support.ino | 15 +++++++++++++++ tasmota/xdrv_01_webserver.ino | 18 +++++++++++++++--- tasmota/xdrv_40_telegram.ino | 9 ++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index fd65135a5..dcbe397b0 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -2198,6 +2198,7 @@ void SyslogAsync(bool refresh) { AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_SYSLOG_HOST_NOT_FOUND ". " D_RETRY_IN " %d " D_UNIT_SECOND), SYSLOG_TIMER); return; } +/* char log_data[len +72]; // Hostname + Id + log data snprintf_P(log_data, sizeof(log_data), PSTR("%s ESP-"), NetworkHostname()); uint32_t preamble_len = strlen(log_data); @@ -2205,6 +2206,20 @@ void SyslogAsync(bool refresh) { strlcpy(log_data +preamble_len, line +mxtime, len); // wemos5 ESP-HTP: Web server active on wemos5 with IP address 192.168.2.172 PortUdp_write(log_data, preamble_len + len); +*/ + String log_data = NetworkHostname(); + log_data += F(" ESP-"); + +// log_data.concat(line +mxtime, len -mxtime -1); // Add terminating \'0' + len--; + char dummy = line[len]; + line[len] = '\0'; // Add terminating \'0' + log_data.concat(line +mxtime); + line[len] = dummy; + + // wemos5 ESP-HTP: Web server active on wemos5 with IP address 192.168.2.172 + PortUdp.write(log_data.c_str()); + PortUdp.endPacket(); delay(1); // Add time for UDP handling (#5512) } diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 68d53d588..8c9434cc9 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -2848,9 +2848,16 @@ void HandleHttpCommand(void) // [14:49:36.123 MQTT: stat/wemos5/RESULT = {"POWER":"OFF"}] > [{"POWER":"OFF"}] char* JSON = (char*)memchr(line, '{', len); if (JSON) { // Is it a JSON message (and not only [15:26:08 MQT: stat/wemos5/POWER = O]) - size_t JSONlen = len - (JSON - line); String stemp = (cflg) ? "," : ""; // Add a comma - stemp.concat(JSON +1, JSONlen -3); // Add a terminating '\0' + size_t JSONlen = len - (JSON - line); + +// stemp.concat(JSON +1, JSONlen -3); // Add a terminating '\0' + len -= 2; + char dummy = line[len]; + line[len] = '\0'; // Add terminating \'0' + stemp.concat(JSON +1); + line[len] = dummy; + Webserver->sendContent(stemp); cflg = true; } @@ -2931,7 +2938,12 @@ void HandleConsoleRefresh(void) WSContentFlush(); while (GetLog(Settings.weblog_level, &index, &line, &len)) { String stemp = (cflg) ? "\n" : ""; // Add a newline - stemp.concat(line, len -1); // Add a terminating '\0' + len--; +// stemp.concat(line, len); // Add a terminating '\0' + char dummy = line[len]; + line[len] = '\0'; // Add terminating \'0' + stemp.concat(line); + line[len] = dummy; Webserver->sendContent(stemp); cflg = true; } diff --git a/tasmota/xdrv_40_telegram.ino b/tasmota/xdrv_40_telegram.ino index 5a4ce7545..630b1690b 100644 --- a/tasmota/xdrv_40_telegram.ino +++ b/tasmota/xdrv_40_telegram.ino @@ -300,7 +300,14 @@ String TelegramExecuteCommand(const char *svalue) { if (JSON) { // Is it a JSON message (and not only [15:26:08 MQT: stat/wemos5/POWER = O]) size_t JSONlen = len - (JSON - line); if (cflg) { response += F(","); } - response.concat(JSON +1, JSONlen -3); + +// response.concat(JSON +1, JSONlen -3); + len -= 2; + char dummy = line[len]; + line[len] = '\0'; // Add terminating \'0' + response.concat(JSON +1); + line[len] = dummy; + cflg = true; } }