From e1011d3cdd8ac55e556169482dd2c82c24b00e12 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sat, 28 Apr 2018 11:17:16 +0200 Subject: [PATCH 1/3] Disable sleep on core 2.4.1 5.12.0m * Disable sleep when using Esp/Arduino core 2.4.1 (#2559) --- sonoff/_releasenotes.ino | 1 + sonoff/support.ino | 2 ++ 2 files changed, 3 insertions(+) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 4be23c8d7..725ce14e3 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,6 +1,7 @@ /* 5.12.0m * Reinit timers to accomodate random window (#2447) * Remove sonoff-xxl + * Disable sleep when using Esp/Arduino core 2.4.1 (#2559) * Add sonoff-classic, sonoff-allsensors and sonoff-knx * Add some coloring to important web buttons * Add rule variables and teleperiod trigger to accomodate user HA messages diff --git a/sonoff/support.ino b/sonoff/support.ino index 8bc76d6a8..37e2139bb 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -615,7 +615,9 @@ void WifiBegin(uint8_t flag) delay(200); WiFi.mode(WIFI_STA); // Disable AP mode if (Settings.sleep) { +#ifndef ARDUINO_ESP8266_RELEASE_2_4_1 // See https://github.com/arendst/Sonoff-Tasmota/issues/2559 WiFi.setSleepMode(WIFI_LIGHT_SLEEP); // Allow light sleep during idle times +#endif } // if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { // WiFi.setPhyMode(WIFI_PHY_MODE_11N); From c8352351413315e034b708f5e4a3f92f4c6a8c6b Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sat, 28 Apr 2018 15:55:38 +0200 Subject: [PATCH 2/3] v5.12.0n - Change ADS1115 and Counter JSON 5.12.0n * Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560) * Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules * Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}} --- README.md | 4 ++-- sonoff/_releasenotes.ino | 7 ++++++- sonoff/sonoff.ino | 2 +- sonoff/support.ino | 2 +- sonoff/xsns_01_counter.ino | 15 ++++++++++++++- sonoff/xsns_12_ads1115.ino | 2 +- sonoff/xsns_12_ads1115_i2cdev.ino | 2 +- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a15c9ab91..8d55383d2 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! ### Development: [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) -Current version is **5.12.0m** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **5.12.0n** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. ### Quick install Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as documented in the wiki. @@ -133,7 +133,7 @@ Different firmware images are released based on Features and Sensors selection g |--------------------------------|--------|---------|---------|------|------------| | ESP/Arduino lib v2.3.0 | 526k | 488k | 427k | 535k | 549k | | ESP/Arduino lib v2.4.0 | 531k | 496k | 435k | 540k | 552k | -| ESP/Arduino lib v2.4.1 | 533k | 498k | 436k | 542k | 554k | +| ESP/Arduino lib v2.4.1 | 534k | 499k | 437k | 543k | 555k | ### Contribute You can contribute to Sonoff-Tasmota by diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 725ce14e3..ec42dee40 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,9 @@ -/* 5.12.0m +/* 5.12.0n + * Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560) + * Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules + * Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}} + * + * 5.12.0m * Reinit timers to accomodate random window (#2447) * Remove sonoff-xxl * Disable sleep when using Esp/Arduino core 2.4.1 (#2559) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index ab223790a..2da537983 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x050C000D // 5.12.0m +#define VERSION 0x050C000E // 5.12.0n // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) diff --git a/sonoff/support.ino b/sonoff/support.ino index 37e2139bb..7ff973b2d 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1396,7 +1396,7 @@ void AdcShow(boolean json) analog >>= 5; if (json) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_ANALOG_INPUT "0\":%d"), mqtt_data, analog); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"ANALOG\":{\"A0\":%d}"), mqtt_data, analog); #ifdef USE_WEBSERVER } else { snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ANALOG, mqtt_data, "", 0, analog); diff --git a/sonoff/xsns_01_counter.ino b/sonoff/xsns_01_counter.ino index 397f3d853..d1cb5da5b 100644 --- a/sonoff/xsns_01_counter.ino +++ b/sonoff/xsns_01_counter.ino @@ -90,9 +90,11 @@ const char HTTP_SNS_COUNTER[] PROGMEM = void CounterShow(boolean json) { + char stemp[10]; char counter[16]; byte dsxflg = 0; + byte header = 0; for (byte i = 0; i < MAX_COUNTERS; i++) { if (pin[GPIO_CNTR1 +i] < 99) { if (bitRead(Settings.pulse_counter_type, i)) { @@ -103,7 +105,13 @@ void CounterShow(boolean json) } if (json) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_COUNTER "%d\":%s"), mqtt_data, i +1, counter); + if (!header) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"COUNTER\":{"), mqtt_data); + stemp[0] = '\0'; + } + header++; + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"C%d\":%s"), mqtt_data, stemp, i +1, counter); + strcpy(stemp, ","); #ifdef USE_DOMOTICZ if ((0 == tele_period) && (1 == dsxflg)) { DomoticzSensor(DZ_COUNT, RtcSettings.pulse_counter[i]); @@ -117,6 +125,11 @@ void CounterShow(boolean json) } } } + if (json) { + if (header) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data); + } + } } /*********************************************************************************************\ diff --git a/sonoff/xsns_12_ads1115.ino b/sonoff/xsns_12_ads1115.ino index 19c3ccf8a..f1279a732 100644 --- a/sonoff/xsns_12_ads1115.ino +++ b/sonoff/xsns_12_ads1115.ino @@ -190,7 +190,7 @@ void Ads1115Show(boolean json) stemp[0] = '\0'; } dsxflg++; - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_JSON_ANALOG_INPUT "%d\":%d"), mqtt_data, stemp, i, adc_value); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"A%d\":%d"), mqtt_data, stemp, i, adc_value); strcpy(stemp, ","); #ifdef USE_WEBSERVER } else { diff --git a/sonoff/xsns_12_ads1115_i2cdev.ino b/sonoff/xsns_12_ads1115_i2cdev.ino index 692040743..d3748ec7a 100644 --- a/sonoff/xsns_12_ads1115_i2cdev.ino +++ b/sonoff/xsns_12_ads1115_i2cdev.ino @@ -110,7 +110,7 @@ void Ads1115Show(boolean json) stemp[0] = '\0'; } dsxflg++; - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_JSON_ANALOG_INPUT "%d\":%d"), mqtt_data, stemp, i, adc_value); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"A%d\":%d"), mqtt_data, stemp, i, adc_value); strcpy(stemp, ","); #ifdef USE_WEBSERVER } else { From 44598e5fc4a2d1a12dc86d721272587c8394c66f Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sat, 28 Apr 2018 18:18:37 +0200 Subject: [PATCH 3/3] Add ANALOG#A0div10 trigger to rules 5.12.0n * Add ANALOG#A0div10 trigger to rules to be used in rule like on analog#a0div10 do publish cmnd/ailight/dimmer %value% endon --- sonoff/_releasenotes.ino | 1 + sonoff/support.ino | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index ec42dee40..d7bed584e 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -2,6 +2,7 @@ * Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560) * Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules * Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}} + * Add ANALOG#A0div10 trigger to rules to be used in rule like on analog#a0div10 do publish cmnd/ailight/dimmer %value% endon * * 5.12.0m * Reinit timers to accomodate random window (#2447) diff --git a/sonoff/support.ino b/sonoff/support.ino index 7ff973b2d..da95e4f25 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1386,7 +1386,10 @@ void RtcInit() * ADC support \*********************************************************************************************/ -void AdcShow(boolean json) +uint8_t adc_counter = 0; +uint16_t adc_last_value = 0; + +uint16_t AdcRead() { uint16_t analog = 0; for (byte i = 0; i < 32; i++) { @@ -1394,6 +1397,26 @@ void AdcShow(boolean json) delay(1); } analog >>= 5; + return analog; +} + +void AdcEvery50ms() +{ + adc_counter++; + if (!(adc_counter % 4)) { + uint16_t new_value = AdcRead(); + if ((new_value < adc_last_value -10) || (new_value > adc_last_value +10)) { + adc_last_value = new_value; + uint16_t value = adc_last_value / 10; + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"ANALOG\":{\"A0div10\":%d}}"), (0 == value) ? 1 : (value > 99) ? 100 : value); + RulesProcess(); + } + } +} + +void AdcShow(boolean json) +{ + uint16_t analog = AdcRead(); if (json) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"ANALOG\":{\"A0\":%d}"), mqtt_data, analog); @@ -1416,6 +1439,9 @@ boolean Xsns02(byte function) if (pin[GPIO_ADC0] < 99) { switch (function) { + case FUNC_EVERY_50_MSECOND: + AdcEvery50ms(); + break; case FUNC_JSON_APPEND: AdcShow(1); break;