diff --git a/README.md b/README.md index 527af8594..4b9968144 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 **3.9.8** - See ```sonoff/_releasenotes.ino``` for change information. +Current version is **3.9.9** - See ```sonoff/_releasenotes.ino``` for change information. - This version provides all (Sonoff) modules in one file and starts up with Sonoff Basic. - Once uploaded select module using the configuration webpage or the commands ```Modules``` and ```Module```. diff --git a/api/arduino/sonoff.ino.bin b/api/arduino/sonoff.ino.bin index 061eb83c7..788244233 100644 Binary files a/api/arduino/sonoff.ino.bin and b/api/arduino/sonoff.ino.bin differ diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 2f4ac83cc..e76539ba8 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,8 @@ -/* 3.9.8 20170130 +/* 3.9.9 20170130 + * Add command status 10 showing sensor data + * Fix hlw status messages if hlw is disabled + * + * 3.9.8 20170130 * Remove GPIO07 and GPIO08 from user selectable (#5) * * 3.9.7 20170129 diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 0120f2a5b..3587de366 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -10,7 +10,7 @@ * ==================================================== */ -#define VERSION 0x03090800 // 3.9.8 +#define VERSION 0x03090900 // 3.9.9 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}; @@ -93,7 +93,7 @@ enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX}; #endif #define APP_BAUDRATE 115200 // Default serial baudrate -#define MAX_STATUS 9 +#define MAX_STATUS 10 enum butt_t {PRESSED, NOT_PRESSED}; @@ -1836,6 +1836,7 @@ void publish_status(uint8_t payload) (!strcmp(SUB_PREFIX,PUB_PREFIX) && (!payload)) ? PUB_PREFIX2 : PUB_PREFIX, sysCfg.mqtt_topic); if ((!sysCfg.mqtt_enabled) && (payload == 6)) payload = 99; + if ((!hlw_flg) && ((payload == 8) || (payload == 9))) payload = 99; if ((payload == 0) || (payload == 99)) { snprintf_P(svalue, sizeof(svalue), PSTR("{\"Status\":{\"Module\":%d, \"FriendlyName\":\"%s\", \"Topic\":\"%s\", \"ButtonTopic\":\"%s\", \"Subtopic\":\"%s\", \"Power\":%d, \"PowerOnState\":%d, \"LedState\":%d, \"SaveData\":%d, \"SaveState\":%d, \"ButtonRetain\":%d, \"PowerRetain\":%d}}"), @@ -1902,11 +1903,53 @@ void publish_status(uint8_t payload) if ((payload == 0) || (payload == 7)) { snprintf_P(svalue, sizeof(svalue), PSTR("{\"StatusTIM\":{\"UTC\":\"%s\", \"Local\":\"%s\", \"StartDST\":\"%s\", \"EndDST\":\"%s\", \"Timezone\":%d}}"), rtc_time(0).c_str(), rtc_time(1).c_str(), rtc_time(2).c_str(), rtc_time(3).c_str(), sysCfg.timezone); + if (payload == 0) mqtt_publish(stopic, svalue); + } + + if ((payload == 0) || (payload == 10)) { + uint8_t djson = 0; + snprintf_P(svalue, sizeof(svalue), PSTR("{\"StatusSNS\":")); + sensors_mqttPresent(svalue, sizeof(svalue), &djson); + if (!djson) snprintf_P(svalue, sizeof(svalue), PSTR("%s}"), svalue); } mqtt_publish(stopic, svalue); } +void sensors_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson) +{ + char stime[21]; + + snprintf_P(stime, sizeof(stime), PSTR("%04d-%02d-%02dT%02d:%02d:%02d"), + rtcTime.Year, rtcTime.Month, rtcTime.Day, rtcTime.Hour, rtcTime.Minute, rtcTime.Second); + snprintf_P(svalue, ssvalue, PSTR("%s{\"Time\":\"%s\""), svalue, stime); + if (pin[GPIO_DSB] < 99) { +#ifdef USE_DS18B20 + dsb_mqttPresent(svalue, ssvalue, djson); +#endif // USE_DS18B20 +#ifdef USE_DS18x20 + ds18x20_mqttPresent(svalue, ssvalue, djson); +#endif // USE_DS18x20 + } +#if defined(USE_DHT) || defined(USE_DHT2) + if (dht_type) dht_mqttPresent(svalue, ssvalue, djson); +#endif // USE_DHT/2 +#ifdef USE_I2C + if (i2c_flg) { +#ifdef USE_HTU + htu_mqttPresent(svalue, ssvalue, djson); +#endif // USE_HTU +#ifdef USE_BMP + bmp_mqttPresent(svalue, ssvalue, djson); +#endif // USE_BMP +#ifdef USE_BH1750 + bh1750_mqttPresent(svalue, ssvalue, djson); +#endif // USE_BH1750 + } +#endif // USE_I2C + snprintf_P(svalue, ssvalue, PSTR("%s}"), svalue); +} + /********************************************************************************************/ void every_second_cb() @@ -2003,37 +2046,11 @@ void every_second() mqtt_publish(stopic, svalue); uint8_t djson = 0; - snprintf_P(svalue, sizeof(svalue), PSTR("{\"Time\":\"%s\""), stime); - if (pin[GPIO_DSB] < 99) { -#ifdef USE_DS18B20 - dsb_mqttPresent(svalue, sizeof(svalue), &djson, 0); -#endif // USE_DS18B20 -#ifdef USE_DS18x20 - ds18x20_mqttPresent(svalue, sizeof(svalue), &djson, 0); -#endif // USE_DS18x20 - } -#if defined(USE_DHT) || defined(USE_DHT2) - if (dht_type) dht_mqttPresent(svalue, sizeof(svalue), &djson, 1); -#endif // USE_DHT/2 -#ifdef USE_I2C - if (i2c_flg) { -#ifdef USE_HTU - htu_mqttPresent(svalue, sizeof(svalue), &djson, 1); -#endif // USE_HTU -#ifdef USE_BMP - bmp_mqttPresent(svalue, sizeof(svalue), &djson, 2); -#endif // USE_BMP -#ifdef USE_BH1750 - bh1750_mqttPresent(svalue, sizeof(svalue), &djson, 3); -#endif // USE_BH1750 - } -#endif // USE_I2C - if (djson) { - snprintf_P(svalue, sizeof(svalue), PSTR("%s}"), svalue); - mqtt_publish(stopic, svalue); - } + svalue[0] = '\0'; + sensors_mqttPresent(svalue, sizeof(svalue), &djson); + if (djson) mqtt_publish(stopic, svalue); - if (hlw_flg) hlw_mqttPresent(4); + if (hlw_flg) hlw_mqttPresent(); } } diff --git a/sonoff/xsns_bh1750.ino b/sonoff/xsns_bh1750.ino index 405e4a1f1..603fd9805 100644 --- a/sonoff/xsns_bh1750.ino +++ b/sonoff/xsns_bh1750.ino @@ -82,7 +82,7 @@ boolean bh1750_detect() * Presentation \*********************************************************************************************/ -void bh1750_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx) +void bh1750_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson) { if (!bh1750type) return; diff --git a/sonoff/xsns_bmp.ino b/sonoff/xsns_bmp.ino index 91f00eb55..6475895b6 100644 --- a/sonoff/xsns_bmp.ino +++ b/sonoff/xsns_bmp.ino @@ -424,7 +424,7 @@ boolean bmp_detect() * Presentation \*********************************************************************************************/ -void bmp_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx) +void bmp_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson) { if (!bmptype) return; diff --git a/sonoff/xsns_dht.ino b/sonoff/xsns_dht.ino index 4809c83ac..816819567 100644 --- a/sonoff/xsns_dht.ino +++ b/sonoff/xsns_dht.ino @@ -178,7 +178,7 @@ void dht_init() * Presentation \*********************************************************************************************/ -void dht_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx) +void dht_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson) { char stemp1[10], stemp2[10]; float t, h; diff --git a/sonoff/xsns_dht2.ino b/sonoff/xsns_dht2.ino index 9239182a8..5b885625a 100644 --- a/sonoff/xsns_dht2.ino +++ b/sonoff/xsns_dht2.ino @@ -57,7 +57,7 @@ void dht_init() * Presentation \*********************************************************************************************/ -void dht_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx) +void dht_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson) { char stemp1[10], stemp2[10]; float t, h; diff --git a/sonoff/xsns_ds18b20.ino b/sonoff/xsns_ds18b20.ino index eec7d5cb2..b77d89f69 100644 --- a/sonoff/xsns_ds18b20.ino +++ b/sonoff/xsns_ds18b20.ino @@ -172,7 +172,7 @@ boolean dsb_readTemp(bool S, float &t) * Presentation \*********************************************************************************************/ -void dsb_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx) +void dsb_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson) { char stemp1[10]; float t; diff --git a/sonoff/xsns_ds18x20.ino b/sonoff/xsns_ds18x20.ino index 1205d76ea..334c3c944 100644 --- a/sonoff/xsns_ds18x20.ino +++ b/sonoff/xsns_ds18x20.ino @@ -155,7 +155,7 @@ boolean ds18x20_read(uint8_t sensor, bool S, float &t) * Presentation \*********************************************************************************************/ -void ds18x20_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx) +void ds18x20_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson) { char stemp1[10], stemp2[10]; float t; diff --git a/sonoff/xsns_hlw8012.ino b/sonoff/xsns_hlw8012.ino index a15b62ded..b37c2fc28 100644 --- a/sonoff/xsns_hlw8012.ino +++ b/sonoff/xsns_hlw8012.ino @@ -520,7 +520,7 @@ void hlw_commands(char *svalue, uint16_t ssvalue) * Presentation \*********************************************************************************************/ -void hlw_mqttPresent(uint8_t domidx) +void hlw_mqttPresent() { char stopic[TOPSZ], svalue[MESSZ], stime[21], stemp0[10], stemp1[10], stemp2[10], stemp3[10]; float ped, pi, pc; diff --git a/sonoff/xsns_htu21.ino b/sonoff/xsns_htu21.ino index ddb9cc6bc..36e26f8be 100644 --- a/sonoff/xsns_htu21.ino +++ b/sonoff/xsns_htu21.ino @@ -229,7 +229,7 @@ uint8_t htu_detect() * Presentation \*********************************************************************************************/ -void htu_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson, uint8_t domidx) +void htu_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson) { if (!htutype) return;