Fix ESP32 command `gpio 255` output

Fix ESP32 command ``gpio 255`` output
This commit is contained in:
Theo Arends 2020-12-16 12:34:43 +01:00
parent 88b3de0138
commit 761281e55c

View File

@ -1154,11 +1154,15 @@ void CmndGpio(void)
TasmotaGlobal.restart_flag = 2; TasmotaGlobal.restart_flag = 2;
} }
} }
Response_P(PSTR("{"));
bool jsflg = false; bool jsflg = false;
bool jsflg2 = false;
for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) {
if (ValidGPIO(i, template_gp.io[i]) || ((255 == XdrvMailbox.payload) && !FlashPin(i))) { if (ValidGPIO(i, template_gp.io[i]) || ((255 == XdrvMailbox.payload) && !FlashPin(i))) {
if (jsflg) { ResponseAppend_P(PSTR(",")); } if (!jsflg) {
Response_P(PSTR("{"));
} else {
ResponseAppend_P(PSTR(","));
}
jsflg = true; jsflg = true;
uint32_t sensor_type = Settings.my_gp.io[i]; uint32_t sensor_type = Settings.my_gp.io[i];
if (!ValidGPIO(i, template_gp.io[i])) { if (!ValidGPIO(i, template_gp.io[i])) {
@ -1183,12 +1187,16 @@ void CmndGpio(void)
sensor_names = kSensorNamesFixed; sensor_names = kSensorNamesFixed;
} }
char stemp1[TOPSZ]; char stemp1[TOPSZ];
ResponseAppend_P(PSTR("\"" D_CMND_GPIO "%d\":{\"%d\":\"%s%s\"}"), if ((ResponseAppend_P(PSTR("\"" D_CMND_GPIO "%d\":{\"%d\":\"%s%s\"}"), i, sensor_type, GetTextIndexed(stemp1, sizeof(stemp1), sensor_name_idx, sensor_names), sindex) > (LOGSZ - TOPSZ)) || (i == ARRAY_SIZE(Settings.my_gp.io) -1)) {
i, sensor_type, GetTextIndexed(stemp1, sizeof(stemp1), sensor_name_idx, sensor_names), sindex); ResponseJsonEndEnd();
MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command);
jsflg2 = true;
jsflg = false;
}
} }
} }
if (jsflg) { if (jsflg2) {
ResponseJsonEnd(); ResponseClear();
} else { } else {
ResponseCmndChar(D_JSON_NOT_SUPPORTED); ResponseCmndChar(D_JSON_NOT_SUPPORTED);
} }