From bacb730b5384e6c9f66026a74cf4853a5a042232 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 26 May 2020 12:35:21 +0200 Subject: [PATCH] Fix escape of non-JSON received serial data Fix escape of non-JSON received serial data (#8329) --- RELEASENOTES.md | 1 + tasmota/CHANGELOG.md | 1 + tasmota/support_tasmota.ino | 6 +++--- tasmota/xdrv_08_serial_bridge.ino | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index f78f518d5d27..2ac283ffbfd3 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -58,6 +58,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Change Adafruit_SGP30 library from v1.0.3 to v1.2.0 (#8519) - Change Energy JSON Total field from ``"Total":[33.736,11.717,16.978]`` to ``"Total":33.736,"TotalTariff":[11.717,16.978]`` - Change Energy JSON ExportActive field from ``"ExportActive":[33.736,11.717,16.978]`` to ``"ExportActive":33.736,"ExportTariff":[11.717,16.978]`` +- Fix escape of non-JSON received serial data (#8329) - Add command ``Rule0`` to change global rule parameters - Add command ``Time 4`` to display timestamp using milliseconds (#8537) - Add commands ``LedPwmOn 0..255``, ``LedPwmOff 0..255`` and ``LedPwmMode1 0/1`` to control led brightness by George (#8491) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 91ddbf1965e7..c7a2866a744e 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -5,6 +5,7 @@ - Change Energy JSON Total field from ``"Total":[33.736,11.717,16.978]`` to ``"Total":33.736,"TotalTariff":[11.717,16.978]`` - Change Energy JSON ExportActive field from ``"ExportActive":[33.736,11.717,16.978]`` to ``"ExportActive":33.736,"ExportTariff":[11.717,16.978]`` - Change Adafruit_SGP30 library from v1.0.3 to v1.2.0 (#8519) +- Fix escape of non-JSON received serial data (#8329) - Add command ``Time 4`` to display timestamp using milliseconds (#8537) - Add commands ``LedPwmOn 0..255``, ``LedPwmOff 0..255`` and ``LedPwmMode1 0/1`` to control led brightness by George (#8491) - Add Three Phase Export Active Energy to SDM630 driver diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index e0a45ce77b61..a3271131b35b 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1300,7 +1300,7 @@ void SerialInput(void) !in_byte_is_delimiter) { // Char is not a delimiter serial_in_buffer[serial_in_byte_counter++] = serial_in_byte; } - + if ((serial_in_byte_counter >= INPUT_BUFFER_SIZE -1) || // Send message when buffer is full or ... in_byte_is_delimiter) { // Char is delimiter serial_polling_window = 0; // Reception done - send mqtt @@ -1346,7 +1346,7 @@ void SerialInput(void) if (Settings.flag.mqtt_serial && serial_in_byte_counter && (millis() > (serial_polling_window + SERIAL_POLLING))) { // CMND_SERIALSEND and CMND_SERIALLOG serial_in_buffer[serial_in_byte_counter] = 0; // Serial data completed bool assume_json = (!Settings.flag.mqtt_serial_raw && (serial_in_buffer[0] == '{')); - + Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":")); if (assume_json) { ResponseAppend_P(serial_in_buffer); @@ -1360,7 +1360,7 @@ void SerialInput(void) } ResponseAppend_P(PSTR("\"")); } - ResponseAppend_P(PSTR("}")); + ResponseJsonEnd(); MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_SERIALRECEIVED)); XdrvRulesProcess(); diff --git a/tasmota/xdrv_08_serial_bridge.ino b/tasmota/xdrv_08_serial_bridge.ino index e50d4dd3317c..0dec9cb6ba3e 100644 --- a/tasmota/xdrv_08_serial_bridge.ino +++ b/tasmota/xdrv_08_serial_bridge.ino @@ -63,7 +63,7 @@ void SerialBridgeInput(void) !in_byte_is_delimiter) { // Char is not a delimiter serial_bridge_buffer[serial_bridge_in_byte_counter++] = serial_in_byte; } - + if ((serial_bridge_in_byte_counter >= SERIAL_BRIDGE_BUFFER_SIZE -1) || // Send message when buffer is full or ... in_byte_is_delimiter) { // Char is delimiter serial_bridge_polling_window = 0; // Publish now @@ -91,7 +91,7 @@ void SerialBridgeInput(void) } ResponseAppend_P(PSTR("\"")); } - ResponseAppend_P(PSTR("}")); + ResponseJsonEnd(); MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_SSERIALRECEIVED)); XdrvRulesProcess();