From 300bb8818f629b360124235f2e35258d16960ee2 Mon Sep 17 00:00:00 2001 From: arendst Date: Tue, 29 Aug 2017 16:35:45 +0200 Subject: [PATCH] Fix Sonoff Bridge duplicates and check power at startup 5.6.1g * Add power check at startup (#526) * Add duplicate check to received RF signal within 2 seconds for Sonoff Bridge (#810) --- README.md | 2 +- sonoff/_releasenotes.ino | 6 +++++- sonoff/sonoff.ino | 10 +++++++++- sonoff/xdrv_snfbridge.ino | 30 ++++++++++++++++++++---------- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index eab99601b..79944d043 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.6.1f** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **5.6.1g** - 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 83112c9ce..562c3382a 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,8 @@ -/* 5.6.1f +/* 5.6.1g + * Add power check at startup (#526) + * Add duplicate check to received RF signal within 2 seconds for Sonoff Bridge (#810) + * + * 5.6.1f * Fix JSON error (#786) * Revert changes from 5.6.1e but extent HLW power timer to 10 seconds (#796) * diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index a8889ad87..e34f64aa8 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x05060106 // 5.6.1f +#define VERSION 0x05060107 // 5.6.1g 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}; @@ -2863,6 +2863,14 @@ void setup() } } } + + // Issue #526 + for (byte i = 0; i < Maxdevice; i++) { + if ((pin[GPIO_REL1 +i] < 99) && (digitalRead(pin[GPIO_REL1 +i]))) { + bitSet(power, i); + } + } + blink_powersave = power; if (SONOFF_SC == sysCfg.module) { diff --git a/sonoff/xdrv_snfbridge.ino b/sonoff/xdrv_snfbridge.ino index 37a293f14..3a60498b9 100644 --- a/sonoff/xdrv_snfbridge.ino +++ b/sonoff/xdrv_snfbridge.ino @@ -21,9 +21,13 @@ Sonoff RF Bridge 433 \*********************************************************************************************/ +#define SFB_TIME_AVOID_DUPLICATE 2000 // Milliseconds + uint8_t sfb_rcvflg = 0; uint8_t sfb_learnKey = 1; uint8_t sfb_learnFlg = 0; +uint32_t sfb_lastrid = 0; +unsigned long sfb_lasttime = 0; void sb_received() { @@ -68,19 +72,25 @@ void sb_received() rlo = serialInBuf[3] << 8 | serialInBuf[4]; // Low time in uSec rhi = serialInBuf[5] << 8 | serialInBuf[6]; // High time in uSec rid = serialInBuf[7] << 16 | serialInBuf[8] << 8 | serialInBuf[9]; - strcpy_P(rfkey, PSTR("\"None\"")); - for (i = 1; i <= 16; i++) { - if (sysCfg.sfb_code[i][0]) { - sid = sysCfg.sfb_code[i][6] << 16 | sysCfg.sfb_code[i][7] << 8 | sysCfg.sfb_code[i][8]; - if (sid == rid) { - snprintf_P(rfkey, sizeof(rfkey), PSTR("%d"), i); - break; + + unsigned long now = millis(); + if (!((rid == sfb_lastrid) && (now - sfb_lasttime < SFB_TIME_AVOID_DUPLICATE))) { + sfb_lastrid = rid; + sfb_lasttime = now; + strcpy_P(rfkey, PSTR("\"None\"")); + for (i = 1; i <= 16; i++) { + if (sysCfg.sfb_code[i][0]) { + sid = sysCfg.sfb_code[i][6] << 16 | sysCfg.sfb_code[i][7] << 8 | sysCfg.sfb_code[i][8]; + if (sid == rid) { + snprintf_P(rfkey, sizeof(rfkey), PSTR("%d"), i); + break; + } } } + snprintf_P(svalue, sizeof(svalue), PSTR("{\"RfReceived\":{\"Sync\":%d, \"Low\":%d, \"High\":%d, \"Data\":\"%06X\", \"RfKey\":%s}}"), + rsy, rlo, rhi, rid, rfkey); + mqtt_publish_topic_P(6, PSTR("RFRECEIVED"), svalue); } - snprintf_P(svalue, sizeof(svalue), PSTR("{\"RfReceived\":{\"Sync\":%d, \"Low\":%d, \"High\":%d, \"Data\":\"%06X\", \"RfKey\":%s}}"), - rsy, rlo, rhi, rid, rfkey); - mqtt_publish_topic_P(6, PSTR("RFRECEIVED"), svalue); } }