Browse Source

Enable serial debug on Sonoff RFBridge

fastled
Xose Pérez 7 years ago
parent
commit
3b385ad6b9
5 changed files with 41 additions and 8 deletions
  1. +1
    -1
      code/espurna/config/debug.h
  2. +10
    -2
      code/espurna/config/general.h
  3. +6
    -0
      code/espurna/config/hardware.h
  4. +10
    -3
      code/espurna/relay.ino
  5. +14
    -2
      code/espurna/rfbridge.ino

+ 1
- 1
code/espurna/config/debug.h View File

@ -1,6 +1,6 @@
#define DEBUG_MESSAGE_MAX_LENGTH 80 #define DEBUG_MESSAGE_MAX_LENGTH 80
#if defined(SONOFF_DUAL) | defined(SONOFF_RFBRIDGE)
#if defined(SONOFF_DUAL)
#undef DEBUG_PORT #undef DEBUG_PORT
#endif #endif


+ 10
- 2
code/espurna/config/general.h View File

@ -23,8 +23,8 @@
// To receive the message son the destination computer use nc: // To receive the message son the destination computer use nc:
// nc -ul 8111 // 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 // EEPROM
@ -346,3 +346,11 @@ PROGMEM const char* const custom_reset_string[] = {
// this device should be discoberable and respond to Alexa commands. // this device should be discoberable and respond to Alexa commands.
// Both ENABLE_FAUXMO and fauxmoEnabled should be 1 for Alexa support to work. // Both ENABLE_FAUXMO and fauxmoEnabled should be 1 for Alexa support to work.
#define FAUXMO_ENABLED 1 #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

+ 6
- 0
code/espurna/config/hardware.h View File

@ -236,6 +236,7 @@
#undef RELAY_PROVIDER #undef RELAY_PROVIDER
#define RELAY_PROVIDER RELAY_PROVIDER_RFBRIDGE #define RELAY_PROVIDER RELAY_PROVIDER_RFBRIDGE
#define DUMMY_RELAY_COUNT 4 #define DUMMY_RELAY_COUNT 4
#define TRACK_RELAY_STATUS 0
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Electrodragon boards // Electrodragon boards
@ -520,6 +521,11 @@
#define BUTTON_SET_PULLUP 4 #define BUTTON_SET_PULLUP 4
#endif #endif
// Does the board track the relay status?
#ifndef TRACK_RELAY_STATUS
#define TRACK_RELAY_STATUS 1
#endif
// Relay providers // Relay providers
#ifndef RELAY_PROVIDER #ifndef RELAY_PROVIDER
#define RELAY_PROVIDER RELAY_PROVIDER_RELAY #define RELAY_PROVIDER RELAY_PROVIDER_RELAY


+ 10
- 3
code/espurna/relay.ino View File

@ -165,7 +165,9 @@ bool relayStatus(unsigned char id, bool status, bool report) {
bool changed = false; 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 floodWindowEnd = _relays[id].floodWindowStart + 1000 * RELAY_FLOOD_WINDOW;
unsigned int currentTime = millis(); unsigned int currentTime = millis();
@ -190,7 +192,9 @@ bool relayStatus(unsigned char id, bool status, bool report) {
changed = true; changed = true;
//}
#if TRACK_RELAY_STATUS
}
#endif
return changed; return changed;
} }
@ -521,8 +525,11 @@ void relayLoop(void) {
unsigned int currentTime = millis(); unsigned int currentTime = millis();
bool status = _relays[id].scheduledStatus; 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) { if (_relays[id].scheduled && currentTime >= _relays[id].scheduledStatusTime) {
#endif
DEBUG_MSG_P(PSTR("[RELAY] %d => %s\n"), id, status ? "ON" : "OFF"); DEBUG_MSG_P(PSTR("[RELAY] %d => %s\n"), id, status ? "ON" : "OFF");


+ 14
- 2
code/espurna/rfbridge.ino View File

@ -8,9 +8,11 @@ Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com>
#ifdef SONOFF_RFBRIDGE #ifdef SONOFF_RFBRIDGE
// -----------------------------------------------------------------------------
// DEFINITIONS
// -----------------------------------------------------------------------------
#define RF_MESSAGE_SIZE 9 #define RF_MESSAGE_SIZE 9
#define RF_SEND_TIMES 3
#define RF_SEND_DELAY 50
#define RF_CODE_START 0xAA #define RF_CODE_START 0xAA
#define RF_CODE_ACK 0xA0 #define RF_CODE_ACK 0xA0
#define RF_CODE_LEARN 0xA1 #define RF_CODE_LEARN 0xA1
@ -20,6 +22,10 @@ Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com>
#define RF_CODE_RFOUT 0xA5 #define RF_CODE_RFOUT 0xA5
#define RF_CODE_STOP 0x55 #define RF_CODE_STOP 0x55
// -----------------------------------------------------------------------------
// GLOBALS TO THE MODULE
// -----------------------------------------------------------------------------
unsigned char _uartbuf[RF_MESSAGE_SIZE+3] = {0}; unsigned char _uartbuf[RF_MESSAGE_SIZE+3] = {0};
unsigned char _uartpos = 0; unsigned char _uartpos = 0;
unsigned char _learnId = 0; unsigned char _learnId = 0;
@ -31,21 +37,26 @@ bool _learnState = true;
void _rfbAck() { void _rfbAck() {
DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending ACK\n")); DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending ACK\n"));
Serial.println();
Serial.write(RF_CODE_START); Serial.write(RF_CODE_START);
Serial.write(RF_CODE_ACK); Serial.write(RF_CODE_ACK);
Serial.write(RF_CODE_STOP); Serial.write(RF_CODE_STOP);
Serial.flush(); Serial.flush();
Serial.println();
} }
void _rfbLearn() { void _rfbLearn() {
DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending LEARN\n")); DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending LEARN\n"));
Serial.println();
Serial.write(RF_CODE_START); Serial.write(RF_CODE_START);
Serial.write(RF_CODE_LEARN); Serial.write(RF_CODE_LEARN);
Serial.write(RF_CODE_STOP); Serial.write(RF_CODE_STOP);
Serial.flush(); Serial.flush();
Serial.println();
} }
void _rfbSend(byte * message) { void _rfbSend(byte * message) {
Serial.println();
Serial.write(RF_CODE_START); Serial.write(RF_CODE_START);
Serial.write(RF_CODE_RFOUT); Serial.write(RF_CODE_RFOUT);
for (unsigned char j=0; j<RF_MESSAGE_SIZE; j++) { for (unsigned char j=0; j<RF_MESSAGE_SIZE; j++) {
@ -53,6 +64,7 @@ void _rfbSend(byte * message) {
} }
Serial.write(RF_CODE_STOP); Serial.write(RF_CODE_STOP);
Serial.flush(); Serial.flush();
Serial.println();
} }
void _rfbSend(byte * message, int times) { void _rfbSend(byte * message, int times) {


Loading…
Cancel
Save