From cb0410a5dc6465bba4dd55f901695063ab43ddfc Mon Sep 17 00:00:00 2001 From: arendst Date: Thu, 14 Sep 2017 15:35:38 +0200 Subject: [PATCH] v5.7.1f - Add dimmer parameter to Wakeup 5.7.1f * Reduce code and string length for output of commands Modules and GPIOs * Add optional dimmer parameter to command Wakeup for AiLight, Sonoff B1, Led and BN-SZ01 (#867) --- README.md | 2 +- sonoff/_releasenotes.ino | 6 ++++- sonoff/sonoff.ino | 56 +++++++++++++++++----------------------- sonoff/xdrv_snfled.ino | 3 +++ 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index c048c4719..16c67f013 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## Sonoff-Tasmota Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE. -Current version is **5.7.1e** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **5.7.1f** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. ### ATTENTION All versions diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 3ebcdb2ee..a0c500bda 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,8 @@ -/* 5.7.1e +/* 5.7.1f + * Reduce code and string length for output of commands Modules and GPIOs + * Add optional dimmer parameter to command Wakeup (#867) + * + * 5.7.1e * Add Sonoff SC debug information * Change syslog service * diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index c50f8289d..810181690 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x05070105 // 5.7.1e +#define VERSION 0x05070106 // 5.7.1f enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL}; enum week_t {Last, First, Second, Third, Fourth}; @@ -882,6 +882,8 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len) char *type = NULL; byte otype = 0; byte ptype = 0; + byte jsflg = 0; + byte lines = 1; uint16_t i = 0; uint16_t grpflg = 0; uint16_t index; @@ -1178,29 +1180,23 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len) snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MODULE "\":\"%d (%s)\"}"), sysCfg.module +1, stemp1); } else if (!strcasecmp_P(type, PSTR(D_CMND_MODULES))) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MODULES "1\":\"")); - byte jsflg = 0; - for (byte i = 0; i < MAXMODULE /2; i++) { - if (jsflg) { + for (byte i = 0; i < MAXMODULE; i++) { + if (!jsflg) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MODULES "%d\":\""), lines); + } else { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, "), mqtt_data); } jsflg = 1; snprintf_P(stemp1, sizeof(stemp1), modules[i].name); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%d (%s)"), mqtt_data, i +1, stemp1); - } - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"}"), mqtt_data); - mqtt_publish_topic_P(5, type); - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MODULES "2\":\"")); - jsflg = 0; - for (byte i = MAXMODULE /2; i < MAXMODULE; i++) { - if (jsflg) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, "), mqtt_data); + if ((strlen(mqtt_data) > 200) || (i == MAXMODULE -1)) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"}"), mqtt_data); + mqtt_publish_topic_P(5, type); + jsflg = 0; + lines++; } - jsflg = 1; - snprintf_P(stemp1, sizeof(stemp1), modules[i].name); - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%d (%s)"), mqtt_data, i +1, stemp1); } - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"}"), mqtt_data); + mqtt_data[0] = '\0'; } else if (!strcasecmp_P(type, PSTR(D_CMND_GPIO)) && (index < MAX_GPIO_PIN)) { mytmplt cmodule; @@ -1233,29 +1229,23 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len) } } else if (!strcasecmp_P(type, PSTR(D_CMND_GPIOS))) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_GPIOS "1\":\"")); - byte jsflg = 0; - for (byte i = 0; i < GPIO_SENSOR_END /2; i++) { - if (jsflg) { + for (byte i = 0; i < GPIO_SENSOR_END; i++) { + if (!jsflg) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_GPIOS "%d\":\""), lines); + } else { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, "), mqtt_data); } jsflg = 1; snprintf_P(stemp1, sizeof(stemp1), sensors[i]); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%d (%s)"), mqtt_data, i, stemp1); - } - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"}"), mqtt_data); - mqtt_publish_topic_P(5, type); - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_GPIOS "2\":\"")); - jsflg = 0; - for (byte i = GPIO_SENSOR_END /2; i < GPIO_SENSOR_END; i++) { - if (jsflg) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, "), mqtt_data); + if ((strlen(mqtt_data) > 200) || (i == GPIO_SENSOR_END -1)) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"}"), mqtt_data); + mqtt_publish_topic_P(5, type); + jsflg = 0; + lines++; } - jsflg = 1; - snprintf_P(stemp1, sizeof(stemp1), sensors[i]); - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%d (%s)"), mqtt_data, i, stemp1); } - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"}"), mqtt_data); + mqtt_data[0] = '\0'; } else if (!strcasecmp_P(type, PSTR(D_CMND_PWM)) && (index > pwm_idxoffset) && (index <= 5)) { if ((payload >= 0) && (payload <= PWM_RANGE) && (pin[GPIO_PWM1 + index -1] < 99)) { diff --git a/sonoff/xdrv_snfled.ino b/sonoff/xdrv_snfled.ino index 12429f394..a7db3934e 100644 --- a/sonoff/xdrv_snfled.ino +++ b/sonoff/xdrv_snfled.ino @@ -549,6 +549,9 @@ boolean sl_command(char *type, uint16_t index, char *dataBufUc, uint16_t data_le snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WAKEUPDURATION "\":%d}"), sysCfg.led_wakeup); } else if (!strcasecmp_P(type, PSTR(D_CMND_WAKEUP))) { + if ((payload >= 0) && (payload <= 100)) { + sysCfg.led_dimmer[0] = payload; + } sl_wakeupActive = 3; do_cmnd_power(1, 1); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WAKEUP "\":\"" D_STARTED "\"}"));