Encode content when not raw or json

This commit is contained in:
Matthijs Abma 2020-05-23 17:34:59 +02:00
parent 3829265e6d
commit a4ce4830e8
2 changed files with 10 additions and 2 deletions

View File

@ -1349,7 +1349,11 @@ void SerialInput(void)
bool assume_json = (!Settings.flag.mqtt_serial_raw && (serial_in_buffer[0] == '{'));
Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":%s%s%s}"),
(assume_json) ? "" : "\"",
(Settings.flag.mqtt_serial_raw) ? ToHex_P((unsigned char*)serial_in_buffer, serial_in_byte_counter, hex_char, sizeof(hex_char)) : serial_in_buffer,
(Settings.flag.mqtt_serial_raw)
? ToHex_P((unsigned char*)serial_in_buffer, serial_in_byte_counter, hex_char, sizeof(hex_char))
: (assume_json)
? serial_in_buffer
: EscapeJSONString(serial_in_buffer).c_str(),
(assume_json) ? "" : "\"");
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_SERIALRECEIVED));
XdrvRulesProcess();

View File

@ -80,7 +80,11 @@ void SerialBridgeInput(void)
bool assume_json = (!serial_bridge_raw && (serial_bridge_buffer[0] == '{'));
Response_P(PSTR("{\"" D_JSON_SSERIALRECEIVED "\":%s%s%s}"),
(assume_json) ? "" : "\"",
(serial_bridge_raw) ? ToHex_P((unsigned char*)serial_bridge_buffer, serial_bridge_in_byte_counter, hex_char, sizeof(hex_char)) : serial_bridge_buffer,
(serial_bridge_raw)
? ToHex_P((unsigned char*)serial_bridge_buffer, serial_bridge_in_byte_counter, hex_char, sizeof(hex_char))
: (assume_json)
? serial_bridge_buffer
: EscapeJSONString(serial_bridge_buffer).c_str(),
(assume_json) ? "" : "\"");
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_SSERIALRECEIVED));
XdrvRulesProcess();