From cbb3f9e0af6e163cebf18a29c4d011281743db23 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 3 Oct 2019 10:02:57 +0200 Subject: [PATCH] Change command PulseTime JSON message Change command PulseTime JSON message format and allow display of all pulsetimer information (#6519) --- sonoff/_changelog.ino | 1 + sonoff/i18n.h | 3 ++- sonoff/support_command.ino | 20 ++++++++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 13a994061..e9cdf437d 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,5 +1,6 @@ /*********************************************************************************************\ * 6.6.0.15 20191003 + * Change command PulseTime JSON message format and allow display of all pulsetimer information (#6519) * * 6.6.0.14 20190925 * Change command Tariffx to allow time entries like 23 (hours), 1320 (minutes) or 23:00. NOTE: As this is development branch previous tariffs are lost! (#6488) diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 5dae197a6..089140dd9 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -118,6 +118,7 @@ #define D_JSON_PROGRAMFLASHSIZE "ProgramFlashSize" #define D_JSON_PROGRAMSIZE "ProgramSize" #define D_JSON_REFERENCETEMPERATURE "ReferenceTemperature" +#define D_JSON_REMAINING "Remaining" #define D_JSON_RESET "Reset" #define D_JSON_RESISTANCE "Resistance" #define D_JSON_RESOLUTION "Resolution" @@ -132,6 +133,7 @@ #define D_JSON_SDKVERSION "SDK" #define D_JSON_SELECTED "selected" #define D_JSON_SERIALRECEIVED "SerialReceived" +#define D_JSON_SET "Set" #define D_JSON_SSID "SSId" #define D_JSON_STARTDST "StartDST" // Start Daylight Savings Time #define D_JSON_STARTED "Started" @@ -557,7 +559,6 @@ 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_SENSOR_INDEX_NVALUE[] PROGMEM = "{\"" D_CMND_SENSOR "%d\":%d}"; const char S_JSON_SENSOR_INDEX_SVALUE[] PROGMEM = "{\"" D_CMND_SENSOR "%d\":\"%s\"}"; diff --git a/sonoff/support_command.ino b/sonoff/support_command.ino index 182796519..4683c7c85 100644 --- a/sonoff/support_command.ino +++ b/sonoff/support_command.ino @@ -565,11 +565,23 @@ void CmndPowerOnState(void) void CmndPulsetime(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_PULSETIMERS)) { - if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 65536)) { - Settings.pulse_timer[XdrvMailbox.index -1] = XdrvMailbox.payload; // 0 - 65535 - SetPulseTimer(XdrvMailbox.index -1, XdrvMailbox.payload); + uint32_t items = 1; + if (!XdrvMailbox.usridx) { + items = MAX_PULSETIMERS; + } else { + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 65536)) { + Settings.pulse_timer[XdrvMailbox.index -1] = XdrvMailbox.payload; // 0 - 65535 + SetPulseTimer(XdrvMailbox.index -1, XdrvMailbox.payload); + } } - Response_P(S_JSON_COMMAND_INDEX_NVALUE_ACTIVE_NVALUE, XdrvMailbox.command, XdrvMailbox.index, Settings.pulse_timer[XdrvMailbox.index -1], GetPulseTimer(XdrvMailbox.index -1)); + mqtt_data[0] = '\0'; + for (uint32_t i = 0; i < items; i++) { + ResponseAppend_P(PSTR("%c\"%s%d\":{\"" D_JSON_SET "\":%d,\"" D_JSON_REMAINING "\":%d}"), + (i) ? ',' : '{', + XdrvMailbox.command, (1 == items) ? XdrvMailbox.index : i +1, + Settings.pulse_timer[XdrvMailbox.index -1], GetPulseTimer(XdrvMailbox.index -1)); + } + ResponseJsonEnd(); } }