mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-30 06:06:36 +00:00
Change JSON output format for some commands
Change JSON output format for commands Adc, Adcs, Modules, Gpio and Gpios from list to dictionary (#6407)
This commit is contained in:
parent
3a0fce2503
commit
1341db1392
@ -4,6 +4,7 @@
|
||||
* Commands Tariff1 22,23 = Tariff1 (Off-Peak) ST,DST Tariff2 (Standard) 6,7 = Tariff2 ST,DST Tariff9 0/1 = Weekend toggle (1 = Off-Peak during weekend)
|
||||
* Change rename "Data" to "Hash" and limit to 32 bits when receiving UNKNOWN IR protocol (see DECODE_HASH from IRremoteESP8266)
|
||||
* Add command Gpios 255/All to show all available GPIO components (#6407)
|
||||
* Change JSON output format for commands Adc, Adcs, Modules, Gpio and Gpios from list to dictionary (#6407)
|
||||
*
|
||||
* 6.6.0.11 20190907
|
||||
* Change Settings crc calculation allowing short term backward compatibility
|
||||
|
@ -537,8 +537,8 @@ const char S_JSON_COMMAND_SVALUE_SPACE_UNIT[] PROGMEM = "{\"%s\":\"%s %s\"
|
||||
const char S_JSON_COMMAND_NVALUE_UNIT[] PROGMEM = "{\"%s\":\"%d%s\"}";
|
||||
const char S_JSON_COMMAND_NVALUE_UNIT_NVALUE_UNIT[] PROGMEM = "{\"%s\":\"%d%s (%d%s)\"}";
|
||||
|
||||
const char S_JSON_COMMAND_NVALUE_SVALUE[] PROGMEM = "{\"%s\":\"%d (%s)\"}";
|
||||
const char S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE[] PROGMEM = "{\"%s\":\"%d (" D_JSON_ACTIVE " %d)\"}";
|
||||
const char S_JSON_COMMAND_NVALUE_SVALUE[] PROGMEM = "{\"%s\":{\"%d\":\"%s\"}}";
|
||||
const char S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE[] PROGMEM = "{\"%s\":{\"%d\":{\"" D_JSON_ACTIVE "\":\"%d\"}}}";
|
||||
|
||||
const char S_JSON_COMMAND_NVALUE[] PROGMEM = "{\"%s\":%d}";
|
||||
const char S_JSON_COMMAND_LVALUE[] PROGMEM = "{\"%s\":%lu}";
|
||||
@ -551,7 +551,7 @@ const char S_JSON_COMMAND_INDEX_LVALUE[] PROGMEM = "{\"%s%d\":%lu}";
|
||||
const char S_JSON_COMMAND_INDEX_SVALUE[] PROGMEM = "{\"%s%d\":\"%s\"}";
|
||||
const char S_JSON_COMMAND_INDEX_ASTERISK[] PROGMEM = "{\"%s%d\":\"" D_ASTERISK_PWD "\"}";
|
||||
const char S_JSON_COMMAND_INDEX_SVALUE_SVALUE[] PROGMEM = "{\"%s%d\":\"%s%s\"}";
|
||||
const char S_JSON_COMMAND_INDEX_NVALUE_ACTIVE_NVALUE[] PROGMEM = "{\"%s%d\":\"%d (" D_JSON_ACTIVE " %d)\"}";
|
||||
const char S_JSON_COMMAND_INDEX_NVALUE_ACTIVE_NVALUE[] PROGMEM = "{\"%s%d\":{\"%d\":{\"" D_JSON_ACTIVE "\":\"%d\"}}}";
|
||||
|
||||
const char S_JSON_SENSOR_INDEX_NVALUE[] PROGMEM = "{\"" D_CMND_SENSOR "%d\":%d}";
|
||||
const char S_JSON_SENSOR_INDEX_SVALUE[] PROGMEM = "{\"" D_CMND_SENSOR "%d\":\"%s\"}";
|
||||
|
@ -951,6 +951,11 @@ int ResponseJsonEnd(void)
|
||||
return ResponseAppend_P(PSTR("}"));
|
||||
}
|
||||
|
||||
int ResponseJsonEndEnd(void)
|
||||
{
|
||||
return ResponseAppend_P(PSTR("}}"));
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* GPIO Module and Template management
|
||||
\*********************************************************************************************/
|
||||
|
@ -366,7 +366,7 @@ void CmndStatus(void)
|
||||
XsnsDriverState();
|
||||
ResponseAppend_P(PSTR(",\"Sensors\":"));
|
||||
XsnsSensorState();
|
||||
ResponseAppend_P(PSTR("}}"));
|
||||
ResponseJsonEndEnd();
|
||||
MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "4"));
|
||||
}
|
||||
|
||||
@ -795,14 +795,14 @@ void CmndModules(void)
|
||||
for (uint32_t i = 0; i <= sizeof(kModuleNiceList); i++) {
|
||||
if (i > 0) { midx = pgm_read_byte(kModuleNiceList + i -1); }
|
||||
if (!jsflg) {
|
||||
Response_P(PSTR("{\"" D_CMND_MODULES "%d\":["), lines);
|
||||
Response_P(PSTR("{\"" D_CMND_MODULES "%d\":{"), lines);
|
||||
} else {
|
||||
ResponseAppend_P(PSTR(","));
|
||||
}
|
||||
jsflg = true;
|
||||
uint32_t j = i ? midx +1 : 0;
|
||||
if ((ResponseAppend_P(PSTR("\"%d (%s)\""), j, AnyModuleName(midx).c_str()) > (LOGSZ - TOPSZ)) || (i == sizeof(kModuleNiceList))) {
|
||||
ResponseAppend_P(PSTR("]}"));
|
||||
if ((ResponseAppend_P(PSTR("\"%d\":\"%s\""), j, AnyModuleName(midx).c_str()) > (LOGSZ - TOPSZ)) || (i == sizeof(kModuleNiceList))) {
|
||||
ResponseJsonEndEnd();
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, UpperCase(XdrvMailbox.command, XdrvMailbox.command));
|
||||
jsflg = false;
|
||||
lines++;
|
||||
@ -839,7 +839,7 @@ void CmndGpio(void)
|
||||
if (jsflg) { ResponseAppend_P(PSTR(",")); }
|
||||
jsflg = true;
|
||||
char stemp1[TOPSZ];
|
||||
ResponseAppend_P(PSTR("\"" D_CMND_GPIO "%d\":\"%d (%s)\""), i, Settings.my_gp.io[i], GetTextIndexed(stemp1, sizeof(stemp1), Settings.my_gp.io[i], kSensorNames));
|
||||
ResponseAppend_P(PSTR("\"" D_CMND_GPIO "%d\":{\"%d\":\"%s\"}"), i, Settings.my_gp.io[i], GetTextIndexed(stemp1, sizeof(stemp1), Settings.my_gp.io[i], kSensorNames));
|
||||
}
|
||||
}
|
||||
if (jsflg) {
|
||||
@ -861,14 +861,14 @@ void CmndGpios(void)
|
||||
midx = pgm_read_byte(kGpioNiceList + i);
|
||||
if ((XdrvMailbox.payload != 255) && GetUsedInModule(midx, cmodule.io)) { continue; }
|
||||
if (!jsflg) {
|
||||
Response_P(PSTR("{\"" D_CMND_GPIOS "%d\":["), lines);
|
||||
Response_P(PSTR("{\"" D_CMND_GPIOS "%d\":{"), lines);
|
||||
} else {
|
||||
ResponseAppend_P(PSTR(","));
|
||||
}
|
||||
jsflg = true;
|
||||
char stemp1[TOPSZ];
|
||||
if ((ResponseAppend_P(PSTR("\"%d (%s)\""), midx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames)) > (LOGSZ - TOPSZ)) || (i == sizeof(kGpioNiceList) -1)) {
|
||||
ResponseAppend_P(PSTR("]}"));
|
||||
if ((ResponseAppend_P(PSTR("\"%d\":\"%s\""), midx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames)) > (LOGSZ - TOPSZ)) || (i == sizeof(kGpioNiceList) -1)) {
|
||||
ResponseJsonEndEnd();
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, UpperCase(XdrvMailbox.command, XdrvMailbox.command));
|
||||
jsflg = false;
|
||||
lines++;
|
||||
|
@ -189,7 +189,7 @@ void IrReceiveCheck(void)
|
||||
ResponseAppend_P(PSTR("],\"" D_JSON_IR_RAWDATA "Info\":[%d,%d,%d]"), extended_length, i -1, results.overflow);
|
||||
}
|
||||
|
||||
ResponseAppend_P(PSTR("}}"));
|
||||
ResponseJsonEndEnd();
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_IRRECEIVED));
|
||||
|
||||
if (iridx) {
|
||||
|
@ -254,7 +254,7 @@ void IrReceiveCheck(void)
|
||||
ResponseAppend_P(PSTR("],\"" D_JSON_IR_RAWDATA "Info\":[%d,%d,%d]"), extended_length, i -1, results.overflow);
|
||||
}
|
||||
|
||||
ResponseAppend_P(PSTR("}}"));
|
||||
ResponseJsonEndEnd();
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_IRRECEIVED));
|
||||
|
||||
if (iridx) {
|
||||
|
@ -482,7 +482,7 @@ void CmndTimers(void)
|
||||
jsflg++;
|
||||
PrepShowTimer(i +1);
|
||||
if (jsflg > 3) {
|
||||
ResponseAppend_P(PSTR("}}"));
|
||||
ResponseJsonEndEnd();
|
||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_TIMERS));
|
||||
jsflg = 0;
|
||||
}
|
||||
|
@ -196,12 +196,12 @@ void CmndAdc(void)
|
||||
restart_flag = 2;
|
||||
}
|
||||
char stemp1[TOPSZ];
|
||||
Response_P(PSTR("{\"" D_CMND_ADC "0\":\"%d (%s)\"}"), Settings.my_adc0, GetTextIndexed(stemp1, sizeof(stemp1), Settings.my_adc0, kAdc0Names));
|
||||
Response_P(PSTR("{\"" D_CMND_ADC "0\":{\"%d\":\"%s\"}}"), Settings.my_adc0, GetTextIndexed(stemp1, sizeof(stemp1), Settings.my_adc0, kAdc0Names));
|
||||
}
|
||||
|
||||
void CmndAdcs(void)
|
||||
{
|
||||
Response_P(PSTR("{\"" D_CMND_ADCS "\":["));
|
||||
Response_P(PSTR("{\"" D_CMND_ADCS "\":{"));
|
||||
bool jsflg = false;
|
||||
char stemp1[TOPSZ];
|
||||
for (uint32_t i = 0; i < ADC0_END; i++) {
|
||||
@ -209,9 +209,9 @@ void CmndAdcs(void)
|
||||
ResponseAppend_P(PSTR(","));
|
||||
}
|
||||
jsflg = true;
|
||||
ResponseAppend_P(PSTR("\"%d (%s)\""), i, GetTextIndexed(stemp1, sizeof(stemp1), i, kAdc0Names));
|
||||
ResponseAppend_P(PSTR("\"%d\":\"%s\""), i, GetTextIndexed(stemp1, sizeof(stemp1), i, kAdc0Names));
|
||||
}
|
||||
ResponseAppend_P(PSTR("]}"));
|
||||
ResponseJsonEndEnd();
|
||||
}
|
||||
|
||||
void CmndAdcParam(void)
|
||||
|
@ -134,7 +134,7 @@ void Sgp30Show(bool json)
|
||||
if (global_update) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_AHUM "\":%s"),abs_hum);
|
||||
}
|
||||
ResponseAppend_P(PSTR("}"));
|
||||
ResponseJsonEnd();
|
||||
#ifdef USE_DOMOTICZ
|
||||
if (0 == tele_period) DomoticzSensor(DZ_AIRQUALITY, sgp.eCO2);
|
||||
#endif // USE_DOMOTICZ
|
||||
|
@ -1616,7 +1616,7 @@ void SML_Show(boolean json) {
|
||||
if (lastmind!=mindex) {
|
||||
// meter changed, close mqtt
|
||||
//snprintf_P(b_mqtt_data, sizeof(b_mqtt_data), "%s}", b_mqtt_data);
|
||||
ResponseAppend_P(PSTR("}"));
|
||||
ResponseJsonEnd();
|
||||
// and open new
|
||||
//snprintf_P(b_mqtt_data, sizeof(b_mqtt_data), "%s,\"%s\":{\"%s\":%s", b_mqtt_data,meter_desc_p[mindex].prefix,jname,tpowstr);
|
||||
ResponseAppend_P(PSTR(",\"%s\":{\"%s\":%s"),meter_desc_p[mindex].prefix,jname,tpowstr);
|
||||
@ -1643,7 +1643,7 @@ void SML_Show(boolean json) {
|
||||
if (json) {
|
||||
//snprintf_P(b_mqtt_data, sizeof(b_mqtt_data), "%s}", b_mqtt_data);
|
||||
//ResponseAppend_P(PSTR("%s"),b_mqtt_data);
|
||||
ResponseAppend_P(PSTR("}"));
|
||||
ResponseJsonEnd();
|
||||
} else {
|
||||
//WSContentSend_PD(PSTR("%s"),b_mqtt_data);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user