From 8d8384f279f2ad30c94125a73798799a27091286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Wed, 27 Dec 2017 11:43:47 +0100 Subject: [PATCH] Force RFBridge to send messages even if switch is already in requested state --- code/espurna/relay.ino | 5 +++++ code/espurna/rfbridge.ino | 22 +++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 10fb7647..4bdab69e 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -141,6 +141,11 @@ bool relayStatus(unsigned char id, bool status, bool report, bool group_report) changed = true; } + // For RFBridge, keep sending the message even if the status is already the required + #if RELAY_PROVIDER == RELAY_PROVIDER_RFBRIDGE + rfbStatus(id, status); + #endif + } else { unsigned int current_time = millis(); diff --git a/code/espurna/rfbridge.ino b/code/espurna/rfbridge.ino index 9af59322..b8680a31 100644 --- a/code/espurna/rfbridge.ino +++ b/code/espurna/rfbridge.ino @@ -8,6 +8,8 @@ Copyright (C) 2017 by Xose PĂ©rez #ifdef ITEAD_SONOFF_RFBRIDGE +#include + // ----------------------------------------------------------------------------- // DEFINITIONS // ----------------------------------------------------------------------------- @@ -32,6 +34,10 @@ unsigned char _learnId = 0; bool _learnStatus = true; bool _rfbin = false; +byte _message_to_send[RF_MESSAGE_SIZE] = {0}; +byte _message_count = 0; +Ticker _rfbTicker; + // ----------------------------------------------------------------------------- // PRIVATES // ----------------------------------------------------------------------------- @@ -96,19 +102,21 @@ void _rfbSend(byte * message) { Serial.println(); } +void _rfbSend() { + if (_message_count) { + _rfbSend(_message_to_send); + if (--_message_count > 0) _rfbTicker.once_ms(RF_SEND_DELAY, _rfbSend); + } +} void _rfbSend(byte * message, int times) { char buffer[RF_MESSAGE_SIZE]; _rfbToChar(message, buffer); DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending MESSAGE '%s' %d time(s)\n"), buffer, times); - for (int i=0; i0) { - unsigned long start = millis(); - while (millis() - start < RF_SEND_DELAY) delay(1); - } - _rfbSend(message); - } + _message_count = times; + memcpy(_message_to_send, message, RF_MESSAGE_SIZE); + _rfbSend(); }