Change command ``Gpio`` layout of JSON message changed to single line

This commit is contained in:
Theo Arends 2021-06-08 18:46:39 +02:00
parent 8ca0b2045a
commit d9e1eaa780
5 changed files with 32 additions and 4 deletions

View File

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Changed ### Changed
- Allow longer MQTT response messages by removing fixed memory buffer with size 1040 to heap allocated buffer - 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 ``Timers`` layout of JSON message changed to single line
- Command ``Gpio`` layout of JSON message changed to single line
## [9.4.0.4] ## [9.4.0.4]
### Added ### Added

View File

@ -78,7 +78,7 @@ The binaries can be downloaded from either https://github.com/arendst/Tasmota/tr
## Changelog v9.4.0.5 ## Changelog v9.4.0.5
### Added ### 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":"<any template related command>|<any template related command>|..."`` [#11788](https://github.com/arendst/Tasmota/issues/11788) - Initial support for optional ``Template`` JSON fieldpair ``"CMND":"<any template related command>|<any template related command>|..."`` [#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) - 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) - 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 - 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 - 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 ``Timers`` layout of JSON message changed to single line
- Command ``Gpio`` layout of JSON message changed to single line
### Fixed ### Fixed

View File

@ -125,6 +125,13 @@ void ResponseCmndIdxError(void) {
void ResponseCmndAll(uint32_t text_index, uint32_t count) { void ResponseCmndAll(uint32_t text_index, uint32_t count) {
uint32_t real_index = text_index; uint32_t real_index = text_index;
ResponseClear(); 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; bool jsflg = false;
for (uint32_t i = 0; i < count; i++) { for (uint32_t i = 0; i < count; i++) {
if ((SET_MQTT_GRP_TOPIC == text_index) && (1 == i)) { real_index = SET_MQTT_GRP_TOPIC2 -1; } 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; jsflg = true;
} }
} }
#endif
} }
/********************************************************************************************/ /********************************************************************************************/
@ -1209,6 +1217,18 @@ void CmndModule(void)
void CmndModules(void) void CmndModules(void)
{ {
uint32_t midx = USER_MODULE; 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; uint32_t lines = 1;
bool jsflg = false; bool jsflg = false;
for (uint32_t i = 0; i <= sizeof(kModuleNiceList); i++) { for (uint32_t i = 0; i <= sizeof(kModuleNiceList); i++) {
@ -1228,6 +1248,7 @@ void CmndModules(void)
} }
} }
ResponseClear(); ResponseClear();
#endif
} }
void CmndGpio(void) void CmndGpio(void)
@ -1288,6 +1309,10 @@ void CmndGpio(void)
sensor_names = kSensorNamesFixed; sensor_names = kSensorNamesFixed;
} }
char stemp1[TOPSZ]; 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))) { 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(); ResponseJsonEnd();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, XdrvMailbox.command); MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, XdrvMailbox.command);
@ -1295,6 +1320,7 @@ void CmndGpio(void)
jsflg2 = true; jsflg2 = true;
jsflg = false; jsflg = false;
} }
#endif
} }
} }
if (jsflg) { if (jsflg) {

View File

@ -3925,7 +3925,7 @@ void toLogN(const char *cp, uint8_t len) {
void toLogEOL(const char *s1,const char *str) { void toLogEOL(const char *s1,const char *str) {
if (!str) return; if (!str) return;
uint8_t index = 0; uint8_t index = 0;
char log_data[MAX_LOGSZ]; char log_data[700]; // Was MAX_LOGSZ
char *cp = log_data; char *cp = log_data;
strcpy(cp, s1); strcpy(cp, s1);
cp += strlen(s1); cp += strlen(s1);
@ -5802,7 +5802,7 @@ void Script_Check_Hue(String *response) {
AddLog(LOG_LEVEL_DEBUG, PSTR("Hue: %d"), hue_devs); AddLog(LOG_LEVEL_DEBUG, PSTR("Hue: %d"), hue_devs);
toLog(">>>>"); toLog(">>>>");
toLog(response->c_str()); toLog(response->c_str());
toLog(response->c_str()+MAX_LOGSZ); toLog(response->c_str()+700); // Was MAX_LOGSZ
} }
#endif #endif
} }

View File

@ -433,7 +433,7 @@ void TuyaSendCmd(uint8_t cmd, uint8_t payload[] = nullptr, uint16_t payload_len
TuyaSerial->write(cmd); // Tuya command TuyaSerial->write(cmd); // Tuya command
TuyaSerial->write(payload_len >> 8); // following data length (Hi) TuyaSerial->write(payload_len >> 8); // following data length (Hi)
TuyaSerial->write(payload_len & 0xFF); // following data length (Lo) 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); 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) { for (uint32_t i = 0; i < payload_len; ++i) {
TuyaSerial->write(payload[i]); TuyaSerial->write(payload[i]);