From d9e1eaa7807bd065a418df86ad2d95d7f8ccf31a Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 8 Jun 2021 18:46:39 +0200 Subject: [PATCH] Change command ``Gpio`` layout of JSON message changed to single line --- CHANGELOG.md | 1 + RELEASENOTES.md | 3 ++- tasmota/support_command.ino | 26 ++++++++++++++++++++++++++ tasmota/xdrv_10_scripter.ino | 4 ++-- tasmota/xdrv_16_tuyamcu.ino | 2 +- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c30fde0c9..c79f47664 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### Changed - Allow longer MQTT response messages by removing fixed memory buffer with size 1040 to heap allocated buffer - Command ``Timers`` layout of JSON message changed to single line +- Command ``Gpio`` layout of JSON message changed to single line ## [9.4.0.4] ### Added diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 405a9a707..ca5b3449d 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -78,7 +78,7 @@ The binaries can be downloaded from either https://github.com/arendst/Tasmota/tr ## Changelog v9.4.0.5 ### Added -- Command ``Status0`` providing all status in one line +- Command ``Status0`` providing all status information on a single line - Initial support for optional ``Template`` JSON fieldpair ``"CMND":"||..."`` [#11788](https://github.com/arendst/Tasmota/issues/11788) - ESP32 pulldown buttons ``Button_d`` and ``Button_id`` and switches ``Switch_d`` [#10814](https://github.com/arendst/Tasmota/issues/10814) - Support for MQTT using Azure IoT Hub by Kevin Saye [#11906](https://github.com/arendst/Tasmota/issues/11906) @@ -96,6 +96,7 @@ The binaries can be downloaded from either https://github.com/arendst/Tasmota/tr - IRremoteESP8266 library from v2.7.16 to v2.7.18 - Allow longer MQTT response messages by removing fixed memory buffer with size 1040 to heap allocated buffer - Command ``Timers`` layout of JSON message changed to single line +- Command ``Gpio`` layout of JSON message changed to single line ### Fixed diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index d36d44c6d..9d7636e2c 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -125,6 +125,13 @@ void ResponseCmndIdxError(void) { void ResponseCmndAll(uint32_t text_index, uint32_t count) { uint32_t real_index = text_index; ResponseClear(); +#ifdef MQTT_DATA_STRING + for (uint32_t i = 0; i < count; i++) { + if ((SET_MQTT_GRP_TOPIC == text_index) && (1 == i)) { real_index = SET_MQTT_GRP_TOPIC2 -1; } + ResponseAppend_P(PSTR("%c\"%s%d\":\"%s\""), (i)?',':'{', XdrvMailbox.command, i +1, EscapeJSONString(SettingsText(real_index +i)).c_str()); + } + ResponseJsonEnd(); +#else bool jsflg = false; for (uint32_t i = 0; i < count; i++) { if ((SET_MQTT_GRP_TOPIC == text_index) && (1 == i)) { real_index = SET_MQTT_GRP_TOPIC2 -1; } @@ -137,6 +144,7 @@ void ResponseCmndAll(uint32_t text_index, uint32_t count) { jsflg = true; } } +#endif } /********************************************************************************************/ @@ -1209,6 +1217,18 @@ void CmndModule(void) void CmndModules(void) { uint32_t midx = USER_MODULE; +#ifdef MQTT_DATA_STRING + Response_P(PSTR("{\"" D_CMND_MODULES "\":{")); + for (uint32_t i = 0; i <= sizeof(kModuleNiceList); i++) { + if (i > 0) { + midx = pgm_read_byte(kModuleNiceList + i -1); + ResponseAppend_P(PSTR(",")); + } + uint32_t j = i ? midx +1 : 0; + ResponseAppend_P(PSTR("\"%d\":\"%s\""), j, AnyModuleName(midx).c_str()); + } + ResponseJsonEndEnd(); +#else uint32_t lines = 1; bool jsflg = false; for (uint32_t i = 0; i <= sizeof(kModuleNiceList); i++) { @@ -1228,6 +1248,7 @@ void CmndModules(void) } } ResponseClear(); +#endif } void CmndGpio(void) @@ -1288,6 +1309,10 @@ void CmndGpio(void) sensor_names = kSensorNamesFixed; } char stemp1[TOPSZ]; +#ifdef MQTT_DATA_STRING + ResponseAppend_P(PSTR("\"" D_CMND_GPIO "%d\":{\"%d\":\"%s%s\"}"), i, sensor_type, GetTextIndexed(stemp1, sizeof(stemp1), sensor_name_idx, sensor_names), sindex); + jsflg2 = true; +#else if ((ResponseAppend_P(PSTR("\"" D_CMND_GPIO "%d\":{\"%d\":\"%s%s\"}"), i, sensor_type, GetTextIndexed(stemp1, sizeof(stemp1), sensor_name_idx, sensor_names), sindex) > (MAX_LOGSZ - TOPSZ))) { ResponseJsonEnd(); MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, XdrvMailbox.command); @@ -1295,6 +1320,7 @@ void CmndGpio(void) jsflg2 = true; jsflg = false; } +#endif } } if (jsflg) { diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 05b69df0c..77927f9c1 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -3925,7 +3925,7 @@ void toLogN(const char *cp, uint8_t len) { void toLogEOL(const char *s1,const char *str) { if (!str) return; uint8_t index = 0; - char log_data[MAX_LOGSZ]; + char log_data[700]; // Was MAX_LOGSZ char *cp = log_data; strcpy(cp, s1); cp += strlen(s1); @@ -5802,7 +5802,7 @@ void Script_Check_Hue(String *response) { AddLog(LOG_LEVEL_DEBUG, PSTR("Hue: %d"), hue_devs); toLog(">>>>"); toLog(response->c_str()); - toLog(response->c_str()+MAX_LOGSZ); + toLog(response->c_str()+700); // Was MAX_LOGSZ } #endif } diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index 295860c33..a629c0a6d 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -433,7 +433,7 @@ void TuyaSendCmd(uint8_t cmd, uint8_t payload[] = nullptr, uint16_t payload_len TuyaSerial->write(cmd); // Tuya command TuyaSerial->write(payload_len >> 8); // following data length (Hi) TuyaSerial->write(payload_len & 0xFF); // following data length (Lo) - char log_data[MAX_LOGSZ]; + char log_data[700]; // Was MAX_LOGSZ snprintf_P(log_data, sizeof(log_data), PSTR("TYA: Send \"55aa00%02x%02x%02x"), cmd, payload_len >> 8, payload_len & 0xFF); for (uint32_t i = 0; i < payload_len; ++i) { TuyaSerial->write(payload[i]);