From 3b385ad6b940edc4e9e05b24853123c6fbf458ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Wed, 9 Aug 2017 21:57:16 +0200 Subject: [PATCH] Enable serial debug on Sonoff RFBridge --- code/espurna/config/debug.h | 2 +- code/espurna/config/general.h | 12 ++++++++++-- code/espurna/config/hardware.h | 6 ++++++ code/espurna/relay.ino | 13 ++++++++++--- code/espurna/rfbridge.ino | 16 ++++++++++++++-- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/code/espurna/config/debug.h b/code/espurna/config/debug.h index e350dbe8..54178cd3 100644 --- a/code/espurna/config/debug.h +++ b/code/espurna/config/debug.h @@ -1,6 +1,6 @@ #define DEBUG_MESSAGE_MAX_LENGTH 80 -#if defined(SONOFF_DUAL) | defined(SONOFF_RFBRIDGE) +#if defined(SONOFF_DUAL) #undef DEBUG_PORT #endif diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 0c2003fe..bda2a590 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -23,8 +23,8 @@ // To receive the message son the destination computer use nc: // nc -ul 8111 -#define DEBUG_UDP_IP IPAddress(192, 168, 1, 100) -#define DEBUG_UDP_PORT 8113 +//#define DEBUG_UDP_IP IPAddress(192, 168, 1, 100) +//#define DEBUG_UDP_PORT 8113 //-------------------------------------------------------------------------------- // EEPROM @@ -346,3 +346,11 @@ PROGMEM const char* const custom_reset_string[] = { // this device should be discoberable and respond to Alexa commands. // Both ENABLE_FAUXMO and fauxmoEnabled should be 1 for Alexa support to work. #define FAUXMO_ENABLED 1 + + +// ----------------------------------------------------------------------------- +// RFBRIDGE +// ----------------------------------------------------------------------------- + +#define RF_SEND_TIMES 4 // How many times to send the message +#define RF_SEND_DELAY 250 // Interval between sendings in ms diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 4990092d..f7f50f4b 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -236,6 +236,7 @@ #undef RELAY_PROVIDER #define RELAY_PROVIDER RELAY_PROVIDER_RFBRIDGE #define DUMMY_RELAY_COUNT 4 + #define TRACK_RELAY_STATUS 0 // ----------------------------------------------------------------------------- // Electrodragon boards @@ -520,6 +521,11 @@ #define BUTTON_SET_PULLUP 4 #endif +// Does the board track the relay status? +#ifndef TRACK_RELAY_STATUS +#define TRACK_RELAY_STATUS 1 +#endif + // Relay providers #ifndef RELAY_PROVIDER #define RELAY_PROVIDER RELAY_PROVIDER_RELAY diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index a8c257f8..c93f955e 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -165,7 +165,9 @@ bool relayStatus(unsigned char id, bool status, bool report) { bool changed = false; - //if (relayStatus(id) != status) { + #if TRACK_RELAY_STATUS + if (relayStatus(id) != status) { + #endif unsigned int floodWindowEnd = _relays[id].floodWindowStart + 1000 * RELAY_FLOOD_WINDOW; unsigned int currentTime = millis(); @@ -190,7 +192,9 @@ bool relayStatus(unsigned char id, bool status, bool report) { changed = true; - //} + #if TRACK_RELAY_STATUS + } + #endif return changed; } @@ -521,8 +525,11 @@ void relayLoop(void) { unsigned int currentTime = millis(); bool status = _relays[id].scheduledStatus; - //if (relayStatus(id) != status && currentTime >= _relays[id].scheduledStatusTime) { + #if TRACK_RELAY_STATUS + if (relayStatus(id) != status && currentTime >= _relays[id].scheduledStatusTime) { + #else if (_relays[id].scheduled && currentTime >= _relays[id].scheduledStatusTime) { + #endif DEBUG_MSG_P(PSTR("[RELAY] %d => %s\n"), id, status ? "ON" : "OFF"); diff --git a/code/espurna/rfbridge.ino b/code/espurna/rfbridge.ino index d05bd96d..d40cdbc1 100644 --- a/code/espurna/rfbridge.ino +++ b/code/espurna/rfbridge.ino @@ -8,9 +8,11 @@ Copyright (C) 2017 by Xose Pérez #ifdef SONOFF_RFBRIDGE +// ----------------------------------------------------------------------------- +// DEFINITIONS +// ----------------------------------------------------------------------------- + #define RF_MESSAGE_SIZE 9 -#define RF_SEND_TIMES 3 -#define RF_SEND_DELAY 50 #define RF_CODE_START 0xAA #define RF_CODE_ACK 0xA0 #define RF_CODE_LEARN 0xA1 @@ -20,6 +22,10 @@ Copyright (C) 2017 by Xose Pérez #define RF_CODE_RFOUT 0xA5 #define RF_CODE_STOP 0x55 +// ----------------------------------------------------------------------------- +// GLOBALS TO THE MODULE +// ----------------------------------------------------------------------------- + unsigned char _uartbuf[RF_MESSAGE_SIZE+3] = {0}; unsigned char _uartpos = 0; unsigned char _learnId = 0; @@ -31,21 +37,26 @@ bool _learnState = true; void _rfbAck() { DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending ACK\n")); + Serial.println(); Serial.write(RF_CODE_START); Serial.write(RF_CODE_ACK); Serial.write(RF_CODE_STOP); Serial.flush(); + Serial.println(); } void _rfbLearn() { DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending LEARN\n")); + Serial.println(); Serial.write(RF_CODE_START); Serial.write(RF_CODE_LEARN); Serial.write(RF_CODE_STOP); Serial.flush(); + Serial.println(); } void _rfbSend(byte * message) { + Serial.println(); Serial.write(RF_CODE_START); Serial.write(RF_CODE_RFOUT); for (unsigned char j=0; j