From 25ccfdd6e4651a5cdfbf61bc35887553b616ce98 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Wed, 22 Apr 2020 12:53:37 +0200 Subject: [PATCH 01/46] TX part first try This is Beta! Receive command from Serial Answer it over Serial & MQTT --- RFLink/3_Serial.cpp | 289 +++++++++++++++++++++++++++++--------------- RFLink/3_Serial.h | 4 +- RFLink/RFLink.h | 2 + RFLink/RFLink.ino | 16 ++- 4 files changed, 208 insertions(+), 103 deletions(-) diff --git a/RFLink/3_Serial.cpp b/RFLink/3_Serial.cpp index 6540f87c..69cdacff 100644 --- a/RFLink/3_Serial.cpp +++ b/RFLink/3_Serial.cpp @@ -6,120 +6,209 @@ // ************************************* // #include -// #include "3_Serial.h" +#include "RFLink.h" +#include "3_Serial.h" +#include "4_Display.h" +#include "5_Plugin.h" -//char InputBuffer_Serial[INPUT_COMMAND_SIZE]; +char InputBuffer_Serial[INPUT_COMMAND_SIZE]; +boolean ReadSerial(); +boolean CheckCmd(); /*********************************************************************************************/ -/* + boolean CheckSerial() { - static byte SerialInByte = 0; // incoming character value - static int SerialInByteCounter = 0; // number of bytes counter - static byte ValidCommand = 0; - static unsigned long FocusTimer; // Timer to keep focus on the task during communication - - InputBuffer_Serial[0] = 0; // erase serial buffer string + if (ReadSerial()) + if (CheckCmd()) + return true; + return false; +} +boolean ReadSerial() +{ // SERIAL: *************** Check if there is data ready on the serial port ********************** - if (Serial.available()) { - FocusTimer = millis() + FOCUS_TIME_MS; + static byte SerialInByte; // incoming character value + static byte SerialInByteCounter; // number of bytes counter + static unsigned long FocusTimer; // Timer to keep focus on the task during communication + + if (Serial.available()) + { + SerialInByteCounter = 0; - while (millis() < FocusTimer) { // standby - if (Serial.available()) { + FocusTimer = millis() + FOCUS_TIME_MS; + while (true) + { + if (Serial.available()) + { SerialInByte = Serial.read(); if (isprint(SerialInByte)) - if (SerialInByteCounter < (INPUT_COMMAND_SIZE - 1)) - InputBuffer_Serial[SerialInByteCounter++] = SerialInByte; + InputBuffer_Serial[SerialInByteCounter++] = SerialInByte; + + FocusTimer = millis() + FOCUS_TIME_MS; + } + + if ((SerialInByte == '\n') || (millis() >= FocusTimer) || (SerialInByteCounter >= (INPUT_COMMAND_SIZE - 1))) + // new line character or timeout or buffer full + { + // if (InputBuffer_Serial[SerialInByteCounter - 1] == ';') + // InputBuffer_Serial[SerialInByteCounter - 1] = 0; // remove last ";" char + // else + InputBuffer_Serial[SerialInByteCounter] = 0; // serial data is complete + return true; + } + } + } + return false; +} - if (SerialInByte == '\n') { // new line character - InputBuffer_Serial[SerialInByteCounter] = 0; // serieel data is complete - //Serial.print("20;incoming;"); - //Serial.println(InputBuffer_Serial); - if (strlen(InputBuffer_Serial) > 7) { // need to see minimal 8 characters on the serial port - // 10;....;..;ON; - if (strncmp (InputBuffer_Serial, "10;", 3) == 0) { // Command from Master to RFLink - // ------------------------------------------------------- - // Handle Device Management Commands - // ------------------------------------------------------- - if (strcasecmp(InputBuffer_Serial + 3, "PING;") == 0) { - sprintf_P(InputBuffer_Serial, PSTR("20;%02X;PONG;"), PKSequenceNumber++); - Serial.println(InputBuffer_Serial); - } else if (strcasecmp(InputBuffer_Serial + 3, "REBOOT;") == 0) { - strcpy(InputBuffer_Serial, "reboot"); - // Reboot(); - } else if (strncasecmp(InputBuffer_Serial + 3, "RFDEBUG=O", 9) == 0) { - if (InputBuffer_Serial[12] == 'N' || InputBuffer_Serial[12] == 'n' ) { - RFDebug = true; // full debug on - RFUDebug = false; // undecoded debug off - QRFDebug = false; // undecoded debug off - sprintf_P(InputBuffer_Serial, PSTR("20;%02X;RFDEBUG=ON;"), PKSequenceNumber++); - } else { - RFDebug = false; // full debug off - sprintf_P(InputBuffer_Serial, PSTR("20;%02X;RFDEBUG=OFF;"), PKSequenceNumber++); - } - Serial.println(InputBuffer_Serial); - } else if (strncasecmp(InputBuffer_Serial + 3, "RFUDEBUG=O", 10) == 0) { - if (InputBuffer_Serial[13] == 'N' || InputBuffer_Serial[13] == 'n') { - RFUDebug = true; // undecoded debug on - QRFDebug = false; // undecoded debug off - RFDebug = false; // full debug off - sprintf_P(InputBuffer_Serial, PSTR("20;%02X;RFUDEBUG=ON;"), PKSequenceNumber++); - } else { - RFUDebug = false; // undecoded debug off - sprintf_P(InputBuffer_Serial, PSTR("20;%02X;RFUDEBUG=OFF;"), PKSequenceNumber++); - } - Serial.println(InputBuffer_Serial); - } else if (strncasecmp(InputBuffer_Serial + 3, "QRFDEBUG=O", 10) == 0) { - if (InputBuffer_Serial[13] == 'N' || InputBuffer_Serial[13] == 'n') { - QRFDebug = true; // undecoded debug on - RFUDebug = false; // undecoded debug off - RFDebug = false; // full debug off - sprintf_P(InputBuffer_Serial, PSTR("20;%02X;QRFDEBUG=ON;"), PKSequenceNumber++); - } else { - QRFDebug = false; // undecoded debug off - sprintf_P(InputBuffer_Serial, PSTR("20;%02X;QRFDEBUG=OFF;"), PKSequenceNumber++); - } - Serial.println(InputBuffer_Serial); - } else if (strncasecmp(InputBuffer_Serial + 3, "VERSION", 7) == 0) { - sprintf_P(InputBuffer_Serial, PSTR("20;%02X;VER=1.1;REV=%02x;BUILD=%02x;"), PKSequenceNumber++, REVNR, BUILDNR); - Serial.println(InputBuffer_Serial); - } else { - // ------------------------------------------------------- - // Handle Generic Commands / Translate protocol data into Nodo text commands - // ------------------------------------------------------- - // check plugins - if (InputBuffer_Serial[SerialInByteCounter - 1] == ';') InputBuffer_Serial[SerialInByteCounter - 1] = 0; // remove last ";" char - if (PluginTXCall(0, InputBuffer_Serial)) { - ValidCommand = 1; - } else { - // Answer that an invalid command was received? - ValidCommand = 2; - } - } - } - } // if > 7 - if (ValidCommand != 0) { - if (ValidCommand == 1) { - sprintf_P(InputBuffer_Serial, PSTR("20;%02X;OK;"), PKSequenceNumber++); - Serial.println( InputBuffer_Serial ); - } else { - sprintf_P(InputBuffer_Serial, PSTR("20;%02X;CMD UNKNOWN;"), PKSequenceNumber++); // Node and packet number - Serial.println( InputBuffer_Serial ); - } - } - SerialInByteCounter = 0; - InputBuffer_Serial[0] = 0; // serial data has been processed. - ValidCommand = 0; - FocusTimer = millis() + FOCUS_TIME_MS; - }// if(SerialInByte - }// if(Serial.available()) - }// while - }// if(Serial.available()) +boolean CheckCmd() +{ + static byte ValidCommand = 0; + if (strlen(InputBuffer_Serial) > 7) + { // need to see minimal 8 characters on the serial port + // 10;....;..;ON; + if (strncmp(InputBuffer_Serial, "10;", 3) == 0) + { // Command from Master to RFLink + // ------------------------------------------------------- + // Handle Device Management Commands + // ------------------------------------------------------- + if (strcasecmp(InputBuffer_Serial + 3, "PING;") == 0) + { + display_Header(); + display_Name(PSTR("PONG")); + display_Footer(); + } + else if (strcasecmp(InputBuffer_Serial + 3, "REBOOT;") == 0) + { + display_Header(); + display_Name(PSTR("REBOOT")); + display_Footer(); + CallReboot(); + } + else if (strncasecmp(InputBuffer_Serial + 3, "RFDEBUG=O", 9) == 0) + { + if (InputBuffer_Serial[12] == 'N' || InputBuffer_Serial[12] == 'n') + { + RFDebug = true; // full debug on + QRFDebug = false; // q full debug off + RFUDebug = false; // undecoded debug off + QRFUDebug = false; // q undecoded debug off + display_Header(); + display_Name(PSTR("RFDEBUG=ON")); + display_Footer(); + } + else + { + RFDebug = false; // full debug off + display_Header(); + display_Name(PSTR("RFDEBUG=OFF")); + display_Footer(); + } + } + else if (strncasecmp(InputBuffer_Serial + 3, "RFUDEBUG=O", 10) == 0) + { + if (InputBuffer_Serial[13] == 'N' || InputBuffer_Serial[13] == 'n') + { + RFDebug = false; // full debug off + QRFDebug = false; // q debug off + RFUDebug = true; // undecoded debug on + QRFUDebug = false; // q undecoded debug off + display_Header(); + display_Name(PSTR("RFUDEBUG=ON")); + display_Footer(); + } + else + { + RFUDebug = false; // undecoded debug off + display_Header(); + display_Name(PSTR("RFUDEBUG=OFF")); + display_Footer(); + } + } + else if (strncasecmp(InputBuffer_Serial + 3, "QRFDEBUG=O", 10) == 0) + { + if (InputBuffer_Serial[13] == 'N' || InputBuffer_Serial[13] == 'n') + { + RFDebug = false; // full debug off + QRFDebug = true; // q debug on + RFUDebug = false; // undecoded debug off + QRFUDebug = false; // q undecoded debug off + display_Header(); + display_Name(PSTR("QRFDEBUG=ON")); + display_Footer(); + } + else + { + QRFDebug = false; // q debug off + display_Header(); + display_Name(PSTR("QRFDEBUG=OFF")); + display_Footer(); + } + } + else if (strncasecmp(InputBuffer_Serial + 3, "QRFUDEBUG=O", 11) == 0) + { + if (InputBuffer_Serial[13] == 'N' || InputBuffer_Serial[13] == 'n') + { + RFDebug = false; // full debug off + QRFDebug = false; // q debug off + RFUDebug = false; // undecoded debug off + QRFUDebug = true; // q undecoded debug on + display_Header(); + display_Name(PSTR("QRFUDEBUG=ON")); + display_Footer(); + } + else + { + QRFUDebug = false; // q undecode debug off + display_Header(); + display_Name(PSTR("QRFUDEBUG=OFF")); + display_Footer(); + } + } + else if (strncasecmp(InputBuffer_Serial + 3, "VERSION", 7) == 0) + { + display_Header(); + display_Splash(); + display_Footer(); + } + else + { + // ------------------------------------------------------- + // Handle Generic Commands / Translate protocol data into Nodo text commands + // ------------------------------------------------------- + // if (PluginTXCall(0, InputBuffer_Serial)) + // { + // ValidCommand = 1; + // } + // else + // { + // Answer that an invalid command was received? + ValidCommand = 2; + //} + } + } + } // if > 7 + if (ValidCommand != 0) + { + if (ValidCommand == 1) + { + display_Header(); + display_Name(PSTR("OK")); + display_Footer(); + } + else + { + display_Header(); + display_Name(PSTR("CMD UNKNOWN")); + display_Footer(); + } + } + InputBuffer_Serial[0] = 0; // serial data has been processed. + ValidCommand = 0; return true; } -*/ /*********************************************************************************************/ diff --git a/RFLink/3_Serial.h b/RFLink/3_Serial.h index 03c46be3..f53c1edc 100644 --- a/RFLink/3_Serial.h +++ b/RFLink/3_Serial.h @@ -11,7 +11,7 @@ #include #include "RFLink.h" -//extern char InputBuffer_Serial[INPUT_COMMAND_SIZE]; // Buffer for Seriel data -// boolean CheckSerial(); +// extern char InputBuffer_Serial[INPUT_COMMAND_SIZE]; // Buffer for Seriel data +boolean CheckSerial(); #endif \ No newline at end of file diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 30be1c48..84e1230a 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -105,4 +105,6 @@ #define RFUDebug_0 false // debug RF signals with plugin 254 (decode 1st) #define QRFUDebug_0 false // debug RF signals with plugin 254 but no multiplication (faster?, compact) +void CallReboot(void); + #endif \ No newline at end of file diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index a123bb9e..ec4624c3 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -19,6 +19,7 @@ #include #include "RFLink.h" #include "2_Signal.h" +#include "3_Serial.h" #include "4_Display.h" #include "5_Plugin.h" #if (defined(__AVR_ATmega328P__) || defined(__AVR_ATmega2560__)) @@ -31,11 +32,20 @@ #endif //**************************************************************************************************************************************** +void sendMsg(); // See at bottom + #if (defined(__AVR_ATmega328P__) || defined(__AVR_ATmega2560__)) void (*Reboot)(void) = 0; // reset function on adress 0. #endif -void sendMsg(); // See at bottom +#if (defined(ESP8266) || defined(ESP32)) +void CallReboot(void) +{ + sendMsg(); + delay(1); + ESP.restart(); +} +#endif void setup() { @@ -105,6 +115,10 @@ void loop() #ifdef MQTT_ENABLED checkMQTTloop(); #endif + + if (CheckSerial()) + sendMsg(); + if (ScanEvent()) sendMsg(); } From 9a5330025f80be994bb7d68c795a3f27b04f2409 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Wed, 22 Apr 2020 16:16:17 +0200 Subject: [PATCH 02/46] Arduino Mega #define Typo --- RFLink/RFLink.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 96fed229..e7e22e62 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -73,8 +73,8 @@ #ifdef __AVR_ATmega2560__ #define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin #define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA D1 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_RX_GND 19 // Ground to the receiver on this pin +#define PIN_RF_RX_DATA 19 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin #endif // OLED display, 0.91" SSD1306 I2C From 1a28f16fdee2e71700173b9a8fd8505a8c3b154e Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Thu, 23 Apr 2020 01:12:28 +0200 Subject: [PATCH 03/46] ReActivate Callback and MQTT Command Can now received MQTT command --- RFLink/3_Serial.cpp | 24 ++++++++++++++++++++++++ RFLink/3_Serial.h | 2 +- RFLink/6_WiFi_MQTT.cpp | 33 ++++++++++++++------------------- RFLink/RFLink.h | 2 +- RFLink/RFLink.ino | 1 + 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/RFLink/3_Serial.cpp b/RFLink/3_Serial.cpp index 69cdacff..afe1ac75 100644 --- a/RFLink/3_Serial.cpp +++ b/RFLink/3_Serial.cpp @@ -15,16 +15,40 @@ char InputBuffer_Serial[INPUT_COMMAND_SIZE]; boolean ReadSerial(); boolean CheckCmd(); +boolean CopySerial(char *); /*********************************************************************************************/ boolean CheckSerial() { if (ReadSerial()) + { + Serial.flush(); + Serial.print(F("Message arrived [Serial] ")); + Serial.println(InputBuffer_Serial); if (CheckCmd()) return true; + } return false; } +boolean CheckMQTT(byte *mqtt_in) +{ + if (CopySerial((char *)mqtt_in)) + { + Serial.flush(); + Serial.print(F("Message arrived [MQTT] ")); + Serial.println(InputBuffer_Serial); + if (CheckCmd()) + return true; + } + return false; +} + +boolean CopySerial(char *src) +{ + return (strncpy(InputBuffer_Serial, src, INPUT_COMMAND_SIZE - 2)); +} + boolean ReadSerial() { // SERIAL: *************** Check if there is data ready on the serial port ********************** diff --git a/RFLink/3_Serial.h b/RFLink/3_Serial.h index f53c1edc..3270cf47 100644 --- a/RFLink/3_Serial.h +++ b/RFLink/3_Serial.h @@ -11,7 +11,7 @@ #include #include "RFLink.h" -// extern char InputBuffer_Serial[INPUT_COMMAND_SIZE]; // Buffer for Seriel data boolean CheckSerial(); +boolean CheckMQTT(byte *); #endif \ No newline at end of file diff --git a/RFLink/6_WiFi_MQTT.cpp b/RFLink/6_WiFi_MQTT.cpp index a220742f..d685a568 100644 --- a/RFLink/6_WiFi_MQTT.cpp +++ b/RFLink/6_WiFi_MQTT.cpp @@ -7,7 +7,7 @@ #include #include "RFLink.h" - +#include "3_Serial.h" #include "4_Display.h" #include "6_WiFi_MQTT.h" @@ -33,6 +33,8 @@ WiFiClient WIFIClient; PubSubClient MQTTClient; // MQTTClient(WIFIClient); +void callback(char *, byte *, unsigned int); + void setup_WIFI() { WiFi.persistent(false); @@ -68,21 +70,14 @@ void setup_MQTT() { MQTTClient.setClient(WIFIClient); MQTTClient.setServer(MQTT_SERVER.c_str(), MQTT_PORT.toInt()); - // MQTTClient.setCallback(callback); + MQTTClient.setCallback(callback); } -/* - void callback(char* topic, byte* payload, unsigned int length) { - Serial.print(F("Message arrived [")); - Serial.print(topic); - Serial.print("] "); - for (unsigned int i = 0; i < length; i++) { - Serial.write(payload[i]); - } - Serial.write('\n'); - Serial.println(); - } -*/ +void callback(char *topic, byte *payload, unsigned int length) +{ + payload[length] = 0; + CheckMQTT(payload); +} void reconnect() { @@ -96,7 +91,7 @@ void reconnect() { Serial.println(F("Connected")); // Once connected, resubscribe - // MQTTClient.subscribe(MQTT_TOPIC_IN.c_str()); + MQTTClient.subscribe(MQTT_TOPIC_IN.c_str()); } else { @@ -143,13 +138,13 @@ void setup_WIFI_OFF() { WiFi.persistent(false); WiFi.setAutoReconnect(false); - #ifdef ESP8266 +#ifdef ESP8266 WiFi.setSleepMode(WIFI_MODEM_SLEEP); - #endif +#endif WiFi.mode(WIFI_OFF); - #ifdef ESP8266 +#ifdef ESP8266 WiFi.forceSleepBegin(); - #endif +#endif } #endif // (defined(ESP32) || defined(ESP8266)) #endif // MQTT_ENABLED \ No newline at end of file diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index e7e22e62..e3801f7a 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -95,7 +95,7 @@ #define SERIAL_ENABLED // Send RFLink messages over Serial #if (defined(ESP32) || defined(ESP8266)) #define MQTT_ENABLED // Send RFLink messages over MQTT -#define MQTT_LOOP_MS 7500 // MQTTClient.loop(); call period (in mSec) +#define MQTT_LOOP_MS 1000 // MQTTClient.loop(); call period (in mSec) #define MQTT_RETAINED false // Retained option #endif diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index ec4624c3..5e956cf5 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -114,6 +114,7 @@ void loop() { #ifdef MQTT_ENABLED checkMQTTloop(); + sendMsg(); #endif if (CheckSerial()) From f5007631ec4741e2e9573dc10c0aad18d5404756 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Fri, 24 Apr 2020 11:40:10 +0200 Subject: [PATCH 04/46] enable/disable RX/TX func --- RFLink/3_Serial.cpp | 6 +++++ RFLink/RFLink.h | 53 ++++++++++++++++++++++++-------------- RFLink/RFLink.ino | 63 +++++++++++++++++++++++++++++++-------------- 3 files changed, 83 insertions(+), 39 deletions(-) diff --git a/RFLink/3_Serial.cpp b/RFLink/3_Serial.cpp index afe1ac75..c9d63e21 100644 --- a/RFLink/3_Serial.cpp +++ b/RFLink/3_Serial.cpp @@ -212,6 +212,12 @@ boolean CheckCmd() // Answer that an invalid command was received? ValidCommand = 2; //} + disableRX(); + enableTX(); + + + disableTX(); + enableRX(); } } } // if > 7 diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index e3801f7a..9e8c2402 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -44,37 +44,46 @@ */ // PIN Definition -#define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin -#define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin -#define PIN_RF_TX_DATA NOT_A_PIN // Data to the 433Mhz transmitter on this pin - +// #ifdef ESP8266 // ESP8266 D1 Mini -#define PIN_RF_RX_VCC D5 // Power to the receiver on this pin -#define PIN_RF_RX_NA D6 // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA D7 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_RX_GND D8 // Ground to the receiver on this pin +#define PIN_RF_RX_VCC D7 // Power to the receiver on this pin +#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_DATA D2 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_RX_GND D8 // Ground to the receiver on this pin +#define PIN_RF_TX_VCC D5 // +5 volt / Vcc power to the transmitter on this pin +#define PIN_RF_TX_GND D6 // Ground power to the transmitter on this pin +#define PIN_RF_TX_DATA D1 // Data to the 433Mhz transmitter on this pin #endif #ifdef ESP32 -#define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin -#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA 2 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin +#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_DATA 2 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin +#define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin +#define PIN_RF_TX_DATA NOT_A_PIN // Data to the 433Mhz transmitter on this pin #endif #ifdef __AVR_ATmega328P__ -#define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin -#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA 2 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin +#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_DATA 2 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin +#define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin +#define PIN_RF_TX_DATA NOT_A_PIN // Data to the 433Mhz transmitter on this pin #endif #ifdef __AVR_ATmega2560__ -#define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin -#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA 19 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin +#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_DATA 19 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin +#define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin +#define PIN_RF_TX_DATA NOT_A_PIN // Data to the 433Mhz transmitter on this pin #endif // OLED display, 0.91" SSD1306 I2C @@ -106,5 +115,9 @@ #define QRFUDebug_0 false // debug RF signals with plugin 254 but no multiplication (faster?, compact) void CallReboot(void); +void enableRX(); +void disableRX(); +void enableTX(); +void disableTX(); #endif \ No newline at end of file diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index 5e956cf5..a8f9b47c 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -31,7 +31,6 @@ #include "8_OLED.h" #endif //**************************************************************************************************************************************** - void sendMsg(); // See at bottom #if (defined(__AVR_ATmega328P__) || defined(__AVR_ATmega2560__)) @@ -61,24 +60,8 @@ void setup() Serial.begin(BAUD); // Initialise the serial port Serial.println(); // ESP "Garbage" message - // RX pins - pinMode(PIN_RF_RX_VCC, OUTPUT); // Initialise in/output ports - pinMode(PIN_RF_RX_NA, INPUT); // Initialise in/output ports - pinMode(PIN_RF_RX_DATA, INPUT); // Initialise in/output ports - pinMode(PIN_RF_RX_GND, OUTPUT); // Initialise in/output ports - digitalWrite(PIN_RF_RX_GND, LOW); // turn GND to RF receiver ON - digitalWrite(PIN_RF_RX_VCC, HIGH); // turn VCC to RF receiver ON - digitalWrite(PIN_RF_RX_DATA, INPUT_PULLUP); // pull-up resistor on (to prevent garbage) - - // TX Pins - // pinMode(PIN_RF_TX_VCC, OUTPUT); // Initialise in/output ports - // pinMode(PIN_RF_TX_DATA, OUTPUT); // Initialise in/output ports - // pinMode(PIN_RF_TX_GND, OUTPUT); // Initialise in/output ports - // digitalWrite(PIN_RF_TX_GND, LOW); // turn GND to TX receiver ON - // digitalWrite(PIN_RF_TX_VCC, HIGH); // turn VCC to TX receiver ON - //delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); - - delay(100); + disableTX(); + enableRX(); #if (defined(ESP32) || defined(ESP8266)) #ifdef MQTT_ENABLED @@ -107,6 +90,7 @@ void setup() pbuffer[0] = 0; PluginInit(); + PluginTXInit(); delay(100); } @@ -140,4 +124,45 @@ void sendMsg() pbuffer[0] = 0; } } + +void enableRX() +{ + // RX pins + pinMode(PIN_RF_RX_GND, OUTPUT); // Initialise in/output ports + pinMode(PIN_RF_RX_VCC, OUTPUT); // Initialise in/output ports + pinMode(PIN_RF_RX_NA, INPUT); // Initialise in/output ports + pinMode(PIN_RF_RX_DATA, INPUT); // Initialise in/output ports + digitalWrite(PIN_RF_RX_GND, LOW); // turn GND to RF receiver ON + digitalWrite(PIN_RF_RX_VCC, HIGH); // turn VCC to RF receiver ON + pinMode(PIN_RF_RX_DATA, INPUT_PULLUP); // Initialise in/output ports +} + +void disableRX() +{ + // RX pins + pinMode(PIN_RF_RX_DATA, INPUT); + pinMode(PIN_RF_RX_NA, INPUT); + pinMode(PIN_RF_RX_VCC, INPUT); + pinMode(PIN_RF_RX_GND, INPUT); +} + +void enableTX() +{ + // TX Pins + pinMode(PIN_RF_TX_GND, OUTPUT); // Initialise in/output ports + pinMode(PIN_RF_TX_VCC, OUTPUT); // Initialise in/output ports + pinMode(PIN_RF_TX_DATA, OUTPUT); // Initialise in/output ports + digitalWrite(PIN_RF_TX_GND, LOW); // turn GND to TX receiver ON + digitalWrite(PIN_RF_TX_VCC, HIGH); // turn VCC to TX receiver ON + delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); +} + +void disableTX() +{ + // TX Pins + pinMode(PIN_RF_TX_DATA, INPUT); + pinMode(PIN_RF_TX_VCC, INPUT); + pinMode(PIN_RF_TX_GND, INPUT); +} + /*********************************************************************************************/ From 5b870781fd2a12b747a8b1370d3b276d728b4140 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Fri, 24 Apr 2020 11:41:59 +0200 Subject: [PATCH 05/46] Bring back PluginTXCall --- RFLink/3_Serial.cpp | 13 +- RFLink/5_Plugin.cpp | 1014 ++++++++++++++++++++++++------------------- RFLink/5_Plugin.h | 14 +- 3 files changed, 575 insertions(+), 466 deletions(-) diff --git a/RFLink/3_Serial.cpp b/RFLink/3_Serial.cpp index c9d63e21..dd1a590f 100644 --- a/RFLink/3_Serial.cpp +++ b/RFLink/3_Serial.cpp @@ -203,18 +203,13 @@ boolean CheckCmd() // Handle Generic Commands / Translate protocol data into Nodo text commands // ------------------------------------------------------- - // if (PluginTXCall(0, InputBuffer_Serial)) - // { - // ValidCommand = 1; - // } - // else - // { - // Answer that an invalid command was received? - ValidCommand = 2; - //} disableRX(); enableTX(); + if (PluginTXCall(0, InputBuffer_Serial)) + ValidCommand = 1; + else // Answer that an invalid command was received? + ValidCommand = 2; disableTX(); enableRX(); diff --git a/RFLink/5_Plugin.cpp b/RFLink/5_Plugin.cpp index f0878e9d..6db99636 100644 --- a/RFLink/5_Plugin.cpp +++ b/RFLink/5_Plugin.cpp @@ -14,6 +14,10 @@ boolean (*Plugin_ptr[PLUGIN_MAX])(byte, char *); // Receive plugins byte Plugin_id[PLUGIN_MAX]; byte Plugin_State[PLUGIN_MAX]; +boolean (*PluginTX_ptr[PLUGIN_TX_MAX])(byte, char *); // Trasmit plugins +byte PluginTX_id[PLUGIN_TX_MAX]; +byte PluginTX_State[PLUGIN_TX_MAX]; + boolean RFDebug = RFDebug_0; // debug RF signals with plugin 001 (no decode) boolean QRFDebug = QRFDebug_0; // debug RF signals with plugin 001 but no multiplication (faster?, compact) boolean RFUDebug = RFUDebug_0; // debug RF signals with plugin 254 (decode 1st) @@ -1180,449 +1184,552 @@ void PluginInit(void) PluginInitCall(0, 0); } /*********************************************************************************************/ -/* - void PluginTXInit(void) - { +void PluginTXInit(void) +{ byte x; // Wis de pointertabel voor de plugins. - for(x=0;x +enum PState {P_Forbidden, P_Disabled, P_Enabled, P_Mandatory}; + extern boolean (*Plugin_ptr[PLUGIN_MAX])(byte, char *); // Receive plugins extern byte Plugin_id[PLUGIN_MAX]; - -enum PState {P_Forbidden, P_Disabled, P_Enabled, P_Mandatory}; extern byte Plugin_State[PLUGIN_MAX]; +extern boolean (*PluginTX_ptr[PLUGIN_TX_MAX])(byte, char *); // Transmit plugins +extern byte PluginTX_id[PLUGIN_TX_MAX]; +extern byte PluginTX_State[PLUGIN_TX_MAX]; + extern boolean RFDebug; // debug RF signals with plugin 001 (no decode) extern boolean QRFDebug; // debug RF signals with plugin 001 but no multiplication (faster?, compact) extern boolean RFUDebug; // debug RF signals with plugin 254 (decode 1st) @@ -26,10 +30,10 @@ extern boolean QRFUDebug; // debug RF signals with plugin 254 but no multiplicat // Of all the devices that are compiled, the addresses are stored in a table so that you can jump to them void PluginInit(void); -// void PluginTXInit(void); +void PluginTXInit(void); byte PluginInitCall(byte Function, char *str); -// byte PluginTXInitCall(byte Function, char *str); +byte PluginTXInitCall(byte Function, char *str); byte PluginRXCall(byte Function, char *str); -// byte PluginTXCall(byte Function, char *str); +byte PluginTXCall(byte Function, char *str); #endif \ No newline at end of file From a4e833bb37ef5b81b2c0d6a88ee2b43226c72935 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Fri, 24 Apr 2020 11:45:11 +0200 Subject: [PATCH 06/46] Bring str2cmd() str2int() back --- RFLink/4_Display.cpp | 66 ++++++++++++++++++++++++++++---------------- RFLink/4_Display.h | 3 +- RFLink/RFLink.h | 2 -- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/RFLink/4_Display.cpp b/RFLink/4_Display.cpp index 18396aa0..57817475 100644 --- a/RFLink/4_Display.cpp +++ b/RFLink/4_Display.cpp @@ -336,33 +336,51 @@ void display_RGBW(unsigned int input) } /*********************************************************************************************\ - Convert string to command code + Convert HEX or DEC tring to unsigned long HEX, DEC \*********************************************************************************************/ -/* - int str2cmd(char *command) { - if (strcasecmp(command, "ON") == 0) return VALUE_ON; - if (strcasecmp(command, "OFF") == 0) return VALUE_OFF; - if (strcasecmp(command, "ALLON") == 0) return VALUE_ALLON; - if (strcasecmp(command, "ALLOFF") == 0) return VALUE_ALLOFF; - if (strcasecmp(command, "PAIR") == 0) return VALUE_PAIR; - if (strcasecmp(command, "DIM") == 0) return VALUE_DIM; - if (strcasecmp(command, "BRIGHT") == 0) return VALUE_BRIGHT; - if (strcasecmp(command, "UP") == 0) return VALUE_UP; - if (strcasecmp(command, "DOWN") == 0) return VALUE_DOWN; - if (strcasecmp(command, "STOP") == 0) return VALUE_STOP; - if (strcasecmp(command, "CONFIRM") == 0) return VALUE_CONFIRM; - if (strcasecmp(command, "LIMIT") == 0) return VALUE_LIMIT; +unsigned long str2int(char *string) +{ + return (strtoul(string, NULL, 0)); +} +/*********************************************************************************************\ + Convert string to command code +\*********************************************************************************************/ +int str2cmd(char *command) +{ + if (strcasecmp(command, "ON") == 0) + return VALUE_ON; + if (strcasecmp(command, "OFF") == 0) + return VALUE_OFF; + if (strcasecmp(command, "ALLON") == 0) + return VALUE_ALLON; + if (strcasecmp(command, "ALLOFF") == 0) + return VALUE_ALLOFF; + if (strcasecmp(command, "PAIR") == 0) + return VALUE_PAIR; + if (strcasecmp(command, "DIM") == 0) + return VALUE_DIM; + if (strcasecmp(command, "BRIGHT") == 0) + return VALUE_BRIGHT; + if (strcasecmp(command, "UP") == 0) + return VALUE_UP; + if (strcasecmp(command, "DOWN") == 0) + return VALUE_DOWN; + if (strcasecmp(command, "STOP") == 0) + return VALUE_STOP; + if (strcasecmp(command, "CONFIRM") == 0) + return VALUE_CONFIRM; + if (strcasecmp(command, "LIMIT") == 0) + return VALUE_LIMIT; return false; - } -*/ +} void replacechar(char *str, char orig, char rep) { - char *ix = str; - int n = 0; - while ((ix = strchr(ix, orig)) != NULL) - { - *ix++ = rep; - n++; - } + char *ix = str; + int n = 0; + while ((ix = strchr(ix, orig)) != NULL) + { + *ix++ = rep; + n++; + } } \ No newline at end of file diff --git a/RFLink/4_Display.h b/RFLink/4_Display.h index 5ff67b75..5de756e3 100644 --- a/RFLink/4_Display.h +++ b/RFLink/4_Display.h @@ -58,7 +58,8 @@ void display_METER(unsigned int); void display_VOLT(unsigned int); void display_RGBW(unsigned int); -// int str2cmd(char *command) +unsigned long str2int(char *); +int str2cmd(char *); void replacechar(char *, char, char); #endif \ No newline at end of file diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 9e8c2402..3a3bd26c 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -28,7 +28,6 @@ #define INPUT_COMMAND_SIZE 60 // 60 // Maximum number of characters that a command via serial can be. #define PRINT_BUFFER_SIZE 90 // 90 // Maximum number of characters that a command should print in one go via the print buffer. -/* #define VALUE_PAIR 44 #define VALUE_ALLOFF 55 #define VALUE_OFF 74 @@ -41,7 +40,6 @@ #define VALUE_CONFIRM 81 #define VALUE_LIMIT 82 #define VALUE_ALLON 141 -*/ // PIN Definition // From 980c57a23cfb23a35c5177a715172615cb728671 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Fri, 24 Apr 2020 11:45:50 +0200 Subject: [PATCH 07/46] Ractivate Plugin_004_TX (1st try) --- RFLink/3_Serial.h | 2 + RFLink/Plugins/Plugin_004.c | 69 +++++++++++++++++++----------- RFLink/Plugins/_Plugin_Config_01.h | 2 +- RFLink/RFLink.h | 2 +- 4 files changed, 48 insertions(+), 27 deletions(-) diff --git a/RFLink/3_Serial.h b/RFLink/3_Serial.h index 3270cf47..fe403bd8 100644 --- a/RFLink/3_Serial.h +++ b/RFLink/3_Serial.h @@ -11,6 +11,8 @@ #include #include "RFLink.h" +extern char InputBuffer_Serial[INPUT_COMMAND_SIZE]; + boolean CheckSerial(); boolean CheckMQTT(byte *); diff --git a/RFLink/Plugins/Plugin_004.c b/RFLink/Plugins/Plugin_004.c index 10cceeb9..6306e5b7 100644 --- a/RFLink/Plugins/Plugin_004.c +++ b/RFLink/Plugins/Plugin_004.c @@ -140,7 +140,7 @@ boolean Plugin_004(byte function, char *string) if (i > 140 && dimbitpresent == 1) display_SET_LEVEL(dim); // Command and Dim part else - display_CMD((CMD_Group)((bitstream >> 5) & B01),(CMD_OnOff)((bitstream >> 4) & B01));// #ALL , #ON + display_CMD((CMD_Group)((bitstream >> 5) & B01), (CMD_OnOff)((bitstream >> 4) & B01)); // #ALL , #ON display_Footer(); // ---------------------------------- RawSignal.Repeats = true; // suppress repeats of the same RF packet @@ -150,12 +150,16 @@ boolean Plugin_004(byte function, char *string) #endif // Plugin_004 #ifdef PLUGIN_TX_004 +#include "3_Serial.h" +#include "4_Display.h" + void AC_Send(unsigned long data, byte cmd); boolean PluginTX_004(byte function, char *string) { boolean success = false; - //10;NewKaku;123456;3;ON; // ON, OFF, ALLON, ALLOFF, ALL 99, 99 + // ON, OFF, ALLON, ALLOFF, ALL 99, 99 + //10;NewKaku;123456;3;ON; //10;NewKaku;0cac142;2;ON; //10;NewKaku;050515;f;OFF; //10;NewKaku;2100fed;1;ON; @@ -163,25 +167,29 @@ boolean PluginTX_004(byte function, char *string) //10;NewKaku;306070b;f;ON; //10;NewKaku;306070b;10;ON; //01234567890123456789012 + + Serial.println("\n*** TX_004 ***"); + Serial.println(InputBuffer_Serial); + if (strncasecmp(InputBuffer_Serial + 3, "NEWKAKU;", 8) == 0) { + Serial.println("Newkaku OK"); + byte x = 18; // pointer to the switch number if (InputBuffer_Serial[17] != ';') { if (InputBuffer_Serial[18] != ';') - { return false; - } else - { x = 19; - } } + Serial.println("Switch OK"); + unsigned long bitstream = 0L; unsigned long tempaddress = 0L; byte cmd = 0; - //byte c=0; // MRI commented + byte c = 0; byte Address = 0; // Address 1..16 // ----- @@ -190,9 +198,14 @@ boolean PluginTX_004(byte function, char *string) InputBuffer_Serial[x - 1] = 0x00; tempaddress = str2int(InputBuffer_Serial + 9); // ----- - //while((c=InputBuffer_Serial[x++])!=';'){ // Address: 1 to 16 - // if(c>='0' && c<='9'){Address=Address*10;Address=Address+c-'0';} - //} + while ((c = InputBuffer_Serial[x++]) != ';') + { // Address: 1 to 16 + if (c >= '0' && c <= '9') + { + Address = Address * 10; + Address = Address + c - '0'; + } + } InputBuffer_Serial[x - 2] = 0x30; // Get unit number from hexadecimal value InputBuffer_Serial[x - 1] = 0x78; // x points to the first character of the unit number if (InputBuffer_Serial[x + 1] == ';') @@ -208,23 +221,25 @@ boolean PluginTX_004(byte function, char *string) cmd = 3; } else - { return false; - } } + + Serial.println("Unit1 OK"); + Address = str2int(InputBuffer_Serial + (x - 2)); // NewKAKU unit number if (Address > 16) return false; // invalid address - Address--; // 1 to 16 -> 0 to 15 (transmitted value is 1 less than shown values) - x = x + cmd; // point to on/off/dim command part + + Serial.println("Unit2 OK"); + + Address--; // 1 to 16 -> 0 to 15 (transmitted value is 1 less than shown values) + x += cmd; // point to on/off/dim command part // ----- tempaddress = (tempaddress << 6) + Address; // Complete transmitted address // ----- - cmd = str2cmd(InputBuffer_Serial + x); // Get ON/OFF etc. command - if (cmd == false) - { // Not a valid command received? ON/OFF/ALLON/ALLOFF + cmd = str2cmd(InputBuffer_Serial + x); // Get ON/OFF etc. command + if (cmd == false) // Not a valid command received? ON/OFF/ALLON/ALLOFF cmd = str2int(InputBuffer_Serial + x); // get DIM value - } // --------------- Prepare bitstream ------------ bitstream = tempaddress & 0xFFFFFFCF; // adres geheel over nemen behalve de twee bits 5 en 6 die het schakel commando bevatten. @@ -244,7 +259,12 @@ boolean PluginTX_004(byte function, char *string) } // bitstream now contains the AC/NewKAKU-bits that have to be transmitted // --------------- NEWKAKU SEND ------------ + Serial.println("Send Ready"); + AC_Send(bitstream, cmd); + + Serial.println("Send OK"); + success = true; } // -------------------------------------- @@ -275,9 +295,9 @@ void AC_Send(unsigned long data, byte cmd) } } // Prepare transmit - digitalWrite(PIN_RF_RX_VCC, LOW); // Turn off power to the RF receiver - digitalWrite(PIN_RF_TX_VCC, HIGH); // Enable the 433Mhz transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) + digitalWrite(PIN_RF_RX_VCC, LOW); // Turn off power to the RF receiver + digitalWrite(PIN_RF_TX_VCC, HIGH); // Enable the 433Mhz transmitter + delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) // send bits for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { @@ -368,9 +388,8 @@ void AC_Send(unsigned long data, byte cmd) delayMicroseconds(fpulse * 40); //31*335=10385 40*260=10400 } // End transmit - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // Turn thew 433Mhz transmitter off - digitalWrite(PIN_RF_RX_VCC, HIGH); // Turn the 433Mhz receiver on - RFLinkHW(); + delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) + digitalWrite(PIN_RF_TX_VCC, LOW); // Turn thew 433Mhz transmitter off + digitalWrite(PIN_RF_RX_VCC, HIGH); // Turn the 433Mhz receiver on } #endif // Plugin_TX_004 diff --git a/RFLink/Plugins/_Plugin_Config_01.h b/RFLink/Plugins/_Plugin_Config_01.h index ff6a14c4..7291dc78 100644 --- a/RFLink/Plugins/_Plugin_Config_01.h +++ b/RFLink/Plugins/_Plugin_Config_01.h @@ -93,7 +93,7 @@ // -- Any of the following protocols can be excluded whenever not needed -- // ------------------------------------------------------------------------ // #define PLUGIN_TX_003 // Kaku : Klik-Aan-Klik-Uit (with code wheel) aka ARC -// #define PLUGIN_TX_004 // NewKAKU : Klik-Aan-Klik-Uit with automatic coding aka Intertechno. +#define PLUGIN_TX_004 // NewKAKU : Klik-Aan-Klik-Uit with automatic coding aka Intertechno. // #define PLUGIN_TX_005 // Eurodomest // #define PLUGIN_TX_006 // Blyss // #define PLUGIN_TX_007 // Conrad RSL2 diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 3a3bd26c..c49e0517 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -24,7 +24,7 @@ #define SCAN_HIGH_TIME_MS 50 // 50 // time interval in ms. fast processing for background tasks #define FOCUS_TIME_MS 50 // 50 // Duration in mSec. that, after receiving serial data from USB only the serial port is checked. #define PLUGIN_MAX 55 // 55 // Maximum number of Receive plugins -#define PLUGIN_TX_MAX 0 // 26 // Maximum number of Transmit plugins +#define PLUGIN_TX_MAX 5 // 26 // Maximum number of Transmit plugins #define INPUT_COMMAND_SIZE 60 // 60 // Maximum number of characters that a command via serial can be. #define PRINT_BUFFER_SIZE 90 // 90 // Maximum number of characters that a command should print in one go via the print buffer. From 34ef853f65052a7f5d4ffb02244d4896e384b188 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Sat, 25 Apr 2020 00:15:57 +0200 Subject: [PATCH 08/46] Minor update --- RFLink/3_Serial.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/RFLink/3_Serial.cpp b/RFLink/3_Serial.cpp index dd1a590f..199083d2 100644 --- a/RFLink/3_Serial.cpp +++ b/RFLink/3_Serial.cpp @@ -202,15 +202,12 @@ boolean CheckCmd() // ------------------------------------------------------- // Handle Generic Commands / Translate protocol data into Nodo text commands // ------------------------------------------------------- - disableRX(); enableTX(); - if (PluginTXCall(0, InputBuffer_Serial)) ValidCommand = 1; else // Answer that an invalid command was received? ValidCommand = 2; - disableTX(); enableRX(); } @@ -218,18 +215,12 @@ boolean CheckCmd() } // if > 7 if (ValidCommand != 0) { + display_Header(); if (ValidCommand == 1) - { - display_Header(); display_Name(PSTR("OK")); - display_Footer(); - } else - { - display_Header(); display_Name(PSTR("CMD UNKNOWN")); - display_Footer(); - } + display_Footer(); } InputBuffer_Serial[0] = 0; // serial data has been processed. ValidCommand = 0; From 63ae236f8057c726f1c4edaee0b1374937b2be8e Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Sat, 25 Apr 2020 00:17:02 +0200 Subject: [PATCH 09/46] D4 (LED) for RX Data Pin --- RFLink/RFLink.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index c49e0517..23af3aff 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -51,7 +51,7 @@ #define PIN_RF_RX_GND D8 // Ground to the receiver on this pin #define PIN_RF_TX_VCC D5 // +5 volt / Vcc power to the transmitter on this pin #define PIN_RF_TX_GND D6 // Ground power to the transmitter on this pin -#define PIN_RF_TX_DATA D1 // Data to the 433Mhz transmitter on this pin +#define PIN_RF_TX_DATA D4 // Data to the 433Mhz transmitter on this pin #endif #ifdef ESP32 From 0904e382bfee8c1536b9fdebd0eccb988f4e322b Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Sat, 25 Apr 2020 00:19:14 +0200 Subject: [PATCH 10/46] Massive overhaull for plugin 004 TX --- RFLink/Plugins/Plugin_004.c | 255 +++++++++++++++++++++++------------- 1 file changed, 167 insertions(+), 88 deletions(-) diff --git a/RFLink/Plugins/Plugin_004.c b/RFLink/Plugins/Plugin_004.c index 6306e5b7..f204066c 100644 --- a/RFLink/Plugins/Plugin_004.c +++ b/RFLink/Plugins/Plugin_004.c @@ -157,7 +157,6 @@ void AC_Send(unsigned long data, byte cmd); boolean PluginTX_004(byte function, char *string) { - boolean success = false; // ON, OFF, ALLON, ALLOFF, ALL 99, 99 //10;NewKaku;123456;3;ON; //10;NewKaku;0cac142;2;ON; @@ -168,116 +167,196 @@ boolean PluginTX_004(byte function, char *string) //10;NewKaku;306070b;10;ON; //01234567890123456789012 - Serial.println("\n*** TX_004 ***"); - Serial.println(InputBuffer_Serial); + // Start message split + // Serial.print("*** Spliting message ***\n"); - if (strncasecmp(InputBuffer_Serial + 3, "NEWKAKU;", 8) == 0) + static const char c_delim[2] = ";"; + static char c_label[10]; + static char c_ID[10]; + static char c_Switch[10]; + static char c_Cmd[10]; + + // 10 + char *ptr = strtok(InputBuffer_Serial, c_delim); + if (ptr != NULL) { - Serial.println("Newkaku OK"); + strcpy(c_label, "10"); + if (strncasecmp(ptr, c_label, strlen(c_label)) != 0) + return false; + } + else + return false; - byte x = 18; // pointer to the switch number - if (InputBuffer_Serial[17] != ';') - { - if (InputBuffer_Serial[18] != ';') + // Newkaku + ptr = strtok(NULL, c_delim); + if (ptr != NULL) + { + strcpy(c_label, "NEWKAKU"); + if (strncasecmp(ptr, c_label, strlen(c_label)) != 0) + return false; + } + else + return false; + + // ID + ptr = strtok(NULL, c_delim); + if (ptr != NULL) + { + strcpy(c_label, "ID="); + if (strncasecmp(ptr, c_label, strlen(c_label)) == 0) + ptr += strlen(c_label); + + if (strlen(ptr) > 8) + return false; + + for (byte i = 0; i < strlen(ptr); i++) + if (!isxdigit(ptr[i])) return false; - else - x = 19; - } - Serial.println("Switch OK"); - - unsigned long bitstream = 0L; - unsigned long tempaddress = 0L; - byte cmd = 0; - byte c = 0; - byte Address = 0; // Address 1..16 - - // ----- - InputBuffer_Serial[9] = 0x30; // Get NEWKAKU/AC main address part from hexadecimal value - InputBuffer_Serial[10] = 0x78; - InputBuffer_Serial[x - 1] = 0x00; - tempaddress = str2int(InputBuffer_Serial + 9); - // ----- - while ((c = InputBuffer_Serial[x++]) != ';') - { // Address: 1 to 16 - if (c >= '0' && c <= '9') - { - Address = Address * 10; - Address = Address + c - '0'; - } - } - InputBuffer_Serial[x - 2] = 0x30; // Get unit number from hexadecimal value - InputBuffer_Serial[x - 1] = 0x78; // x points to the first character of the unit number - if (InputBuffer_Serial[x + 1] == ';') - { - InputBuffer_Serial[x + 1] = 0x00; - cmd = 2; - } - else - { - if (InputBuffer_Serial[x + 2] == ';') - { - InputBuffer_Serial[x + 2] = 0x00; - cmd = 3; - } - else + strcpy(c_ID, ptr); + c_ID[8] = 0; + } + else + return false; + + // Switch + ptr = strtok(NULL, c_delim); + if (ptr != NULL) + { + strcpy(c_label, "SWITCH="); + if (strncasecmp(ptr, c_label, strlen(c_label)) == 0) + ptr += strlen(c_label); + + if (strlen(ptr) > 1) + return false; + + for (byte i = 0; i < strlen(ptr); i++) + if (!isxdigit(ptr[i])) return false; - } - Serial.println("Unit1 OK"); + strcpy(c_Switch, ptr); + } + else + return false; - Address = str2int(InputBuffer_Serial + (x - 2)); // NewKAKU unit number - if (Address > 16) - return false; // invalid address + // Command + ptr = strtok(NULL, c_delim); + if (ptr != NULL) + { + strcpy(c_label, "SET_LEVEL="); + if (strncasecmp(ptr, c_label, strlen(c_label)) == 0) + ptr += strlen(c_label); - Serial.println("Unit2 OK"); + strcpy(c_label, "CMD="); + if (strncasecmp(ptr, c_label, strlen(c_label)) == 0) + ptr += strlen(c_label); - Address--; // 1 to 16 -> 0 to 15 (transmitted value is 1 less than shown values) - x += cmd; // point to on/off/dim command part - // ----- - tempaddress = (tempaddress << 6) + Address; // Complete transmitted address - // ----- - cmd = str2cmd(InputBuffer_Serial + x); // Get ON/OFF etc. command - if (cmd == false) // Not a valid command received? ON/OFF/ALLON/ALLOFF - cmd = str2int(InputBuffer_Serial + x); // get DIM value - // --------------- Prepare bitstream ------------ - bitstream = tempaddress & 0xFFFFFFCF; // adres geheel over nemen behalve de twee bits 5 en 6 die het schakel commando bevatten. + if (strlen(ptr) > 7) + return false; - // Dimming of groups is also possible but not supported yet! - // when level=0 is it better to transmit just the off command ? + for (byte i = 0; i < strlen(ptr); i++) + if (!isalnum(ptr[i])) + return false; - if (cmd == VALUE_ON || cmd == VALUE_OFF) - { - bitstream |= (cmd == VALUE_ON) << 4; // bit-5 is the on/off command in the KAKU signal - cmd = 0xff; - } - else if (cmd == VALUE_ALLON || cmd == VALUE_ALLOFF) - { - bitstream |= B1 << 5; // bit 5 is the group indicator - bitstream |= (cmd == VALUE_ALLON) << 4; // bit-4 is the on/off indicator - cmd = 0xff; - } - // bitstream now contains the AC/NewKAKU-bits that have to be transmitted - // --------------- NEWKAKU SEND ------------ - Serial.println("Send Ready"); + strcpy(c_Cmd, ptr); + } + else + return false; + + // End + ptr = strtok(NULL, c_delim); + if (ptr != NULL) + return false; + + // Summary message split + // Serial.print("*** Split OK ***\n"); + // Serial.println(c_ID); + // Serial.println(c_Switch); + // Serial.println(c_Cmd); - AC_Send(bitstream, cmd); + // --------------- Prepare bitstream ------------ + // Dimming of groups is also possible but not supported yet! + // when level=0 is it better to transmit just the off command ? + // Serial.print("*** Creating bitstream ***\n"); + unsigned long bitstream = 0L; // 32 bits complete packet - Serial.println("Send OK"); + unsigned long ID_bitstream = 0L; // 26 bits Address + ID_bitstream = strtoul(c_ID, NULL, HEX); + ID_bitstream &= 0x03FFFFFF; + // Serial.println("ID_bitstream"); + // Serial.println(ID_bitstream, HEX); - success = true; + bitstream = (ID_bitstream << 6); // 26 bits on top + + byte Switch_bitstream = 0; // 4 bits Unit + Switch_bitstream = (byte)strtoul(c_Switch, NULL, HEX); + Switch_bitstream--; // 1 to 16 -> 0 to 15 (displayed value is one more) + if (Switch_bitstream > 0xF) + return false; // invalid address + // Serial.println("Switch_bitstream"); + // Serial.println(Switch_bitstream, HEX); + + bitstream |= Switch_bitstream; // Complete transmitted address + bitstream &= 0xFFFFFFCF; // Bit 4 and 5 are left for cmd + + byte Cmd_bitstream = 0x00; // 2 bits Command + byte cmd = 0; + cmd = str2cmd(c_Cmd); // Get ON/OFF etc. command + if (cmd == false) // Not a valid command received? ON/OFF/ALLON/ALLOFF + cmd = (byte)strtoul(c_Cmd, NULL, HEX); + // ON + switch (cmd) + { + case VALUE_ON: + case VALUE_ALLON: + Cmd_bitstream |= B01; + break; + } + // Group + switch (cmd) + { + case VALUE_ALLON: + case VALUE_ALLOFF: + Cmd_bitstream |= B10; + break; + } + // Dimmer + switch (cmd) + { + case VALUE_ON: + case VALUE_OFF: + case VALUE_ALLON: + case VALUE_ALLOFF: + cmd = 0xFF; + break; } + // Serial.println("Cmd_bitstream"); + // Serial.println(Cmd_bitstream, HEX); + + bitstream |= (Cmd_bitstream << 4); + + // Serial.println("Complete bitstream"); + // Serial.println(bitstream, HEX); + + // Serial.println("cmd"); + // Serial.println(cmd, HEX); + + // bitstream now contains the AC/NewKAKU-bits that have to be transmitted + // --------------- NEWKAKU SEND ------------ + + AC_Send(bitstream, cmd); + // -------------------------------------- - return success; + return true; } void AC_Send(unsigned long data, byte cmd) { - int fpulse = 260; // Pulse width in microseconds - int fretrans = 10; // Number of code retransmissions + int fpulse = 260; // Pulse width in microseconds + int fretrans = 5; // Number of code retransmissions unsigned long bitstream = 0L; - byte command; + byte command = 0; // prepare data to send for (unsigned short i = 0; i < 32; i++) { // reverse data bits From 122f0cbcbbbcb095ae1546419c4fe05903e50c81 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Sat, 25 Apr 2020 18:17:05 +0200 Subject: [PATCH 11/46] New "MOS" PINs For handling N/P-MOSFETs --- RFLink/RFLink.h | 44 ++++++++++++++++++++++++++++++-------------- RFLink/RFLink.ino | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 23af3aff..9a06c0ab 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -45,43 +45,59 @@ // #ifdef ESP8266 // ESP8266 D1 Mini -#define PIN_RF_RX_VCC D7 // Power to the receiver on this pin -#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA D2 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_RX_GND D8 // Ground to the receiver on this pin -#define PIN_RF_TX_VCC D5 // +5 volt / Vcc power to the transmitter on this pin -#define PIN_RF_TX_GND D6 // Ground power to the transmitter on this pin -#define PIN_RF_TX_DATA D4 // Data to the 433Mhz transmitter on this pin +#define PIN_RF_RX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_RX_NMOS D5 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin +#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_DATA D7 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_TX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_TX_NMOS D6 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin +#define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin +#define PIN_RF_TX_DATA D4 // Data to the 433Mhz transmitter on this pin #endif #ifdef ESP32 +#define PIN_RF_RX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_RX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level #define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin -#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA 2 // On this input, the 433Mhz-RF signal is received. LOW when no signal. #define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_DATA NOT_A_PIN // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_TX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_TX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level #define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin #define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin #define PIN_RF_TX_DATA NOT_A_PIN // Data to the 433Mhz transmitter on this pin #endif #ifdef __AVR_ATmega328P__ +#define PIN_RF_RX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_RX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level #define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin +#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin #define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input #define PIN_RF_RX_DATA 2 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_TX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_TX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level #define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin #define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin #define PIN_RF_TX_DATA NOT_A_PIN // Data to the 433Mhz transmitter on this pin #endif #ifdef __AVR_ATmega2560__ -#define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin +#define PIN_RF_RX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_RX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_RX_VCC 16 // Power to the receiver on this pin +#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin #define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input #define PIN_RF_RX_DATA 19 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin -#define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin +#define PIN_RF_TX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_TX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_TX_VCC 15 // +5 volt / Vcc power to the transmitter on this pin #define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin -#define PIN_RF_TX_DATA NOT_A_PIN // Data to the 433Mhz transmitter on this pin +#define PIN_RF_TX_DATA 14 // Data to the 433Mhz transmitter on this pin #endif // OLED display, 0.91" SSD1306 I2C diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index a8f9b47c..a1a07692 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -128,13 +128,18 @@ void sendMsg() void enableRX() { // RX pins - pinMode(PIN_RF_RX_GND, OUTPUT); // Initialise in/output ports - pinMode(PIN_RF_RX_VCC, OUTPUT); // Initialise in/output ports pinMode(PIN_RF_RX_NA, INPUT); // Initialise in/output ports pinMode(PIN_RF_RX_DATA, INPUT); // Initialise in/output ports + pinMode(PIN_RF_RX_NMOS, OUTPUT); // MOSFET, always output + pinMode(PIN_RF_RX_PMOS, OUTPUT); // MOSFET, always output + digitalWrite(PIN_RF_RX_NMOS, HIGH); // turn GND to RF receiver ON + digitalWrite(PIN_RF_RX_PMOS, LOW); // turn VCC to RF receiver ON + pinMode(PIN_RF_RX_GND, OUTPUT); // Initialise in/output ports + pinMode(PIN_RF_RX_VCC, OUTPUT); // Initialise in/output ports digitalWrite(PIN_RF_RX_GND, LOW); // turn GND to RF receiver ON digitalWrite(PIN_RF_RX_VCC, HIGH); // turn VCC to RF receiver ON pinMode(PIN_RF_RX_DATA, INPUT_PULLUP); // Initialise in/output ports + delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); } void disableRX() @@ -142,6 +147,10 @@ void disableRX() // RX pins pinMode(PIN_RF_RX_DATA, INPUT); pinMode(PIN_RF_RX_NA, INPUT); + pinMode(PIN_RF_RX_PMOS, OUTPUT); // MOSFET, always output + pinMode(PIN_RF_RX_NMOS, OUTPUT); // MOSFET, always output + digitalWrite(PIN_RF_RX_PMOS, HIGH); // turn VCC to RF receiver OFF + digitalWrite(PIN_RF_RX_NMOS, LOW); // turn GND to RF receiver OFF pinMode(PIN_RF_RX_VCC, INPUT); pinMode(PIN_RF_RX_GND, INPUT); } @@ -149,18 +158,29 @@ void disableRX() void enableTX() { // TX Pins - pinMode(PIN_RF_TX_GND, OUTPUT); // Initialise in/output ports - pinMode(PIN_RF_TX_VCC, OUTPUT); // Initialise in/output ports - pinMode(PIN_RF_TX_DATA, OUTPUT); // Initialise in/output ports - digitalWrite(PIN_RF_TX_GND, LOW); // turn GND to TX receiver ON - digitalWrite(PIN_RF_TX_VCC, HIGH); // turn VCC to TX receiver ON + pinMode(PIN_RF_TX_DATA, OUTPUT); // Initialise in/output ports + digitalWrite(PIN_RF_TX_DATA, LOW); // No signal yet + pinMode(PIN_RF_TX_NMOS, OUTPUT); // MOSFET, always output + pinMode(PIN_RF_TX_PMOS, OUTPUT); // MOSFET, always output + digitalWrite(PIN_RF_TX_NMOS, HIGH); // turn GND to TX receiver ON + digitalWrite(PIN_RF_TX_PMOS, LOW); // turn VCC to TX receiver ON + pinMode(PIN_RF_TX_GND, OUTPUT); // Initialise in/output ports + pinMode(PIN_RF_TX_VCC, OUTPUT); // Initialise in/output ports + digitalWrite(PIN_RF_TX_GND, LOW); // turn GND to TX receiver ON + digitalWrite(PIN_RF_TX_VCC, HIGH); // turn VCC to TX receiver ON delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); } void disableTX() { // TX Pins - pinMode(PIN_RF_TX_DATA, INPUT); + delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); + digitalWrite(PIN_RF_TX_DATA, LOW); // No more signal + pinMode(PIN_RF_TX_DATA, INPUT); // + pinMode(PIN_RF_TX_NMOS, OUTPUT); // MOSFET, always output + pinMode(PIN_RF_TX_PMOS, OUTPUT); // MOSFET, always output + digitalWrite(PIN_RF_TX_PMOS, HIGH); // turn VCC to TX receiver OFF + digitalWrite(PIN_RF_TX_NMOS, LOW); // turn GND to TX receiver OFF pinMode(PIN_RF_TX_VCC, INPUT); pinMode(PIN_RF_TX_GND, INPUT); } From ba01a0d2fced4587342efb2c43b8891e10fb0b4f Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Sat, 25 Apr 2020 18:18:05 +0200 Subject: [PATCH 12/46] Moved cmd #define Closer to str2cmd() --- RFLink/4_Display.h | 13 +++++++++++++ RFLink/RFLink.h | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/RFLink/4_Display.h b/RFLink/4_Display.h index 5de756e3..c2f7ccc3 100644 --- a/RFLink/4_Display.h +++ b/RFLink/4_Display.h @@ -59,6 +59,19 @@ void display_VOLT(unsigned int); void display_RGBW(unsigned int); unsigned long str2int(char *); +#define VALUE_PAIR 44 +#define VALUE_ALLOFF 55 +#define VALUE_OFF 74 +#define VALUE_ON 75 +#define VALUE_DIM 76 +#define VALUE_BRIGHT 77 +#define VALUE_UP 78 +#define VALUE_DOWN 79 +#define VALUE_STOP 80 +#define VALUE_CONFIRM 81 +#define VALUE_LIMIT 82 +#define VALUE_ALLON 141 + int str2cmd(char *); void replacechar(char *, char, char); diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 9a06c0ab..1c0c1302 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -28,19 +28,6 @@ #define INPUT_COMMAND_SIZE 60 // 60 // Maximum number of characters that a command via serial can be. #define PRINT_BUFFER_SIZE 90 // 90 // Maximum number of characters that a command should print in one go via the print buffer. -#define VALUE_PAIR 44 -#define VALUE_ALLOFF 55 -#define VALUE_OFF 74 -#define VALUE_ON 75 -#define VALUE_DIM 76 -#define VALUE_BRIGHT 77 -#define VALUE_UP 78 -#define VALUE_DOWN 79 -#define VALUE_STOP 80 -#define VALUE_CONFIRM 81 -#define VALUE_LIMIT 82 -#define VALUE_ALLON 141 - // PIN Definition // #ifdef ESP8266 From 8c459c6c5e2c47af3b3cbc0fa7d3e673107d9f26 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Sat, 25 Apr 2020 18:19:02 +0200 Subject: [PATCH 13/46] Removed str2int alias May cause too much misunderstandings --- RFLink/4_Display.cpp | 7 ------- RFLink/4_Display.h | 1 - 2 files changed, 8 deletions(-) diff --git a/RFLink/4_Display.cpp b/RFLink/4_Display.cpp index 57817475..3aa11c87 100644 --- a/RFLink/4_Display.cpp +++ b/RFLink/4_Display.cpp @@ -335,13 +335,6 @@ void display_RGBW(unsigned int input) strcat(pbuffer, dbuffer); } -/*********************************************************************************************\ - Convert HEX or DEC tring to unsigned long HEX, DEC - \*********************************************************************************************/ -unsigned long str2int(char *string) -{ - return (strtoul(string, NULL, 0)); -} /*********************************************************************************************\ Convert string to command code \*********************************************************************************************/ diff --git a/RFLink/4_Display.h b/RFLink/4_Display.h index c2f7ccc3..aaaf32cb 100644 --- a/RFLink/4_Display.h +++ b/RFLink/4_Display.h @@ -58,7 +58,6 @@ void display_METER(unsigned int); void display_VOLT(unsigned int); void display_RGBW(unsigned int); -unsigned long str2int(char *); #define VALUE_PAIR 44 #define VALUE_ALLOFF 55 #define VALUE_OFF 74 From 2264d22f2f20e435f8afe9e81d37d29f5673ac12 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Sat, 25 Apr 2020 18:20:41 +0200 Subject: [PATCH 14/46] Moved AC_Send() in 2_Signal.cpp A plugin should not handle radio pins directly. --- RFLink/2_Signal.cpp | 126 +++++++++++++++++++++++++++++++++++- RFLink/2_Signal.h | 2 + RFLink/Plugins/Plugin_004.c | 122 ---------------------------------- 3 files changed, 126 insertions(+), 124 deletions(-) diff --git a/RFLink/2_Signal.cpp b/RFLink/2_Signal.cpp index 59fa9498..e5654968 100644 --- a/RFLink/2_Signal.cpp +++ b/RFLink/2_Signal.cpp @@ -256,7 +256,7 @@ boolean FetchSignal() */ /*********************************************************************************************\ Send rawsignal buffer to RF * DEPRICATED * DO NOT USE - \*********************************************************************************************/ +\*********************************************************************************************/ /* void RawSendRF(void) { // * DEPRICATED * DO NOT USE * int x; @@ -285,4 +285,126 @@ boolean FetchSignal() // RFLinkHW(); } */ -/*********************************************************************************************/ + +/*********************************************************************************************\ + Send bitstream to RF - Plugin 004 (Newkaku) special version +\*********************************************************************************************/ +void AC_Send(unsigned long data, byte cmd) +{ +#define AC_FPULSE 260 // Pulse width in microseconds +#define AC_FRETRANS 5 // Number of code retransmissions + + // Serial.println("Send AC"); + // Serial.println(data, HEX); + // Serial.println(cmd, HEX); + + unsigned long bitstream = 0L; + byte command = 0; + // prepare data to send + for (unsigned short i = 0; i < 32; i++) + { // reverse data bits + bitstream <<= 1; + bitstream |= (data & B1); + data >>= 1; + } + if (cmd != 0xff) + { // reverse dim bits + for (unsigned short i = 0; i < 4; i++) + { + command <<= 1; + command |= (cmd & B1); + cmd >>= 1; + } + } + // send bits + for (byte nRepeat = 0; nRepeat < AC_FRETRANS; nRepeat++) + { + data = bitstream; + if (cmd != 0xff) + cmd = command; + digitalWrite(PIN_RF_TX_DATA, HIGH); + //delayMicroseconds(fpulse); //335 + delayMicroseconds(335); + digitalWrite(PIN_RF_TX_DATA, LOW); + delayMicroseconds(AC_FPULSE * 10 + (AC_FPULSE >> 1)); //335*9=3015 //260*10=2600 + for (unsigned short i = 0; i < 32; i++) + { + if (i == 27 && cmd != 0xff) + { // DIM command, send special DIM sequence TTTT replacing on/off bit + digitalWrite(PIN_RF_TX_DATA, HIGH); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, LOW); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, HIGH); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, LOW); + delayMicroseconds(AC_FPULSE); + } + else + switch (data & B1) + { + case 0: + digitalWrite(PIN_RF_TX_DATA, HIGH); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, LOW); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, HIGH); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, LOW); + delayMicroseconds(AC_FPULSE * 5); // 335*3=1005 260*5=1300 260*4=1040 + break; + case 1: + digitalWrite(PIN_RF_TX_DATA, HIGH); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, LOW); + delayMicroseconds(AC_FPULSE * 5); + digitalWrite(PIN_RF_TX_DATA, HIGH); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, LOW); + delayMicroseconds(AC_FPULSE); + break; + } + //Next bit + data >>= 1; + } + // send dim bits when needed + if (cmd != 0xff) + { // need to send DIM command bits + for (unsigned short i = 0; i < 4; i++) + { // 4 bits + switch (cmd & B1) + { + case 0: + digitalWrite(PIN_RF_TX_DATA, HIGH); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, LOW); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, HIGH); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, LOW); + delayMicroseconds(AC_FPULSE * 5); // 335*3=1005 260*5=1300 + break; + case 1: + digitalWrite(PIN_RF_TX_DATA, HIGH); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, LOW); + delayMicroseconds(AC_FPULSE * 5); + digitalWrite(PIN_RF_TX_DATA, HIGH); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, LOW); + delayMicroseconds(AC_FPULSE); + break; + } + //Next bit + cmd >>= 1; + } + } + //Send termination/synchronisation-signal. Total length: 32 periods + digitalWrite(PIN_RF_TX_DATA, HIGH); + delayMicroseconds(AC_FPULSE); + digitalWrite(PIN_RF_TX_DATA, LOW); + delayMicroseconds(AC_FPULSE * 40); //31*335=10385 40*260=10400 + } + // End transmit +} +/*********************************************************************************************/ \ No newline at end of file diff --git a/RFLink/2_Signal.h b/RFLink/2_Signal.h index dd00ce84..6655b862 100644 --- a/RFLink/2_Signal.h +++ b/RFLink/2_Signal.h @@ -34,4 +34,6 @@ boolean ScanEvent(void); // void RFLinkHW(void); // void RawSendRF(void); +void AC_Send(unsigned long data, byte cmd); + #endif \ No newline at end of file diff --git a/RFLink/Plugins/Plugin_004.c b/RFLink/Plugins/Plugin_004.c index f204066c..af43d8de 100644 --- a/RFLink/Plugins/Plugin_004.c +++ b/RFLink/Plugins/Plugin_004.c @@ -153,8 +153,6 @@ boolean Plugin_004(byte function, char *string) #include "3_Serial.h" #include "4_Display.h" -void AC_Send(unsigned long data, byte cmd); - boolean PluginTX_004(byte function, char *string) { // ON, OFF, ALLON, ALLOFF, ALL 99, 99 @@ -350,125 +348,5 @@ boolean PluginTX_004(byte function, char *string) return true; } -void AC_Send(unsigned long data, byte cmd) -{ - int fpulse = 260; // Pulse width in microseconds - int fretrans = 5; // Number of code retransmissions - unsigned long bitstream = 0L; - byte command = 0; - // prepare data to send - for (unsigned short i = 0; i < 32; i++) - { // reverse data bits - bitstream <<= 1; - bitstream |= (data & B1); - data >>= 1; - } - if (cmd != 0xff) - { // reverse dim bits - for (unsigned short i = 0; i < 4; i++) - { - command <<= 1; - command |= (cmd & B1); - cmd >>= 1; - } - } - // Prepare transmit - digitalWrite(PIN_RF_RX_VCC, LOW); // Turn off power to the RF receiver - digitalWrite(PIN_RF_TX_VCC, HIGH); // Enable the 433Mhz transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - // send bits - for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) - { - data = bitstream; - if (cmd != 0xff) - cmd = command; - digitalWrite(PIN_RF_TX_DATA, HIGH); - //delayMicroseconds(fpulse); //335 - delayMicroseconds(335); - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(fpulse * 10 + (fpulse >> 1)); //335*9=3015 //260*10=2600 - for (unsigned short i = 0; i < 32; i++) - { - if (i == 27 && cmd != 0xff) - { // DIM command, send special DIM sequence TTTT replacing on/off bit - digitalWrite(PIN_RF_TX_DATA, HIGH); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, HIGH); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(fpulse); - } - else - switch (data & B1) - { - case 0: - digitalWrite(PIN_RF_TX_DATA, HIGH); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, HIGH); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(fpulse * 5); // 335*3=1005 260*5=1300 260*4=1040 - break; - case 1: - digitalWrite(PIN_RF_TX_DATA, HIGH); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(fpulse * 5); - digitalWrite(PIN_RF_TX_DATA, HIGH); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(fpulse); - break; - } - //Next bit - data >>= 1; - } - // send dim bits when needed - if (cmd != 0xff) - { // need to send DIM command bits - for (unsigned short i = 0; i < 4; i++) - { // 4 bits - switch (cmd & B1) - { - case 0: - digitalWrite(PIN_RF_TX_DATA, HIGH); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, HIGH); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(fpulse * 5); // 335*3=1005 260*5=1300 - break; - case 1: - digitalWrite(PIN_RF_TX_DATA, HIGH); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(fpulse * 5); - digitalWrite(PIN_RF_TX_DATA, HIGH); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(fpulse); - break; - } - //Next bit - cmd >>= 1; - } - } - //Send termination/synchronisation-signal. Total length: 32 periods - digitalWrite(PIN_RF_TX_DATA, HIGH); - delayMicroseconds(fpulse); - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(fpulse * 40); //31*335=10385 40*260=10400 - } - // End transmit - delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // Turn thew 433Mhz transmitter off - digitalWrite(PIN_RF_RX_VCC, HIGH); // Turn the 433Mhz receiver on -} #endif // Plugin_TX_004 From 9862c03a8334055bd9fc75cd028a3c535664fe0d Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Sat, 25 Apr 2020 20:45:58 +0200 Subject: [PATCH 15/46] Turned specific some Plugin TX 004 code into generic "retrieve_XXX" funcs --- RFLink/4_Display.cpp | 190 ++++++++++++++++++++++++++++++++++-- RFLink/4_Display.h | 66 +++++++++---- RFLink/Plugins/Plugin_004.c | 169 +++----------------------------- 3 files changed, 241 insertions(+), 184 deletions(-) diff --git a/RFLink/4_Display.cpp b/RFLink/4_Display.cpp index 3aa11c87..1b0cd6ed 100644 --- a/RFLink/4_Display.cpp +++ b/RFLink/4_Display.cpp @@ -6,6 +6,7 @@ // ************************************* // #include +#include "3_Serial.h" #include "4_Display.h" byte PKSequenceNumber = 0; // 1 byte packet counter @@ -335,6 +336,175 @@ void display_RGBW(unsigned int input) strcat(pbuffer, dbuffer); } +// --------------------- // +// get label shared func // +// --------------------- // + +char *ptr; +const char c_delim[2] = ";"; +char c_label[10]; + +boolean retrieve_Init10() +{ + // 10 + ptr = strtok(InputBuffer_Serial, c_delim); + if (ptr != NULL) + { + if (strncasecmp(ptr, "10", strlen("10")) != 0) + return false; + return true; + } + else + return false; +} + +boolean retrieve_Name(const char *c_Name) +{ + // Newkaku + ptr = strtok(NULL, c_delim); + if (ptr != NULL) + { + if (strncasecmp(ptr, c_Name, strlen(c_Name)) != 0) + return false; + return true; + } + else + return false; +} + +boolean retrieve_ID(unsigned long &ul_ID) +{ + // ID + char c_ID[10]; + + ptr = strtok(NULL, c_delim); + if (ptr != NULL) + { + strcpy(c_label, "ID="); + if (strncasecmp(ptr, c_label, strlen(c_label)) == 0) + ptr += strlen(c_label); + + if (strlen(ptr) > 8) + return false; + + for (byte i = 0; i < strlen(ptr); i++) + if (!isxdigit(ptr[i])) + return false; + + strcpy(c_ID, ptr); + c_ID[8] = 0; + + ul_ID = strtoul(c_ID, NULL, HEX); + ul_ID &= 0x03FFFFFF; + + return true; + } + else + return false; +} + +boolean retrieve_Switch(byte &b_Switch) +{ + // Switch + char c_Switch[10]; + + ptr = strtok(NULL, c_delim); + if (ptr != NULL) + { + strcpy(c_label, "SWITCH="); + if (strncasecmp(ptr, c_label, strlen(c_label)) == 0) + ptr += strlen(c_label); + + if (strlen(ptr) > 1) + return false; + + for (byte i = 0; i < strlen(ptr); i++) + if (!isxdigit(ptr[i])) + return false; + + strcpy(c_Switch, ptr); + + b_Switch = (byte)strtoul(c_Switch, NULL, HEX); + b_Switch--; // 1 to 16 -> 0 to 15 (displayed value is one more) + if (b_Switch > 0xF) + return false; // invalid address + + return true; + } + else + return false; +} + +boolean retrieve_Command(byte &b_Cmd, byte &b_Cmd2) +{ + // Command + char c_Cmd[10]; + + ptr = strtok(NULL, c_delim); + if (ptr != NULL) + { + strcpy(c_label, "SET_LEVEL="); + if (strncasecmp(ptr, c_label, strlen(c_label)) == 0) + ptr += strlen(c_label); + + strcpy(c_label, "CMD="); + if (strncasecmp(ptr, c_label, strlen(c_label)) == 0) + ptr += strlen(c_label); + + if (strlen(ptr) > 7) + return false; + + for (byte i = 0; i < strlen(ptr); i++) + if (!isalnum(ptr[i])) + return false; + + strcpy(c_Cmd, ptr); + + b_Cmd2 = str2cmd(c_Cmd); // Get ON/OFF etc. command + if (b_Cmd2 == false) // Not a valid command received? ON/OFF/ALLON/ALLOFF + b_Cmd2 = (byte)strtoul(c_Cmd, NULL, HEX); + // ON + switch (b_Cmd2) + { + case VALUE_ON: + case VALUE_ALLON: + b_Cmd |= B01; + break; + } + // Group + switch (b_Cmd2) + { + case VALUE_ALLON: + case VALUE_ALLOFF: + b_Cmd |= B10; + break; + } + // Dimmer + switch (b_Cmd2) + { + case VALUE_ON: + case VALUE_OFF: + case VALUE_ALLON: + case VALUE_ALLOFF: + b_Cmd2 = 0xFF; + break; + } + + return true; + } + else + return false; +} + +boolean retrieve_End() +{ + // End + ptr = strtok(NULL, c_delim); + if (ptr != NULL) + return false; + return true; +} + /*********************************************************************************************\ Convert string to command code \*********************************************************************************************/ @@ -367,13 +537,13 @@ int str2cmd(char *command) return false; } -void replacechar(char *str, char orig, char rep) -{ - char *ix = str; - int n = 0; - while ((ix = strchr(ix, orig)) != NULL) - { - *ix++ = rep; - n++; - } -} \ No newline at end of file +// void replacechar(char *str, char orig, char rep) +// { +// char *ix = str; +// int n = 0; +// while ((ix = strchr(ix, orig)) != NULL) +// { +// *ix++ = rep; +// n++; +// } +// } \ No newline at end of file diff --git a/RFLink/4_Display.h b/RFLink/4_Display.h index aaaf32cb..2ff51672 100644 --- a/RFLink/4_Display.h +++ b/RFLink/4_Display.h @@ -22,12 +22,27 @@ void display_IDn(unsigned int, byte); void display_IDc(const char *); void display_SWITCH(byte); void display_SWITCHc(const char *); -enum CMD_Group {CMD_Single, CMD_All}; -enum CMD_OnOff {CMD_Off, CMD_On, CMD_Bright, CMD_Dim, CMD_Unknown}; +enum CMD_Group +{ + CMD_Single, + CMD_All +}; +enum CMD_OnOff +{ + CMD_Off, + CMD_On, + CMD_Bright, + CMD_Dim, + CMD_Unknown +}; void display_CMD(boolean, byte); void display_SET_LEVEL(byte); void display_TEMP(unsigned int); -enum HUM_Type {HUM_HEX, HUM_BCD}; +enum HUM_Type +{ + HUM_HEX, + HUM_BCD +}; void display_HUM(byte, boolean); void display_BARO(unsigned int); void display_HSTATUS(byte); @@ -44,9 +59,17 @@ void display_WINDIR(unsigned int); void display_WINCHL(unsigned int); void display_WINTMP(unsigned int); void display_CHIME(unsigned int); -enum SMOKE_OnOff {SMOKE_Off, SMOKE_On}; +enum SMOKE_OnOff +{ + SMOKE_Off, + SMOKE_On +}; void display_SMOKEALERT(boolean); -enum PIR_OnOff {PIR_Off, PIR_On}; +enum PIR_OnOff +{ + PIR_Off, + PIR_On +}; void display_PIR(boolean); void display_CO2(unsigned int); void display_SOUND(unsigned int); @@ -58,20 +81,27 @@ void display_METER(unsigned int); void display_VOLT(unsigned int); void display_RGBW(unsigned int); -#define VALUE_PAIR 44 -#define VALUE_ALLOFF 55 -#define VALUE_OFF 74 -#define VALUE_ON 75 -#define VALUE_DIM 76 -#define VALUE_BRIGHT 77 -#define VALUE_UP 78 -#define VALUE_DOWN 79 -#define VALUE_STOP 80 -#define VALUE_CONFIRM 81 -#define VALUE_LIMIT 82 -#define VALUE_ALLON 141 +boolean retrieve_Init10(); +boolean retrieve_Name(const char *); +boolean retrieve_ID(unsigned long &); +boolean retrieve_Switch(byte &); +boolean retrieve_Command(byte &, byte &); +boolean retrieve_End(); + +#define VALUE_PAIR 44 +#define VALUE_ALLOFF 55 +#define VALUE_OFF 74 +#define VALUE_ON 75 +#define VALUE_DIM 76 +#define VALUE_BRIGHT 77 +#define VALUE_UP 78 +#define VALUE_DOWN 79 +#define VALUE_STOP 80 +#define VALUE_CONFIRM 81 +#define VALUE_LIMIT 82 +#define VALUE_ALLON 141 int str2cmd(char *); -void replacechar(char *, char, char); +// void replacechar(char *, char, char); #endif \ No newline at end of file diff --git a/RFLink/Plugins/Plugin_004.c b/RFLink/Plugins/Plugin_004.c index af43d8de..e0daf399 100644 --- a/RFLink/Plugins/Plugin_004.c +++ b/RFLink/Plugins/Plugin_004.c @@ -165,188 +165,45 @@ boolean PluginTX_004(byte function, char *string) //10;NewKaku;306070b;10;ON; //01234567890123456789012 - // Start message split - // Serial.print("*** Spliting message ***\n"); - - static const char c_delim[2] = ";"; - static char c_label[10]; - static char c_ID[10]; - static char c_Switch[10]; - static char c_Cmd[10]; + unsigned long bitstream = 0L; // 32 bits complete packet + unsigned long ID_bitstream = 0L; // 26 bits Address + byte Switch_bitstream = 0; // 4 bits Unit + byte Cmd_bitstream = 0; // 2 bits Command + byte Cmd_dimmer = 0; // 4 bits Alt Command - // 10 - char *ptr = strtok(InputBuffer_Serial, c_delim); - if (ptr != NULL) - { - strcpy(c_label, "10"); - if (strncasecmp(ptr, c_label, strlen(c_label)) != 0) - return false; - } - else + if (!retrieve_Init10()) return false; - - // Newkaku - ptr = strtok(NULL, c_delim); - if (ptr != NULL) - { - strcpy(c_label, "NEWKAKU"); - if (strncasecmp(ptr, c_label, strlen(c_label)) != 0) - return false; - } - else + if (!retrieve_Name("Newkaku")) return false; - - // ID - ptr = strtok(NULL, c_delim); - if (ptr != NULL) - { - strcpy(c_label, "ID="); - if (strncasecmp(ptr, c_label, strlen(c_label)) == 0) - ptr += strlen(c_label); - - if (strlen(ptr) > 8) - return false; - - for (byte i = 0; i < strlen(ptr); i++) - if (!isxdigit(ptr[i])) - return false; - - strcpy(c_ID, ptr); - c_ID[8] = 0; - } - else + if (!retrieve_ID(ID_bitstream)) return false; - - // Switch - ptr = strtok(NULL, c_delim); - if (ptr != NULL) - { - strcpy(c_label, "SWITCH="); - if (strncasecmp(ptr, c_label, strlen(c_label)) == 0) - ptr += strlen(c_label); - - if (strlen(ptr) > 1) - return false; - - for (byte i = 0; i < strlen(ptr); i++) - if (!isxdigit(ptr[i])) - return false; - - strcpy(c_Switch, ptr); - } - else + if (!retrieve_Switch(Switch_bitstream)) return false; - - // Command - ptr = strtok(NULL, c_delim); - if (ptr != NULL) - { - strcpy(c_label, "SET_LEVEL="); - if (strncasecmp(ptr, c_label, strlen(c_label)) == 0) - ptr += strlen(c_label); - - strcpy(c_label, "CMD="); - if (strncasecmp(ptr, c_label, strlen(c_label)) == 0) - ptr += strlen(c_label); - - if (strlen(ptr) > 7) - return false; - - for (byte i = 0; i < strlen(ptr); i++) - if (!isalnum(ptr[i])) - return false; - - strcpy(c_Cmd, ptr); - } - else + if (!retrieve_Command(Cmd_bitstream, Cmd_dimmer)) return false; - - // End - ptr = strtok(NULL, c_delim); - if (ptr != NULL) + if (!retrieve_End()) return false; - // Summary message split - // Serial.print("*** Split OK ***\n"); - // Serial.println(c_ID); - // Serial.println(c_Switch); - // Serial.println(c_Cmd); - // --------------- Prepare bitstream ------------ // Dimming of groups is also possible but not supported yet! // when level=0 is it better to transmit just the off command ? // Serial.print("*** Creating bitstream ***\n"); - unsigned long bitstream = 0L; // 32 bits complete packet - unsigned long ID_bitstream = 0L; // 26 bits Address - ID_bitstream = strtoul(c_ID, NULL, HEX); - ID_bitstream &= 0x03FFFFFF; - // Serial.println("ID_bitstream"); - // Serial.println(ID_bitstream, HEX); bitstream = (ID_bitstream << 6); // 26 bits on top - - byte Switch_bitstream = 0; // 4 bits Unit - Switch_bitstream = (byte)strtoul(c_Switch, NULL, HEX); - Switch_bitstream--; // 1 to 16 -> 0 to 15 (displayed value is one more) - if (Switch_bitstream > 0xF) - return false; // invalid address - // Serial.println("Switch_bitstream"); - // Serial.println(Switch_bitstream, HEX); - bitstream |= Switch_bitstream; // Complete transmitted address - bitstream &= 0xFFFFFFCF; // Bit 4 and 5 are left for cmd - - byte Cmd_bitstream = 0x00; // 2 bits Command - byte cmd = 0; - cmd = str2cmd(c_Cmd); // Get ON/OFF etc. command - if (cmd == false) // Not a valid command received? ON/OFF/ALLON/ALLOFF - cmd = (byte)strtoul(c_Cmd, NULL, HEX); - // ON - switch (cmd) - { - case VALUE_ON: - case VALUE_ALLON: - Cmd_bitstream |= B01; - break; - } - // Group - switch (cmd) - { - case VALUE_ALLON: - case VALUE_ALLOFF: - Cmd_bitstream |= B10; - break; - } - // Dimmer - switch (cmd) - { - case VALUE_ON: - case VALUE_OFF: - case VALUE_ALLON: - case VALUE_ALLOFF: - cmd = 0xFF; - break; - } - // Serial.println("Cmd_bitstream"); - // Serial.println(Cmd_bitstream, HEX); - + // bitstream &= 0xFFFFFFCF; // Bit 4 and 5 are left for cmd bitstream |= (Cmd_bitstream << 4); - // Serial.println("Complete bitstream"); - // Serial.println(bitstream, HEX); - // Serial.println("cmd"); - // Serial.println(cmd, HEX); // bitstream now contains the AC/NewKAKU-bits that have to be transmitted // --------------- NEWKAKU SEND ------------ - AC_Send(bitstream, cmd); + AC_Send(bitstream, Cmd_dimmer); // -------------------------------------- return true; } - #endif // Plugin_TX_004 From f87343ac0b20a35399caad7191eeaba0d1977478 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Sun, 26 Apr 2020 20:45:01 +0200 Subject: [PATCH 16/46] added PULLUP_RF_TX_DATA define To use D3 (already pulled up) pin as a RX_DATA pin --- RFLink/RFLink.h | 3 ++- RFLink/RFLink.ino | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 1c0c1302..d3ddeee1 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -30,6 +30,7 @@ // PIN Definition // +// #define PULLUP_RF_TX_DATA #ifdef ESP8266 // ESP8266 D1 Mini #define PIN_RF_RX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level @@ -37,7 +38,7 @@ #define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin #define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin #define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA D7 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_RX_DATA D3 // On this input, the 433Mhz-RF signal is received. LOW when no signal. #define PIN_RF_TX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level #define PIN_RF_TX_NMOS D6 // Low Side N-MOSFET, active on HIGH level #define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index a1a07692..4c36a465 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -128,17 +128,19 @@ void sendMsg() void enableRX() { // RX pins - pinMode(PIN_RF_RX_NA, INPUT); // Initialise in/output ports - pinMode(PIN_RF_RX_DATA, INPUT); // Initialise in/output ports - pinMode(PIN_RF_RX_NMOS, OUTPUT); // MOSFET, always output - pinMode(PIN_RF_RX_PMOS, OUTPUT); // MOSFET, always output - digitalWrite(PIN_RF_RX_NMOS, HIGH); // turn GND to RF receiver ON - digitalWrite(PIN_RF_RX_PMOS, LOW); // turn VCC to RF receiver ON - pinMode(PIN_RF_RX_GND, OUTPUT); // Initialise in/output ports - pinMode(PIN_RF_RX_VCC, OUTPUT); // Initialise in/output ports - digitalWrite(PIN_RF_RX_GND, LOW); // turn GND to RF receiver ON - digitalWrite(PIN_RF_RX_VCC, HIGH); // turn VCC to RF receiver ON + pinMode(PIN_RF_RX_NA, INPUT); // Initialise in/output ports + pinMode(PIN_RF_RX_DATA, INPUT); // Initialise in/output ports + pinMode(PIN_RF_RX_NMOS, OUTPUT); // MOSFET, always output + pinMode(PIN_RF_RX_PMOS, OUTPUT); // MOSFET, always output + digitalWrite(PIN_RF_RX_NMOS, HIGH); // turn GND to RF receiver ON + digitalWrite(PIN_RF_RX_PMOS, LOW); // turn VCC to RF receiver ON + pinMode(PIN_RF_RX_GND, OUTPUT); // Initialise in/output ports + pinMode(PIN_RF_RX_VCC, OUTPUT); // Initialise in/output ports + digitalWrite(PIN_RF_RX_GND, LOW); // turn GND to RF receiver ON + digitalWrite(PIN_RF_RX_VCC, HIGH); // turn VCC to RF receiver ON +#ifdef PULLUP_RF_TX_DATA pinMode(PIN_RF_RX_DATA, INPUT_PULLUP); // Initialise in/output ports +#endif delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); } @@ -158,7 +160,7 @@ void disableRX() void enableTX() { // TX Pins - pinMode(PIN_RF_TX_DATA, OUTPUT); // Initialise in/output ports + pinMode(PIN_RF_TX_DATA, OUTPUT); // Initialise in/output ports digitalWrite(PIN_RF_TX_DATA, LOW); // No signal yet pinMode(PIN_RF_TX_NMOS, OUTPUT); // MOSFET, always output pinMode(PIN_RF_TX_PMOS, OUTPUT); // MOSFET, always output From 94806a646000a5ae67494969355855707de2d45a Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Mon, 27 Apr 2020 19:05:44 +0200 Subject: [PATCH 17/46] build flag commented during beta --- platformio.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 4f937861..8b299589 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,7 +15,8 @@ src_dir = RFLink [env] framework = arduino monitor_speed = 57600 -build_flags = -DAC_LABELS='"${PROJECT_SRC_DIR}/9_AutoConnect.h"' ; For allowing tabs renaming in AtoConnect menu + +;build_flags = -DAC_LABELS='"${PROJECT_SRC_DIR}/9_AutoConnect.h"' ; For allowing tabs renaming in AtoConnect menu [env:d1_mini] platform = espressif8266 From 27a42b43443039de76d090b7e5eb4f74a542b79e Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Mon, 27 Apr 2020 19:06:34 +0200 Subject: [PATCH 18/46] Changed REV number and version date --- RFLink/8_OLED.cpp | 2 +- RFLink/RFLink.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RFLink/8_OLED.cpp b/RFLink/8_OLED.cpp index 4b52d909..fcef7cae 100644 --- a/RFLink/8_OLED.cpp +++ b/RFLink/8_OLED.cpp @@ -46,7 +46,7 @@ void splash_OLED() u8x8.draw2x2String(0, 0, "RFLink"); u8x8.draw2x2String(10, 2, "ESP"); u8x8.drawString(0, 3, ver); - u8x8.drawString(0, 4, "20/04/20"); + u8x8.drawString(0, 4, "01/05/20"); u8x8.drawString(6, 6, "github.com"); u8x8.drawString(2, 7, "/couin3/RFLink"); u8x8.setPowerSave(0); diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 4bf5d725..e8f3e74c 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -9,8 +9,8 @@ #define RFLink_h // -#define BUILDNR 0x01 // 0x07 // shown in version -#define REVNR 0x01 // 0X42 // shown in version and startup string +#define BUILDNR 0x04 // 0x07 // shown in version +#define REVNR 0x00 // 0X42 // shown in version and startup string #define BAUD 57600 // 57600 // Baudrate for serial communication. #define MIN_RAW_PULSES 50 // 50 // Minimal number of bits that need to have been received before we spend CPU time on decoding the signal. #define RAW_BUFFER_SIZE 292 // 292 // Maximum number of pulses that is received in one go. From 3514704c26caa622d8835c923326b9b8db8d225a Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Mon, 27 Apr 2020 19:07:06 +0200 Subject: [PATCH 19/46] New default pin settings --- RFLink/RFLink.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index e8f3e74c..047ee954 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -34,13 +34,13 @@ #ifdef ESP8266 // ESP8266 D1 Mini #define PIN_RF_RX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level -#define PIN_RF_RX_NMOS D5 // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin -#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin -#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA D3 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_RX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_RX_VCC D5 // Power to the receiver on this pin +#define PIN_RF_RX_GND D8 // Ground to the receiver on this pin +#define PIN_RF_RX_NA D6 // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_DATA D7 // On this input, the 433Mhz-RF signal is received. LOW when no signal. #define PIN_RF_TX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level -#define PIN_RF_TX_NMOS D6 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_TX_NMOS D0 // Low Side N-MOSFET, active on HIGH level #define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin #define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin #define PIN_RF_TX_DATA D4 // Data to the 433Mhz transmitter on this pin From ef582028ba288748f0bf9300ff9d636f86b30f4a Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Mon, 27 Apr 2020 19:10:44 +0200 Subject: [PATCH 20/46] MQTT merged complement --- RFLink/6_WiFi_MQTT.cpp | 25 +++++++++---------------- RFLink/9_AutoConnect.cpp | 2 ++ RFLink/RFLink.h | 6 +++--- RFLink/RFLink.ino | 22 +++++++++++++--------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/RFLink/6_WiFi_MQTT.cpp b/RFLink/6_WiFi_MQTT.cpp index b314324c..15e23fa4 100644 --- a/RFLink/6_WiFi_MQTT.cpp +++ b/RFLink/6_WiFi_MQTT.cpp @@ -39,11 +39,10 @@ WiFiClient WIFIClient; PubSubClient MQTTClient; // MQTTClient(WIFIClient); +void callback(char *, byte *, unsigned int); + #ifndef AUTOCONNECT_ENABLED static String WIFI_PWR = String(WIFI_PWR_0); -#endif - -void callback(char *, byte *, unsigned int); void setup_WIFI() { @@ -109,18 +108,18 @@ void reconnect() // Once connected, resubscribe MQTTClient.subscribe(MQTT_TOPIC_IN.c_str()); Serial.print(F("MQTT connection Established : ")); - Serial.println(clientId.c_str()); + Serial.println(MQTT_ID.c_str()); MQTTClient.subscribe(MQTT_TOPIC_IN.c_str()); } else { - Serial.print(F("Connection mqttserver : ")); + Serial.print(F("Connection MQTT_Server : ")); Serial.println(MQTT_SERVER.c_str()); - Serial.print(F("Connection Mqtt_ID : ")); + Serial.print(F("Connection MQTT_ID : ")); Serial.println(MQTT_ID.c_str()); - Serial.print(F("Connection Mqtt_Username : ")); + Serial.print(F("Connection MQTT_Username : ")); Serial.println(MQTT_USER.c_str()); - Serial.print(F("Connection Mqtt_Password : ********")); + Serial.print(F("Connection MQTT_Password : ********")); Serial.print(F("Connection failed : ")); Serial.println(MQTTClient.state()); if (!--retry) @@ -135,18 +134,15 @@ void reconnect() { // Loop until we're reconnected // delay(1); - uint8_t retry = 3; - - Serial.print(F("test")); while (!MQTTClient.connected()) { Serial.print(F("Attempting MQTT connection...")); // Attempt to connect - if (MQTTClient.connect(ac_MQTT_ID.c_str(), ac_MQTT_USER.c_str(), ac_MQTT_PSWD.c_str())) + if (MQTTClient.connect(MQTT_ID.c_str(), MQTT_USER.c_str(), MQTT_PSWD.c_str())) { Serial.println(F("Connected")); // Once connected, resubscribe - // MQTTClient.subscribe(ac_MQTT_TOPIC_IN.c_str()); + MQTTClient.subscribe(MQTT_TOPIC_IN.c_str()); } else { @@ -156,9 +152,6 @@ void reconnect() // Wait 5 seconds before retrying for (byte i = 0; i < 10; i++) delay(500); // delay(5000) may cause hang - if (!--retry) - break; - delay(500); } } } diff --git a/RFLink/9_AutoConnect.cpp b/RFLink/9_AutoConnect.cpp index c0416ec8..6767f9b1 100644 --- a/RFLink/9_AutoConnect.cpp +++ b/RFLink/9_AutoConnect.cpp @@ -451,7 +451,9 @@ String saveParams(AutoConnectAux &aux, PageArgument &args) echo.value += Adv_Power; echo.value += F("
"); +#ifdef MQTT_ENABLED setup_MQTT(); // Reload settings +#endif return String(""); } diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 047ee954..3caeddaa 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -106,9 +106,9 @@ // MQTT messages #define SERIAL_ENABLED // Send RFLink messages over Serial #if (defined(ESP32) || defined(ESP8266)) -#define MQTT_ENABLED // Send RFLink messages over MQTT -#define MQTT_LOOP_MS 1000 // MQTTClient.loop(); call period (in mSec) -#define MQTT_RETAINED false // Retained option +#define MQTT_ENABLED // Send RFLink messages over MQTT +#define MQTT_LOOP_MS 1000 // MQTTClient.loop(); call period (in mSec) +#define MQTT_RETAINED_0 false // Retained option #endif // Debug default diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index 6701dedf..f2a852b5 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -109,19 +109,23 @@ void loop() { #ifdef AUTOCONNECT_ENABLED loop_AutoConnect(); -#endif -#ifdef MQTT_ENABLED if (WiFi.status() == WL_CONNECTED) { - checkMQTTloop(); - sendMsg(); #endif - - if (CheckSerial()) +#ifdef MQTT_ENABLED + checkMQTTloop(); sendMsg(); +#endif - if (ScanEvent()) - sendMsg(); + if (CheckSerial()) + sendMsg(); + + if (ScanEvent()) + sendMsg(); + +#ifdef AUTOCONNECT_ENABLED + } +#endif } void sendMsg() @@ -135,7 +139,7 @@ void sendMsg() publishMsg(); #endif #ifdef AUTOCONNECT_ENABLED - LastMsg = pbuffer; + LastMsg = pbuffer; #endif #ifdef OLED_ENABLED print_OLED(); From 43724ab6bdad39c016d01325b886e34e98a35195 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Tue, 28 Apr 2020 00:52:51 +0200 Subject: [PATCH 21/46] New 1_Radio files ... for radio stuff --- RFLink/1_Radio.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++++ RFLink/1_Radio.h | 91 +++++++++++++++++++++++++++++++++++++++ RFLink/2_Signal.cpp | 1 + RFLink/3_Serial.cpp | 1 + RFLink/RFLink.h | 72 +------------------------------ RFLink/RFLink.ino | 68 ++--------------------------- 6 files changed, 199 insertions(+), 135 deletions(-) create mode 100644 RFLink/1_Radio.cpp create mode 100644 RFLink/1_Radio.h diff --git a/RFLink/1_Radio.cpp b/RFLink/1_Radio.cpp new file mode 100644 index 00000000..9eed9e49 --- /dev/null +++ b/RFLink/1_Radio.cpp @@ -0,0 +1,101 @@ +// ************************************* // +// * Arduino Project RFLink-esp * // +// * https://github.com/couin3/RFLink * // +// * 2018..2020 Stormteam - Marc RIVES * // +// * More details in RFLink.ino file * // +// ************************************* // + +#include +#include "1_Radio.h" + +// Prototype +void enableRX(); +void disableRX(); +void enableTX(); +void disableTX(); + +uint8_t PIN_RF_RX_PMOS = PIN_RF_RX_PMOS_0; +uint8_t PIN_RF_RX_NMOS = PIN_RF_RX_NMOS_0; +uint8_t PIN_RF_RX_VCC = PIN_RF_RX_VCC_0; +uint8_t PIN_RF_RX_GND = PIN_RF_RX_GND_0; +uint8_t PIN_RF_RX_NA = PIN_RF_RX_NA_0; +uint8_t PIN_RF_RX_DATA = PIN_RF_RX_DATA_0; +uint8_t PIN_RF_TX_PMOS = PIN_RF_TX_PMOS_0; +uint8_t PIN_RF_TX_NMOS = PIN_RF_TX_NMOS_0; +uint8_t PIN_RF_TX_VCC = PIN_RF_TX_VCC_0; +uint8_t PIN_RF_TX_GND = PIN_RF_TX_GND_0; +uint8_t PIN_RF_TX_DATA = PIN_RF_TX_DATA_0; +boolean PULLUP_RF_RX_DATA = PULLUP_RF_RX_DATA_0; + +void setmode_RX() +{ + disableTX(); + enableRX(); +} + +void setmode_TX() +{ + disableRX(); + enableTX(); +} + +void enableRX() +{ + // RX pins + pinMode(PIN_RF_RX_NA, INPUT); // Initialise in/output ports + pinMode(PIN_RF_RX_DATA, INPUT); // Initialise in/output ports + pinMode(PIN_RF_RX_NMOS, OUTPUT); // MOSFET, always output + pinMode(PIN_RF_RX_PMOS, OUTPUT); // MOSFET, always output + digitalWrite(PIN_RF_RX_NMOS, HIGH); // turn GND to RF receiver ON + digitalWrite(PIN_RF_RX_PMOS, LOW); // turn VCC to RF receiver ON + pinMode(PIN_RF_RX_GND, OUTPUT); // Initialise in/output ports + pinMode(PIN_RF_RX_VCC, OUTPUT); // Initialise in/output ports + digitalWrite(PIN_RF_RX_GND, LOW); // turn GND to RF receiver ON + digitalWrite(PIN_RF_RX_VCC, HIGH); // turn VCC to RF receiver ON + if (PULLUP_RF_RX_DATA) + pinMode(PIN_RF_RX_DATA, INPUT_PULLUP); // Initialise in/output ports + delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); +} + +void disableRX() +{ + // RX pins + pinMode(PIN_RF_RX_DATA, INPUT); + pinMode(PIN_RF_RX_NA, INPUT); + pinMode(PIN_RF_RX_PMOS, OUTPUT); // MOSFET, always output + pinMode(PIN_RF_RX_NMOS, OUTPUT); // MOSFET, always output + digitalWrite(PIN_RF_RX_PMOS, HIGH); // turn VCC to RF receiver OFF + digitalWrite(PIN_RF_RX_NMOS, LOW); // turn GND to RF receiver OFF + pinMode(PIN_RF_RX_VCC, INPUT); + pinMode(PIN_RF_RX_GND, INPUT); +} + +void enableTX() +{ + // TX Pins + pinMode(PIN_RF_TX_DATA, OUTPUT); // Initialise in/output ports + digitalWrite(PIN_RF_TX_DATA, LOW); // No signal yet + pinMode(PIN_RF_TX_NMOS, OUTPUT); // MOSFET, always output + pinMode(PIN_RF_TX_PMOS, OUTPUT); // MOSFET, always output + digitalWrite(PIN_RF_TX_NMOS, HIGH); // turn GND to TX receiver ON + digitalWrite(PIN_RF_TX_PMOS, LOW); // turn VCC to TX receiver ON + pinMode(PIN_RF_TX_GND, OUTPUT); // Initialise in/output ports + pinMode(PIN_RF_TX_VCC, OUTPUT); // Initialise in/output ports + digitalWrite(PIN_RF_TX_GND, LOW); // turn GND to TX receiver ON + digitalWrite(PIN_RF_TX_VCC, HIGH); // turn VCC to TX receiver ON + delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); +} + +void disableTX() +{ + // TX Pins + delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); + digitalWrite(PIN_RF_TX_DATA, LOW); // No more signal + pinMode(PIN_RF_TX_DATA, INPUT); // + pinMode(PIN_RF_TX_NMOS, OUTPUT); // MOSFET, always output + pinMode(PIN_RF_TX_PMOS, OUTPUT); // MOSFET, always output + digitalWrite(PIN_RF_TX_PMOS, HIGH); // turn VCC to TX receiver OFF + digitalWrite(PIN_RF_TX_NMOS, LOW); // turn GND to TX receiver OFF + pinMode(PIN_RF_TX_VCC, INPUT); + pinMode(PIN_RF_TX_GND, INPUT); +} \ No newline at end of file diff --git a/RFLink/1_Radio.h b/RFLink/1_Radio.h new file mode 100644 index 00000000..dc82252b --- /dev/null +++ b/RFLink/1_Radio.h @@ -0,0 +1,91 @@ +// ************************************* // +// * Arduino Project RFLink-esp * // +// * https://github.com/couin3/RFLink * // +// * 2018..2020 Stormteam - Marc RIVES * // +// * More details in RFLink.ino file * // +// ************************************* // + +#ifndef Radio_h +#define Radio_h + +#include + +#define TRANSMITTER_STABLE_DELAY_US 500 // 500 // Delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms). +#define PULLUP_RF_RX_DATA_0 false // false // Sometimes a pullup in needed on RX data pin + +// PIN Definition +// +extern uint8_t PIN_RF_RX_PMOS; +extern uint8_t PIN_RF_RX_NMOS; +extern uint8_t PIN_RF_RX_VCC; +extern uint8_t PIN_RF_RX_GND; +extern uint8_t PIN_RF_RX_NA; +extern uint8_t PIN_RF_RX_DATA; +extern uint8_t PIN_RF_TX_PMOS; +extern uint8_t PIN_RF_TX_NMOS; +extern uint8_t PIN_RF_TX_VCC; +extern uint8_t PIN_RF_TX_GND; +extern uint8_t PIN_RF_TX_DATA; +extern boolean PULLUP_RF_RX_DATA; + +#ifdef ESP8266 +// ESP8266 D1 Mini +#define PIN_RF_RX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_RX_NMOS_0 D5 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_RX_VCC_0 NOT_A_PIN // Power to the receiver on this pin +#define PIN_RF_RX_GND_0 NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_RX_NA_0 NOT_A_PIN // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_DATA_0 D3 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_TX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_TX_NMOS_0 D6 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_TX_VCC_0 NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin +#define PIN_RF_TX_GND_0 NOT_A_PIN // Ground power to the transmitter on this pin +#define PIN_RF_TX_DATA_0 D4 // Data to the 433Mhz transmitter on this pin +#endif + +#ifdef ESP32 +#define PIN_RF_RX_PMOS NOT_A_PIN_0 // High Side P-MOSFET, active on LOW level +#define PIN_RF_RX_NMOS NOT_A_PIN_0 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_RX_VCC NOT_A_PIN_0 // Power to the receiver on this pin +#define PIN_RF_RX_GND NOT_A_PIN_0 // Ground to the receiver on this pin +#define PIN_RF_RX_NA NOT_A_PIN_0 // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_DATA NOT_A_PIN_0 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_TX_PMOS NOT_A_PIN_0 // High Side P-MOSFET, active on LOW level +#define PIN_RF_TX_NMOS NOT_A_PIN_0 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_TX_VCC NOT_A_PIN_0 // +5 volt / Vcc power to the transmitter on this pin +#define PIN_RF_TX_GND NOT_A_PIN_0 // Ground power to the transmitter on this pin +#define PIN_RF_TX_DATA NOT_A_PIN_0 // Data to the 433Mhz transmitter on this pin +#endif + +#ifdef __AVR_ATmega328P__ +#define PIN_RF_RX_PMOS NOT_A_PIN_0 // High Side P-MOSFET, active on LOW level +#define PIN_RF_RX_NMOS NOT_A_PIN_0 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_RX_VCC NOT_A_PIN_0 // Power to the receiver on this pin +#define PIN_RF_RX_GND NOT_A_PIN_0 // Ground to the receiver on this pin +#define PIN_RF_RX_NA NOT_A_PIN_0 // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_DATA_0 2 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_TX_PMOS NOT_A_PIN_0 // High Side P-MOSFET, active on LOW level +#define PIN_RF_TX_NMOS NOT_A_PIN_0 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_TX_VCC NOT_A_PIN_0 // +5 volt / Vcc power to the transmitter on this pin +#define PIN_RF_TX_GND NOT_A_PIN_0 // Ground power to the transmitter on this pin +#define PIN_RF_TX_DATA NOT_A_PIN_0 // Data to the 433Mhz transmitter on this pin +#endif + +#ifdef __AVR_ATmega2560__ +#define PIN_RF_RX_PMOS NOT_A_PIN_0 // High Side P-MOSFET, active on LOW level +#define PIN_RF_RX_NMOS NOT_A_PIN_0 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_RX_VCC_0 16 // Power to the receiver on this pin +#define PIN_RF_RX_GND NOT_A_PIN_0 // Ground to the receiver on this pin +#define PIN_RF_RX_NA NOT_A_PIN_0 // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_DATA_0 19 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_TX_PMOS NOT_A_PIN_0 // High Side P-MOSFET, active on LOW level +#define PIN_RF_TX_NMOS NOT_A_PIN_0 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_TX_VCC_0 15 // +5 volt / Vcc power to the transmitter on this pin +#define PIN_RF_TX_GND NOT_A_PIN_0 // Ground power to the transmitter on this pin +#define PIN_RF_TX_DATA_0 14 // Data to the 433Mhz transmitter on this pin +#endif + +void setmode_RX(); +void setmode_TX(); + +#endif // Radio_h \ No newline at end of file diff --git a/RFLink/2_Signal.cpp b/RFLink/2_Signal.cpp index e5654968..f533fcdc 100644 --- a/RFLink/2_Signal.cpp +++ b/RFLink/2_Signal.cpp @@ -6,6 +6,7 @@ // ************************************* // #include +#include "1_Radio.h" #include "2_Signal.h" #include "5_Plugin.h" diff --git a/RFLink/3_Serial.cpp b/RFLink/3_Serial.cpp index 199083d2..87d1b578 100644 --- a/RFLink/3_Serial.cpp +++ b/RFLink/3_Serial.cpp @@ -7,6 +7,7 @@ #include #include "RFLink.h" +#include "1_Radio.h" #include "3_Serial.h" #include "4_Display.h" #include "5_Plugin.h" diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 3caeddaa..cc5f743e 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -20,7 +20,6 @@ #define MIN_PULSE_LENGTH_US 100 // 25! // Pulses shorter than this value in uSec. will be seen as garbage and not taken as actual pulses. #define SIGNAL_END_TIMEOUT_US 5000 // 4500 // After this time in uSec, the RF signal will be considered to have stopped. #define SIGNAL_REPEAT_TIME_MS 250 // 500 // Time in mSec. in which the same RF signal should not be accepted again. Filters out retransmits. -#define TRANSMITTER_STABLE_DELAY_US 500 // 500 // delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms). #define SCAN_HIGH_TIME_MS 50 // 50 // time interval in ms. fast processing for background tasks #define FOCUS_TIME_MS 50 // 50 // Duration in mSec. that, after receiving serial data from USB only the serial port is checked. #define PLUGIN_MAX 55 // 55 // Maximum number of Receive plugins @@ -28,74 +27,11 @@ #define INPUT_COMMAND_SIZE 60 // 60 // Maximum number of characters that a command via serial can be. #define PRINT_BUFFER_SIZE 90 // 90 // Maximum number of characters that a command should print in one go via the print buffer. -// PIN Definition -// -// #define PULLUP_RF_TX_DATA -#ifdef ESP8266 -// ESP8266 D1 Mini -#define PIN_RF_RX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level -#define PIN_RF_RX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_RX_VCC D5 // Power to the receiver on this pin -#define PIN_RF_RX_GND D8 // Ground to the receiver on this pin -#define PIN_RF_RX_NA D6 // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA D7 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_TX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level -#define PIN_RF_TX_NMOS D0 // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin -#define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin -#define PIN_RF_TX_DATA D4 // Data to the 433Mhz transmitter on this pin -#endif - -#ifdef ESP32 -#define PIN_RF_RX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level -#define PIN_RF_RX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin -#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin -#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA NOT_A_PIN // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_TX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level -#define PIN_RF_TX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin -#define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin -#define PIN_RF_TX_DATA NOT_A_PIN // Data to the 433Mhz transmitter on this pin -#endif - -#ifdef __AVR_ATmega328P__ -#define PIN_RF_RX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level -#define PIN_RF_RX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_RX_VCC NOT_A_PIN // Power to the receiver on this pin -#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin -#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA 2 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_TX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level -#define PIN_RF_TX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_TX_VCC NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin -#define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin -#define PIN_RF_TX_DATA NOT_A_PIN // Data to the 433Mhz transmitter on this pin -#endif - -#ifdef __AVR_ATmega2560__ -#define PIN_RF_RX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level -#define PIN_RF_RX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_RX_VCC 16 // Power to the receiver on this pin -#define PIN_RF_RX_GND NOT_A_PIN // Ground to the receiver on this pin -#define PIN_RF_RX_NA NOT_A_PIN // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA 19 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_TX_PMOS NOT_A_PIN // High Side P-MOSFET, active on LOW level -#define PIN_RF_TX_NMOS NOT_A_PIN // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_TX_VCC 15 // +5 volt / Vcc power to the transmitter on this pin -#define PIN_RF_TX_GND NOT_A_PIN // Ground power to the transmitter on this pin -#define PIN_RF_TX_DATA 14 // Data to the 433Mhz transmitter on this pin -#endif +#define BUILDNR 0x04 // 0x07 // shown in version +#define REVNR 0x00 // 0X42 // shown in version and startup string // OLED display, 0.91" SSD1306 I2C // #define OLED_ENABLED -#ifdef OLED_ENABLED -#define PIN_OLED_GND NOT_A_PIN // Ground power on this pin -#define PIN_OLED_VCC NOT_A_PIN // +3 volt / Vcc power on this pin# -#define PIN_OLED_SCL D1 // I2C SCL -#define PIN_OLED_SDA D2 // I2C SDA -#endif // WIFI #if (defined(ESP32) || defined(ESP8266)) @@ -118,9 +54,5 @@ #define QRFUDebug_0 false // debug RF signals with plugin 254 but no multiplication (faster?, compact) void CallReboot(void); -void enableRX(); -void disableRX(); -void enableTX(); -void disableTX(); #endif diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index f2a852b5..3f4a7ff9 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -18,6 +18,7 @@ // **************************************************************************** #include #include "RFLink.h" +#include "1_Radio.h" #include "2_Signal.h" #include "3_Serial.h" #include "4_Display.h" @@ -59,8 +60,7 @@ void setup() Serial.begin(BAUD); // Initialise the serial port Serial.println(); // ESP "Garbage" message - disableTX(); - enableRX(); + setmode_RX(); #if (!defined(AUTOCONNECT_ENABLED) && !defined(MQTT_ENABLED)) #if (defined(ESP32) || defined(ESP8266)) @@ -122,7 +122,7 @@ void loop() if (ScanEvent()) sendMsg(); - + #ifdef AUTOCONNECT_ENABLED } #endif @@ -148,66 +148,4 @@ void sendMsg() } } -void enableRX() -{ - // RX pins - pinMode(PIN_RF_RX_NA, INPUT); // Initialise in/output ports - pinMode(PIN_RF_RX_DATA, INPUT); // Initialise in/output ports - pinMode(PIN_RF_RX_NMOS, OUTPUT); // MOSFET, always output - pinMode(PIN_RF_RX_PMOS, OUTPUT); // MOSFET, always output - digitalWrite(PIN_RF_RX_NMOS, HIGH); // turn GND to RF receiver ON - digitalWrite(PIN_RF_RX_PMOS, LOW); // turn VCC to RF receiver ON - pinMode(PIN_RF_RX_GND, OUTPUT); // Initialise in/output ports - pinMode(PIN_RF_RX_VCC, OUTPUT); // Initialise in/output ports - digitalWrite(PIN_RF_RX_GND, LOW); // turn GND to RF receiver ON - digitalWrite(PIN_RF_RX_VCC, HIGH); // turn VCC to RF receiver ON -#ifdef PULLUP_RF_TX_DATA - pinMode(PIN_RF_RX_DATA, INPUT_PULLUP); // Initialise in/output ports -#endif - delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); -} - -void disableRX() -{ - // RX pins - pinMode(PIN_RF_RX_DATA, INPUT); - pinMode(PIN_RF_RX_NA, INPUT); - pinMode(PIN_RF_RX_PMOS, OUTPUT); // MOSFET, always output - pinMode(PIN_RF_RX_NMOS, OUTPUT); // MOSFET, always output - digitalWrite(PIN_RF_RX_PMOS, HIGH); // turn VCC to RF receiver OFF - digitalWrite(PIN_RF_RX_NMOS, LOW); // turn GND to RF receiver OFF - pinMode(PIN_RF_RX_VCC, INPUT); - pinMode(PIN_RF_RX_GND, INPUT); -} - -void enableTX() -{ - // TX Pins - pinMode(PIN_RF_TX_DATA, OUTPUT); // Initialise in/output ports - digitalWrite(PIN_RF_TX_DATA, LOW); // No signal yet - pinMode(PIN_RF_TX_NMOS, OUTPUT); // MOSFET, always output - pinMode(PIN_RF_TX_PMOS, OUTPUT); // MOSFET, always output - digitalWrite(PIN_RF_TX_NMOS, HIGH); // turn GND to TX receiver ON - digitalWrite(PIN_RF_TX_PMOS, LOW); // turn VCC to TX receiver ON - pinMode(PIN_RF_TX_GND, OUTPUT); // Initialise in/output ports - pinMode(PIN_RF_TX_VCC, OUTPUT); // Initialise in/output ports - digitalWrite(PIN_RF_TX_GND, LOW); // turn GND to TX receiver ON - digitalWrite(PIN_RF_TX_VCC, HIGH); // turn VCC to TX receiver ON - delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); -} - -void disableTX() -{ - // TX Pins - delayMicroseconds(TRANSMITTER_STABLE_DELAY_US); - digitalWrite(PIN_RF_TX_DATA, LOW); // No more signal - pinMode(PIN_RF_TX_DATA, INPUT); // - pinMode(PIN_RF_TX_NMOS, OUTPUT); // MOSFET, always output - pinMode(PIN_RF_TX_PMOS, OUTPUT); // MOSFET, always output - digitalWrite(PIN_RF_TX_PMOS, HIGH); // turn VCC to TX receiver OFF - digitalWrite(PIN_RF_TX_NMOS, LOW); // turn GND to TX receiver OFF - pinMode(PIN_RF_TX_VCC, INPUT); - pinMode(PIN_RF_TX_GND, INPUT); -} - /*********************************************************************************************/ From 481c778773f4e0ab6738d56ff0c9a0564cddce8b Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Tue, 28 Apr 2020 00:54:44 +0200 Subject: [PATCH 22/46] Moved signal specific define to 2_Signal.h --- RFLink/2_Signal.h | 11 ++++++++++- RFLink/RFLink.h | 9 --------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/RFLink/2_Signal.h b/RFLink/2_Signal.h index 6655b862..31a86ae8 100644 --- a/RFLink/2_Signal.h +++ b/RFLink/2_Signal.h @@ -9,7 +9,16 @@ #define Signal_h #include -#include "RFLink.h" + +#define RAW_BUFFER_SIZE 292 // 292 // Maximum number of pulses that is received in one go. +#define MIN_RAW_PULSES 50 // 50 // Minimal number of bits that need to have been received before we spend CPU time on decoding the signal. +#define RAWSIGNAL_SAMPLE_RATE 32 // 32 // =8 bits. Sample width / resolution in uSec for raw RF pulses. +#define SIGNAL_SEEK_TIMEOUT_MS 25 // 25 // After this time in mSec, RF signal will be considered absent. +#define SIGNAL_MIN_PREAMBLE_US 3000 // 3000 // After this time in mSec, a RF signal will be considered to have started. +#define MIN_PULSE_LENGTH_US 100 // 25! // Pulses shorter than this value in uSec. will be seen as garbage and not taken as actual pulses. +#define SIGNAL_END_TIMEOUT_US 5000 // 4500 // After this time in uSec, the RF signal will be considered to have stopped. +#define SIGNAL_REPEAT_TIME_MS 250 // 500 // Time in mSec. in which the same RF signal should not be accepted again. Filters out retransmits. +#define SCAN_HIGH_TIME_MS 50 // 50 // time interval in ms. fast processing for background tasks struct RawSignalStruct // Raw signal variabelen places in a struct { diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index cc5f743e..8952d40d 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -12,15 +12,6 @@ #define BUILDNR 0x04 // 0x07 // shown in version #define REVNR 0x00 // 0X42 // shown in version and startup string #define BAUD 57600 // 57600 // Baudrate for serial communication. -#define MIN_RAW_PULSES 50 // 50 // Minimal number of bits that need to have been received before we spend CPU time on decoding the signal. -#define RAW_BUFFER_SIZE 292 // 292 // Maximum number of pulses that is received in one go. -#define RAWSIGNAL_SAMPLE_RATE 32 // 32 // =8 bits. Sample width / resolution in uSec for raw RF pulses. -#define SIGNAL_SEEK_TIMEOUT_MS 25 // 25 // After this time in mSec, RF signal will be considered absent. -#define SIGNAL_MIN_PREAMBLE_US 3000 // 3000 // After this time in mSec, a RF signal will be considered to have started. -#define MIN_PULSE_LENGTH_US 100 // 25! // Pulses shorter than this value in uSec. will be seen as garbage and not taken as actual pulses. -#define SIGNAL_END_TIMEOUT_US 5000 // 4500 // After this time in uSec, the RF signal will be considered to have stopped. -#define SIGNAL_REPEAT_TIME_MS 250 // 500 // Time in mSec. in which the same RF signal should not be accepted again. Filters out retransmits. -#define SCAN_HIGH_TIME_MS 50 // 50 // time interval in ms. fast processing for background tasks #define FOCUS_TIME_MS 50 // 50 // Duration in mSec. that, after receiving serial data from USB only the serial port is checked. #define PLUGIN_MAX 55 // 55 // Maximum number of Receive plugins #define PLUGIN_TX_MAX 5 // 26 // Maximum number of Transmit plugins From b2a36b474a94e0019e2de1d1b05194e4fa93632d Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Tue, 28 Apr 2020 00:55:57 +0200 Subject: [PATCH 23/46] Moved plugin specific define to 5_plugin.h and code formatting --- RFLink/5_Plugin.h | 14 ++++++++++---- RFLink/RFLink.h | 2 -- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/RFLink/5_Plugin.h b/RFLink/5_Plugin.h index c5f12c71..6f50e0f6 100644 --- a/RFLink/5_Plugin.h +++ b/RFLink/5_Plugin.h @@ -10,7 +10,16 @@ #include -enum PState {P_Forbidden, P_Disabled, P_Enabled, P_Mandatory}; +#define PLUGIN_MAX 55 // 55 // Maximum number of Receive plugins +#define PLUGIN_TX_MAX 5 // 26 // Maximum number of Transmit plugins + +enum PState +{ + P_Forbidden, + P_Disabled, + P_Enabled, + P_Mandatory +}; extern boolean (*Plugin_ptr[PLUGIN_MAX])(byte, char *); // Receive plugins extern byte Plugin_id[PLUGIN_MAX]; @@ -26,9 +35,6 @@ extern boolean QRFDebug; // debug RF signals with plugin 001 but no multiplicat extern boolean RFUDebug; // debug RF signals with plugin 254 (decode 1st) extern boolean QRFUDebug; // debug RF signals with plugin 254 but no multiplication (faster?, compact) -// void(*Reboot)(void) = 0; -// boolean (*Plugin_ptr[PLUGIN_MAX])(byte, char*); - // Of all the devices that are compiled, the addresses are stored in a table so that you can jump to them void PluginInit(void); void PluginTXInit(void); diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 8952d40d..02e4ff42 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -13,8 +13,6 @@ #define REVNR 0x00 // 0X42 // shown in version and startup string #define BAUD 57600 // 57600 // Baudrate for serial communication. #define FOCUS_TIME_MS 50 // 50 // Duration in mSec. that, after receiving serial data from USB only the serial port is checked. -#define PLUGIN_MAX 55 // 55 // Maximum number of Receive plugins -#define PLUGIN_TX_MAX 5 // 26 // Maximum number of Transmit plugins #define INPUT_COMMAND_SIZE 60 // 60 // Maximum number of characters that a command via serial can be. #define PRINT_BUFFER_SIZE 90 // 90 // Maximum number of characters that a command should print in one go via the print buffer. From 1e62276aa092e34318f04aa49b17f0d887b467e5 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Tue, 28 Apr 2020 00:57:12 +0200 Subject: [PATCH 24/46] Moved OLED specific define to 8_OLED.h --- RFLink/8_OLED.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RFLink/8_OLED.h b/RFLink/8_OLED.h index 95751793..f33e9205 100644 --- a/RFLink/8_OLED.h +++ b/RFLink/8_OLED.h @@ -13,6 +13,11 @@ #ifdef OLED_ENABLED +#define PIN_OLED_GND NOT_A_PIN // Ground power on this pin +#define PIN_OLED_VCC NOT_A_PIN // +3 volt / Vcc power on this pin# +#define PIN_OLED_SCL D1 // I2C SCL +#define PIN_OLED_SDA D2 // I2C SDA + void setup_OLED(); void splash_OLED(); void print_OLED(); From 3fddcdd1c82b8962a3701455cac2b3fe26f9ba3b Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Tue, 28 Apr 2020 00:58:30 +0200 Subject: [PATCH 25/46] Moved Serial specific define to 3_Serial.h --- RFLink/3_Serial.cpp | 6 ++---- RFLink/3_Serial.h | 5 ++++- RFLink/RFLink.h | 3 --- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/RFLink/3_Serial.cpp b/RFLink/3_Serial.cpp index 87d1b578..f21ae246 100644 --- a/RFLink/3_Serial.cpp +++ b/RFLink/3_Serial.cpp @@ -203,14 +203,12 @@ boolean CheckCmd() // ------------------------------------------------------- // Handle Generic Commands / Translate protocol data into Nodo text commands // ------------------------------------------------------- - disableRX(); - enableTX(); + setmode_TX(); if (PluginTXCall(0, InputBuffer_Serial)) ValidCommand = 1; else // Answer that an invalid command was received? ValidCommand = 2; - disableTX(); - enableRX(); + setmode_RX(); } } } // if > 7 diff --git a/RFLink/3_Serial.h b/RFLink/3_Serial.h index fe403bd8..e74b0937 100644 --- a/RFLink/3_Serial.h +++ b/RFLink/3_Serial.h @@ -9,7 +9,10 @@ #define Serial_h #include -#include "RFLink.h" + +#define BAUD 57600 // 57600 // Baudrate for serial communication. +#define INPUT_COMMAND_SIZE 60 // 60 // Maximum number of characters that a command via serial can be. +#define FOCUS_TIME_MS 50 // 50 // Duration in mSec. that, after receiving serial data from USB only the serial port is checked. extern char InputBuffer_Serial[INPUT_COMMAND_SIZE]; diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 02e4ff42..9254795a 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -11,9 +11,6 @@ // #define BUILDNR 0x04 // 0x07 // shown in version #define REVNR 0x00 // 0X42 // shown in version and startup string -#define BAUD 57600 // 57600 // Baudrate for serial communication. -#define FOCUS_TIME_MS 50 // 50 // Duration in mSec. that, after receiving serial data from USB only the serial port is checked. -#define INPUT_COMMAND_SIZE 60 // 60 // Maximum number of characters that a command via serial can be. #define PRINT_BUFFER_SIZE 90 // 90 // Maximum number of characters that a command should print in one go via the print buffer. #define BUILDNR 0x04 // 0x07 // shown in version From 643e2d3903a32ebaa5b6aee2074bcb06bac84160 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Tue, 28 Apr 2020 00:59:19 +0200 Subject: [PATCH 26/46] Moved display specific define to 4_Display.h --- RFLink/4_Display.cpp | 1 + RFLink/4_Display.h | 3 ++- RFLink/RFLink.h | 3 --- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/RFLink/4_Display.cpp b/RFLink/4_Display.cpp index 1b0cd6ed..3d2e597a 100644 --- a/RFLink/4_Display.cpp +++ b/RFLink/4_Display.cpp @@ -6,6 +6,7 @@ // ************************************* // #include +#include "RFLink.h" #include "3_Serial.h" #include "4_Display.h" diff --git a/RFLink/4_Display.h b/RFLink/4_Display.h index 2ff51672..de6c7208 100644 --- a/RFLink/4_Display.h +++ b/RFLink/4_Display.h @@ -9,7 +9,8 @@ #define Misc_h #include -#include "RFLink.h" + +#define PRINT_BUFFER_SIZE 90 // 90 // Maximum number of characters that a command should print in one go via the print buffer. // extern byte PKSequenceNumber; // 1 byte packet counter extern char pbuffer[PRINT_BUFFER_SIZE]; // Buffer for printing data diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index 9254795a..e9f3cf83 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -8,11 +8,8 @@ #ifndef RFLink_h #define RFLink_h -// #define BUILDNR 0x04 // 0x07 // shown in version #define REVNR 0x00 // 0X42 // shown in version and startup string -#define PRINT_BUFFER_SIZE 90 // 90 // Maximum number of characters that a command should print in one go via the print buffer. - #define BUILDNR 0x04 // 0x07 // shown in version #define REVNR 0x00 // 0X42 // shown in version and startup string From 77dbfc16320e35626162c96354bb9ecb38ca7105 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Tue, 28 Apr 2020 00:59:41 +0200 Subject: [PATCH 27/46] Minor code formatting --- RFLink/5_Plugin.cpp | 9 ++-- RFLink/7_Utils.cpp | 118 ++++++++++++++++++++++++++++++-------------- RFLink/7_Utils.h | 4 +- RFLink/8_OLED.cpp | 1 + RFLink/RFLink.h | 2 - 5 files changed, 86 insertions(+), 48 deletions(-) diff --git a/RFLink/5_Plugin.cpp b/RFLink/5_Plugin.cpp index 6fa6ab7f..e0edc04d 100644 --- a/RFLink/5_Plugin.cpp +++ b/RFLink/5_Plugin.cpp @@ -9,8 +9,8 @@ #include "RFLink.h" #include "2_Signal.h" #include "5_Plugin.h" -#include //used to store current plugins states -#include // To save MQTT parameters +//#include //used to store current plugins states +#include // To save MQTT parameters #include boolean (*Plugin_ptr[PLUGIN_MAX])(byte, char *); // Receive plugins @@ -1311,7 +1311,6 @@ void PluginInit(void) Plugin_ptr[x++] = &Plugin_255; #endif - // read config file to desactivated protocols #ifdef AUTOCONNECT_ENABLED Serial.println("mounting FS..."); @@ -1340,17 +1339,15 @@ void PluginInit(void) { Serial.println(F("Failed to read file, using default configuration")); } - for (x = 0; x < PLUGIN_MAX; x++) - { + { if (doc[x][String(Plugin_id[x])] == 0) { Plugin_State[x] = P_Disabled; } } configFile.close(); - } } } diff --git a/RFLink/7_Utils.cpp b/RFLink/7_Utils.cpp index 1990c7ca..9714c7a6 100644 --- a/RFLink/7_Utils.cpp +++ b/RFLink/7_Utils.cpp @@ -24,7 +24,8 @@ uint8_t reverse8(uint8_t x) void reflect_bytes(uint8_t message[], unsigned num_bytes) { - for (unsigned i = 0; i < num_bytes; ++i) { + for (unsigned i = 0; i < num_bytes; ++i) + { message[i] = reverse8(message[i]); } } @@ -38,7 +39,8 @@ uint8_t reflect4(uint8_t x) void reflect_nibbles(uint8_t message[], unsigned num_bytes) { - for (unsigned i = 0; i < num_bytes; ++i) { + for (unsigned i = 0; i < num_bytes; ++i) + { message[i] = reflect4(message[i]); } } @@ -47,7 +49,8 @@ unsigned extract_nibbles_4b1s(uint8_t *message, unsigned offset_bits, unsigned n { unsigned ret = 0; - while (num_bits >= 5) { + while (num_bits >= 5) + { uint16_t bits = (message[offset_bits / 8] << 8) | message[(offset_bits / 8) + 1]; bits >>= 11 - (offset_bits % 8); // align 5 bits to LSB if ((bits & 1) != 1) @@ -67,12 +70,17 @@ uint8_t crc4(uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8 unsigned poly = polynomial << 4; unsigned bit; - while (nBytes--) { + while (nBytes--) + { remainder ^= *message++; - for (bit = 0; bit < 8; bit++) { - if (remainder & 0x80) { + for (bit = 0; bit < 8; bit++) + { + if (remainder & 0x80) + { remainder = (remainder << 1) ^ poly; - } else { + } + else + { remainder = (remainder << 1); } } @@ -86,12 +94,17 @@ uint8_t crc7(uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8 unsigned poly = polynomial << 1; unsigned byte, bit; - for (byte = 0; byte < nBytes; ++byte) { + for (byte = 0; byte < nBytes; ++byte) + { remainder ^= message[byte]; - for (bit = 0; bit < 8; ++bit) { - if (remainder & 0x80) { + for (bit = 0; bit < 8; ++bit) + { + if (remainder & 0x80) + { remainder = (remainder << 1) ^ poly; - } else { + } + else + { remainder = (remainder << 1); } } @@ -104,12 +117,17 @@ uint8_t crc8(uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8 uint8_t remainder = init; unsigned byte, bit; - for (byte = 0; byte < nBytes; ++byte) { + for (byte = 0; byte < nBytes; ++byte) + { remainder ^= message[byte]; - for (bit = 0; bit < 8; ++bit) { - if (remainder & 0x80) { + for (bit = 0; bit < 8; ++bit) + { + if (remainder & 0x80) + { remainder = (remainder << 1) ^ polynomial; - } else { + } + else + { remainder = (remainder << 1); } } @@ -123,12 +141,17 @@ uint8_t crc8le(uint8_t const message[], unsigned nBytes, uint8_t polynomial, uin unsigned byte, bit; polynomial = reverse8(polynomial); - for (byte = 0; byte < nBytes; ++byte) { + for (byte = 0; byte < nBytes; ++byte) + { remainder ^= message[byte]; - for (bit = 0; bit < 8; ++bit) { - if (remainder & 1) { + for (bit = 0; bit < 8; ++bit) + { + if (remainder & 1) + { remainder = (remainder >> 1) ^ polynomial; - } else { + } + else + { remainder = (remainder >> 1); } } @@ -141,13 +164,17 @@ uint16_t crc16lsb(uint8_t const message[], unsigned nBytes, uint16_t polynomial, uint16_t remainder = init; unsigned byte, bit; - for (byte = 0; byte < nBytes; ++byte) { + for (byte = 0; byte < nBytes; ++byte) + { remainder ^= message[byte]; - for (bit = 0; bit < 8; ++bit) { - if (remainder & 1) { + for (bit = 0; bit < 8; ++bit) + { + if (remainder & 1) + { remainder = (remainder >> 1) ^ polynomial; } - else { + else + { remainder = (remainder >> 1); } } @@ -160,13 +187,17 @@ uint16_t crc16(uint8_t const message[], unsigned nBytes, uint16_t polynomial, ui uint16_t remainder = init; unsigned byte, bit; - for (byte = 0; byte < nBytes; ++byte) { + for (byte = 0; byte < nBytes; ++byte) + { remainder ^= message[byte] << 8; - for (bit = 0; bit < 8; ++bit) { - if (remainder & 0x8000) { + for (bit = 0; bit < 8; ++bit) + { + if (remainder & 0x8000) + { remainder = (remainder << 1) ^ polynomial; } - else { + else + { remainder = (remainder << 1); } } @@ -177,9 +208,11 @@ uint16_t crc16(uint8_t const message[], unsigned nBytes, uint16_t polynomial, ui uint8_t lfsr_digest8(uint8_t const message[], unsigned bytes, uint8_t gen, uint8_t key) { uint8_t sum = 0; - for (unsigned k = 0; k < bytes; ++k) { + for (unsigned k = 0; k < bytes; ++k) + { uint8_t data = message[k]; - for (int i = 7; i >= 0; --i) { + for (int i = 7; i >= 0; --i) + { // fprintf(stderr, "key is %02x\n", key); // XOR key into sum if data bit is set if ((data >> i) & 1) @@ -200,13 +233,16 @@ uint8_t lfsr_digest8_reflect(uint8_t const message[], int bytes, uint8_t gen, ui { uint8_t sum = 0; // Process message from last byte to first byte (reflected) - for (int k = bytes - 1; k >= 0; --k) { + for (int k = bytes - 1; k >= 0; --k) + { uint8_t data = message[k]; // Process individual bits of each byte (reflected) - for (int i = 0; i < 8; ++i) { + for (int i = 0; i < 8; ++i) + { // fprintf(stderr, "key is %02x\n", key); // XOR key into sum if data bit is set - if ((data >> i) & 1) { + if ((data >> i) & 1) + { sum ^= key; } @@ -224,7 +260,8 @@ uint8_t lfsr_digest8_reflect(uint8_t const message[], int bytes, uint8_t gen, ui uint16_t lfsr_digest16(uint32_t data, int bits, uint16_t gen, uint16_t key) { uint16_t sum = 0; - for (int bit = bits - 1; bit >= 0; --bit) { + for (int bit = bits - 1; bit >= 0; --bit) + { // fprintf(stderr, "key at bit %d : %04x\n", bit, key); // if data bit is set then xor with key if ((data >> bit) & 1) @@ -281,7 +318,8 @@ int parity8(uint8_t byte) int parity_bytes(uint8_t const message[], unsigned num_bytes) { int result = 0; - for (unsigned i = 0; i < num_bytes; ++i) { + for (unsigned i = 0; i < num_bytes; ++i) + { result ^= parity8(message[i]); } return result; @@ -290,7 +328,8 @@ int parity_bytes(uint8_t const message[], unsigned num_bytes) uint8_t xor_bytes(uint8_t const message[], unsigned num_bytes) { uint8_t result = 0; - for (unsigned i = 0; i < num_bytes; ++i) { + for (unsigned i = 0; i < num_bytes; ++i) + { result ^= message[i]; } return result; @@ -299,7 +338,8 @@ uint8_t xor_bytes(uint8_t const message[], unsigned num_bytes) int add_bytes(uint8_t const message[], unsigned num_bytes) { int result = 0; - for (unsigned i = 0; i < num_bytes; ++i) { + for (unsigned i = 0; i < num_bytes; ++i) + { result += message[i]; } return result; @@ -308,7 +348,8 @@ int add_bytes(uint8_t const message[], unsigned num_bytes) int add_nibbles(uint8_t const message[], unsigned num_bytes) { int result = 0; - for (unsigned i = 0; i < num_bytes; ++i) { + for (unsigned i = 0; i < num_bytes; ++i) + { result += (message[i] >> 4) + (message[i] & 0x0f); } return result; @@ -316,7 +357,8 @@ int add_nibbles(uint8_t const message[], unsigned num_bytes) // Unit testing #ifdef _TEST -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ fprintf(stderr, "util:: test\n"); uint8_t msg[] = {0x08, 0x0a, 0xe8, 0x80}; diff --git a/RFLink/7_Utils.h b/RFLink/7_Utils.h index a0e3b541..04d8d17b 100644 --- a/RFLink/7_Utils.h +++ b/RFLink/7_Utils.h @@ -16,10 +16,10 @@ // Helper macros, collides with MSVC's stdlib.h unless NOMINMAX is used #ifndef MAX -#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif #ifndef MIN -#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif /// Reverse (reflect) the bits in an 8 bit byte. diff --git a/RFLink/8_OLED.cpp b/RFLink/8_OLED.cpp index fcef7cae..0bc06800 100644 --- a/RFLink/8_OLED.cpp +++ b/RFLink/8_OLED.cpp @@ -7,6 +7,7 @@ #include #include "RFLink.h" +#include "8_OLED.h" #ifdef OLED_ENABLED diff --git a/RFLink/RFLink.h b/RFLink/RFLink.h index e9f3cf83..d1fcd68c 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -8,8 +8,6 @@ #ifndef RFLink_h #define RFLink_h -#define BUILDNR 0x04 // 0x07 // shown in version -#define REVNR 0x00 // 0X42 // shown in version and startup string #define BUILDNR 0x04 // 0x07 // shown in version #define REVNR 0x00 // 0X42 // shown in version and startup string From f82ba3cbe42e5d09dfdbe35ba8116412ac4abcb3 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Tue, 28 Apr 2020 09:34:36 +0200 Subject: [PATCH 28/46] New set_Radio_mode func Also Radio_State enum And current_State global var --- RFLink/1_Radio.cpp | 46 +++++++++++++++++++++++++++++++-------------- RFLink/1_Radio.h | 11 +++++++++-- RFLink/3_Serial.cpp | 6 ++++-- RFLink/RFLink.ino | 5 +++-- 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/RFLink/1_Radio.cpp b/RFLink/1_Radio.cpp index 9eed9e49..345d0424 100644 --- a/RFLink/1_Radio.cpp +++ b/RFLink/1_Radio.cpp @@ -8,12 +8,6 @@ #include #include "1_Radio.h" -// Prototype -void enableRX(); -void disableRX(); -void enableTX(); -void disableTX(); - uint8_t PIN_RF_RX_PMOS = PIN_RF_RX_PMOS_0; uint8_t PIN_RF_RX_NMOS = PIN_RF_RX_NMOS_0; uint8_t PIN_RF_RX_VCC = PIN_RF_RX_VCC_0; @@ -27,16 +21,40 @@ uint8_t PIN_RF_TX_GND = PIN_RF_TX_GND_0; uint8_t PIN_RF_TX_DATA = PIN_RF_TX_DATA_0; boolean PULLUP_RF_RX_DATA = PULLUP_RF_RX_DATA_0; -void setmode_RX() -{ - disableTX(); - enableRX(); -} +// Prototype +void enableRX(); +void disableRX(); +void enableTX(); +void disableTX(); -void setmode_TX() +Radio_State current_State = Radio_NA; + +void set_Radio_mode(Radio_State new_State) { - disableRX(); - enableTX(); + if (current_State != new_State) + { + switch (new_State) + { + case Radio_OFF: + disableTX(); + disableRX(); + break; + + case Radio_RX: + disableTX(); + enableRX(); + break; + + case Radio_TX: + disableRX(); + enableTX(); + break; + + case Radio_NA: + break; + } + current_State = new_State; + } } void enableRX() diff --git a/RFLink/1_Radio.h b/RFLink/1_Radio.h index dc82252b..e5889712 100644 --- a/RFLink/1_Radio.h +++ b/RFLink/1_Radio.h @@ -85,7 +85,14 @@ extern boolean PULLUP_RF_RX_DATA; #define PIN_RF_TX_DATA_0 14 // Data to the 433Mhz transmitter on this pin #endif -void setmode_RX(); -void setmode_TX(); +enum Radio_State +{ + Radio_OFF, + Radio_RX, + Radio_TX, + Radio_NA +}; + +void set_Radio_mode(Radio_State new_state); #endif // Radio_h \ No newline at end of file diff --git a/RFLink/3_Serial.cpp b/RFLink/3_Serial.cpp index f21ae246..4f817af2 100644 --- a/RFLink/3_Serial.cpp +++ b/RFLink/3_Serial.cpp @@ -203,12 +203,14 @@ boolean CheckCmd() // ------------------------------------------------------- // Handle Generic Commands / Translate protocol data into Nodo text commands // ------------------------------------------------------- - setmode_TX(); + set_Radio_mode(Radio_TX); + if (PluginTXCall(0, InputBuffer_Serial)) ValidCommand = 1; else // Answer that an invalid command was received? ValidCommand = 2; - setmode_RX(); + + set_Radio_mode(Radio_RX); } } } // if > 7 diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index 3f4a7ff9..72a9d3be 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -60,7 +60,7 @@ void setup() Serial.begin(BAUD); // Initialise the serial port Serial.println(); // ESP "Garbage" message - setmode_RX(); + set_Radio_mode(Radio_OFF); #if (!defined(AUTOCONNECT_ENABLED) && !defined(MQTT_ENABLED)) #if (defined(ESP32) || defined(ESP8266)) @@ -102,7 +102,8 @@ void setup() PluginInit(); PluginTXInit(); - delay(100); + + set_Radio_mode(Radio_RX); } void loop() From 705302738ea272663cff60fc9cfd1c07402c3a54 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Tue, 28 Apr 2020 11:33:27 +0200 Subject: [PATCH 29/46] Added more #ifdef SERIAL_ENABLED --- RFLink/3_Serial.cpp | 4 ++++ RFLink/RFLink.ino | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/RFLink/3_Serial.cpp b/RFLink/3_Serial.cpp index 4f817af2..f3dc6c28 100644 --- a/RFLink/3_Serial.cpp +++ b/RFLink/3_Serial.cpp @@ -23,9 +23,11 @@ boolean CheckSerial() { if (ReadSerial()) { +#ifdef SERIAL_ENABLED Serial.flush(); Serial.print(F("Message arrived [Serial] ")); Serial.println(InputBuffer_Serial); +#endif if (CheckCmd()) return true; } @@ -36,9 +38,11 @@ boolean CheckMQTT(byte *mqtt_in) { if (CopySerial((char *)mqtt_in)) { +#ifdef SERIAL_ENABLED Serial.flush(); Serial.print(F("Message arrived [MQTT] ")); Serial.println(InputBuffer_Serial); +#endif if (CheckCmd()) return true; } diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index 72a9d3be..6f9fbeb5 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -102,7 +102,7 @@ void setup() PluginInit(); PluginTXInit(); - + set_Radio_mode(Radio_RX); } @@ -118,8 +118,10 @@ void loop() sendMsg(); #endif +#ifdef SERIAL_ENABLED if (CheckSerial()) sendMsg(); +#endif if (ScanEvent()) sendMsg(); From 0d09a082a76012c589e4841df2c7278c15bc8722 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Tue, 28 Apr 2020 17:17:07 +0200 Subject: [PATCH 30/46] Added GPIO Radio Pin in Webserver configuration menu Plus 2 helper functions uint8_t String2GPIO(String); String GPIO2String(uint8_t uGPIO); --- RFLink/1_Radio.cpp | 6 +- RFLink/4_Display.cpp | 88 ++++++++++++++++++++++++- RFLink/4_Display.h | 3 + RFLink/6_WiFi_MQTT.cpp | 4 +- RFLink/6_WiFi_MQTT.h | 15 ++++- RFLink/9_AutoConnect.cpp | 86 +++++++++++++++++++++++-- RFLink/9_AutoConnect.h | 136 ++++++++++++++++++++++++++++++++++----- 7 files changed, 310 insertions(+), 28 deletions(-) diff --git a/RFLink/1_Radio.cpp b/RFLink/1_Radio.cpp index 345d0424..a91dacbc 100644 --- a/RFLink/1_Radio.cpp +++ b/RFLink/1_Radio.cpp @@ -6,8 +6,11 @@ // ************************************* // #include +#include "RFLink.h" #include "1_Radio.h" - +#ifdef AUTOCONNECT_ENABLED +#include "9_AutoConnect.h" +#else uint8_t PIN_RF_RX_PMOS = PIN_RF_RX_PMOS_0; uint8_t PIN_RF_RX_NMOS = PIN_RF_RX_NMOS_0; uint8_t PIN_RF_RX_VCC = PIN_RF_RX_VCC_0; @@ -20,6 +23,7 @@ uint8_t PIN_RF_TX_VCC = PIN_RF_TX_VCC_0; uint8_t PIN_RF_TX_GND = PIN_RF_TX_GND_0; uint8_t PIN_RF_TX_DATA = PIN_RF_TX_DATA_0; boolean PULLUP_RF_RX_DATA = PULLUP_RF_RX_DATA_0; +#endif //AUTOCONNECT_ENABLED // Prototype void enableRX(); diff --git a/RFLink/4_Display.cpp b/RFLink/4_Display.cpp index 3d2e597a..aafedf59 100644 --- a/RFLink/4_Display.cpp +++ b/RFLink/4_Display.cpp @@ -547,4 +547,90 @@ int str2cmd(char *command) // *ix++ = rep; // n++; // } -// } \ No newline at end of file +// } + +uint8_t String2GPIO(String sGPIO) +{ + byte num_part; + char cGPIO[4]; + + sGPIO.toCharArray(cGPIO, 4); + + if (strlen(cGPIO) != 2) + return NOT_A_PIN; + if (cGPIO[0] != 'D') + return NOT_A_PIN; + if (isdigit(cGPIO[1])) + num_part = (cGPIO[1] - '0'); + else + return NOT_A_PIN; + + switch (num_part) + { + case 0: + return D0; + break; + case 1: + return D1; + break; + case 2: + return D2; + break; + case 3: + return D3; + break; + case 4: + return D4; + break; + case 5: + return D5; + break; + case 6: + return D6; + break; + case 7: + return D7; + break; + case 8: + return D8; + break; + default: + return NOT_A_PIN; + } +} + +String GPIO2String(uint8_t uGPIO) +{ + switch (uGPIO) + { + case D0: + return "D0"; + break; + case D1: + return "D1"; + break; + case D2: + return "D2"; + break; + case D3: + return "D3"; + break; + case D4: + return "D4"; + break; + case D5: + return "D5"; + break; + case D6: + return "D6"; + break; + case D7: + return "D7"; + break; + case D8: + return "D8"; + break; + default: + return "NOT_A_PIN"; + } +} \ No newline at end of file diff --git a/RFLink/4_Display.h b/RFLink/4_Display.h index de6c7208..0e86929a 100644 --- a/RFLink/4_Display.h +++ b/RFLink/4_Display.h @@ -105,4 +105,7 @@ boolean retrieve_End(); int str2cmd(char *); // void replacechar(char *, char, char); +uint8_t String2GPIO(String); +String GPIO2String(uint8_t uGPIO); + #endif \ No newline at end of file diff --git a/RFLink/6_WiFi_MQTT.cpp b/RFLink/6_WiFi_MQTT.cpp index 15e23fa4..db5dd838 100644 --- a/RFLink/6_WiFi_MQTT.cpp +++ b/RFLink/6_WiFi_MQTT.cpp @@ -10,9 +10,7 @@ #include "3_Serial.h" #include "4_Display.h" #include "6_WiFi_MQTT.h" -#ifndef AUTOCONNECT_ENABLED -#include "6_Credentials.h" -#else +#ifdef AUTOCONNECT_ENABLED #include "9_AutoConnect.h" #endif diff --git a/RFLink/6_WiFi_MQTT.h b/RFLink/6_WiFi_MQTT.h index 8ded26d2..dd7f42dc 100644 --- a/RFLink/6_WiFi_MQTT.h +++ b/RFLink/6_WiFi_MQTT.h @@ -11,7 +11,20 @@ #include #include "RFLink.h" -#ifndef AUTOCONNECT_ENABLED +#ifdef AUTOCONNECT_ENABLED +extern String MQTT_SERVER; +extern String MQTT_PORT; +extern String MQTT_ID; +extern String MQTT_USER; +extern String MQTT_PSWD; +extern String MQTT_TOPIC_OUT; +extern String MQTT_TOPIC_IN; +extern boolean MQTT_RETAINED; +extern String Adv_HostName; +extern String Adv_Power; +extern String LastMsg; +#else +#include "6_Credentials.h" #ifdef ESP32 #include #elif ESP8266 diff --git a/RFLink/9_AutoConnect.cpp b/RFLink/9_AutoConnect.cpp index 6767f9b1..29bfe000 100644 --- a/RFLink/9_AutoConnect.cpp +++ b/RFLink/9_AutoConnect.cpp @@ -8,6 +8,7 @@ #include #include #include "RFLink.h" +#include "1_Radio.h" #include "4_Display.h" // To allow displaying the last message #include "5_Plugin.h" #include "6_WiFi_MQTT.h" @@ -47,11 +48,33 @@ boolean MQTT_RETAINED; String Adv_HostName; String Adv_Power; String LastMsg; +// Radio pins settings +uint8_t PIN_RF_RX_PMOS; +uint8_t PIN_RF_RX_NMOS; +uint8_t PIN_RF_RX_VCC; +uint8_t PIN_RF_RX_GND; +uint8_t PIN_RF_RX_NA; +uint8_t PIN_RF_RX_DATA; +boolean PULLUP_RF_RX_DATA; +uint8_t PIN_RF_TX_PMOS; +uint8_t PIN_RF_TX_NMOS; +uint8_t PIN_RF_TX_VCC; +uint8_t PIN_RF_TX_GND; +uint8_t PIN_RF_TX_DATA; // Prototypes String loadParams(AutoConnectAux &aux, PageArgument &args); String saveParams(AutoConnectAux &aux, PageArgument &args); +void get_GPIO(String sGPIO) +{ + + sGPIO.trim(); + Serial.print("sGPIO *"); + Serial.print(sGPIO); + Serial.println("*"); +} + void rootPage() { @@ -164,14 +187,14 @@ void rootPage() ""; //// Graphical icon to access network config - //" "; - // "

RFLink-ESP " AUTOCONNECT_LINK(COG_32) "


"; + // ""; + // "

RFLink-ESP " AUTOCONNECT_LINK(COG_32) "


"; //// iframe test : - //"" + // "" // content += "Last refresh : "; // Require NTP time, We'll see that later.... - //content += ctime(&now); + // content += ctime(&now); content += "
"; content += "
"; content += "
Last Message
"; @@ -232,6 +255,10 @@ void rootPage() void setup_AutoConnect() { + + String test = "D12 "; + get_GPIO(test); + if (portal.load(FPSTR(AUX_settings))) { // we load all the settings from "/settings" uri AutoConnectAux &aux1 = *portal.aux(AUX_SETTING_URI); @@ -320,7 +347,7 @@ void HandleLastMsg() // Required only for ajax auto-refresh of the last message void getParams(AutoConnectAux &aux) { ////// MQTT settings ////// - MQTT_SERVER = aux["MQTT_SERVER"].value; + MQTT_SERVER = (aux["MQTT_SERVER"].value); MQTT_SERVER.trim(); MQTT_PORT = aux["MQTT_PORT"].value; MQTT_PORT.trim(); @@ -341,6 +368,20 @@ void getParams(AutoConnectAux &aux) Adv_HostName.trim(); Adv_Power = aux["Adv_Power"].value; Adv_Power.trim(); + + // Radio pins settings + PIN_RF_RX_PMOS = String2GPIO(aux["PIN_RF_RX_PMOS"].value); + PIN_RF_RX_NMOS = String2GPIO(aux["PIN_RF_RX_NMOS"].value); + PIN_RF_RX_VCC = String2GPIO(aux["PIN_RF_RX_VCC"].value); + PIN_RF_RX_GND = String2GPIO(aux["PIN_RF_RX_GND"].value); + PIN_RF_RX_NA = String2GPIO(aux["PIN_RF_RX_NA"].value); + PIN_RF_RX_DATA = String2GPIO(aux["PIN_RF_RX_DATA"].value); + PULLUP_RF_RX_DATA = aux["PULLUP_RF_RX_DATA"].as().checked; + PIN_RF_TX_PMOS = String2GPIO(aux["PIN_RF_TX_PMOS"].value); + PIN_RF_TX_NMOS = String2GPIO(aux["PIN_RF_TX_NMOS"].value); + PIN_RF_TX_VCC = String2GPIO(aux["PIN_RF_TX_VCC"].value); + PIN_RF_TX_GND = String2GPIO(aux["PIN_RF_TX_GND"].value); + PIN_RF_TX_DATA = String2GPIO(aux["PIN_RF_TX_DATA"].value); } // Load parameters saved with saveParams from SPIFFS into the @@ -414,7 +455,13 @@ String saveParams(AutoConnectAux &aux, PageArgument &args) src_aux.saveElement(my_file, {"MQTT_SERVER", "MQTT_PORT", "MQTT_ID", "MQTT_USER", "MQTT_PSWD", "MQTT_TOPIC_OUT", "MQTT_TOPIC_IN", "MQTT_RETAINED", - "Adv_HostName", "Adv_Power"}); + "Adv_HostName", "Adv_Power", + "PIN_RF_RX_PMOS", "PIN_RF_RX_NMOS", + "PIN_RF_RX_VCC", "PIN_RF_RX_GND", + "PIN_RF_RX_NA", "PIN_RF_RX_DATA", "PULLUP_RF_RX_DATA", + "PIN_RF_TX_PMOS", "PIN_RF_TX_NMOS", + "PIN_RF_TX_VCC", "PIN_RF_TX_GND", + "PIN_RF_TX_DATA"}); Serial.println(F(" saved")); my_file.close(); } @@ -449,6 +496,33 @@ String saveParams(AutoConnectAux &aux, PageArgument &args) echo.value += Adv_HostName; echo.value += F("
TX Power: "); echo.value += Adv_Power; + echo.value += F("

GPIO settings
"); + echo.value += F("
Radio Receiver"); + echo.value += F("
RX_PMOS: "); + echo.value += GPIO2String(PIN_RF_RX_PMOS); + echo.value += F("
RX_NMOS: "); + echo.value += GPIO2String(PIN_RF_RX_NMOS); + echo.value += F("
RX_VCC: "); + echo.value += GPIO2String(PIN_RF_RX_VCC); + echo.value += F("
RX_GND: "); + echo.value += GPIO2String(PIN_RF_RX_GND); + echo.value += F("
RX_NA: "); + echo.value += GPIO2String(PIN_RF_RX_NA); + echo.value += F("
RX_DATA: "); + echo.value += GPIO2String(PIN_RF_RX_DATA); + echo.value += F("
Pullup on RX_DATA: "); + echo.value += String(PULLUP_RF_RX_DATA == true ? "true" : "false"); + echo.value += F("

Radio Emitter"); + echo.value += F("
TX_PMOS: "); + echo.value += GPIO2String(PIN_RF_TX_PMOS); + echo.value += F("
TX_NMOS: "); + echo.value += GPIO2String(PIN_RF_TX_NMOS); + echo.value += F("
TX_VCC: "); + echo.value += GPIO2String(PIN_RF_TX_VCC); + echo.value += F("
TX_GND: "); + echo.value += GPIO2String(PIN_RF_TX_GND); + echo.value += F("
TX_DATA: "); + echo.value += GPIO2String(PIN_RF_TX_DATA); echo.value += F("
"); #ifdef MQTT_ENABLED diff --git a/RFLink/9_AutoConnect.h b/RFLink/9_AutoConnect.h index 81d46ab1..ae1b44c5 100644 --- a/RFLink/9_AutoConnect.h +++ b/RFLink/9_AutoConnect.h @@ -55,18 +55,6 @@ #define AUX_SAVE_URI "/settings_save" //#define AUX_CLEAR_URI "/settings_clear" -extern String MQTT_SERVER; -extern String MQTT_PORT; -extern String MQTT_ID; -extern String MQTT_USER; -extern String MQTT_PSWD; -extern String MQTT_TOPIC_OUT; -extern String MQTT_TOPIC_IN; -extern boolean MQTT_RETAINED; -extern String Adv_HostName; -extern String Adv_Power; -extern String LastMsg; - void setup_AutoConnect(); void loop_AutoConnect(); @@ -81,7 +69,7 @@ void HandleLastMsg(); static const char AUX_settings[] PROGMEM = R"raw( [ { - "title": "MQTT settings", + "title": "RFLink settings", "uri": "/settings", "menu": true, "element": [ @@ -126,14 +114,12 @@ static const char AUX_settings[] PROGMEM = R"raw( "name": "MQTT_ID", "type": "ACInput", "label": "ID", - "pattern": "^[0-9]{6}$", "placeholder": "example : RFLink-ESP-xx" }, { "name": "MQTT_USER", "type": "ACInput", - "label": "User", - "pattern": "^[0-9]{6}$" + "label": "User" }, { "name": "MQTT_PSWD", @@ -220,6 +206,124 @@ static const char AUX_settings[] PROGMEM = R"raw( "type": "ACElement", "value": "
" }, + { + "name": "style5", + "type": "ACStyle", + "value": "label+input,label+select{position:sticky;left:180px;width:210px!important;box-sizing:border-box;}" + }, + { + "name": "header5", + "type": "ACText", + "value": "

GPIO settings

", + "style": "text-align:center;color:#2f4f4f;padding:10px;" + }, + { + "name": "caption6", + "type": "ACText", + "value": "Radio Receiver", + "style": "font-family:serif;color:#4682b4;" + }, + { + "name": "newline7", + "type": "ACElement", + "value": "
" + }, + { + "name": "PIN_RF_RX_PMOS", + "type": "ACInput", + "label": "RX_PMOS", + "placeholder": "NOT_A_PIN" + }, + { + "name": "PIN_RF_RX_NMOS", + "type": "ACInput", + "label": "RX_NMOS", + "placeholder": "NOT_A_PIN" + }, + { + "name": "PIN_RF_RX_VCC", + "type": "ACInput", + "label": "RX_VCC", + "placeholder": "NOT_A_PIN" + }, + { + "name": "PIN_RF_RX_GND", + "type": "ACInput", + "label": "RX_GND", + "placeholder": "NOT_A_PIN" + }, + { + "name": "PIN_RF_RX_NA", + "type": "ACInput", + "label": "RX_NA", + "placeholder": "NOT_A_PIN" + }, + { + "name": "PIN_RF_RX_DATA", + "type": "ACInput", + "label": "RX_DATA", + "placeholder": "NOT_A_PIN" + }, + { + "name": "PULLUP_RF_RX_DATA", + "type": "ACCheckbox", + "value": "unique", + "labelPosition" : "AC_Infront", + "post" : "AC_Tag_BR", + "label": "Pullup on RX_DATA", + "checked": false + }, + { + "name": "newlineX", + "type": "ACElement", + "value": "
" + }, + { + "name": "caption7", + "type": "ACText", + "value": "Radio Emitter", + "style": "font-family:serif;color:#4682b4;" + }, + { + "name": "newline8", + "type": "ACElement", + "value": "
" + }, + { + "name": "PIN_RF_TX_PMOS", + "type": "ACInput", + "label": "TX_PMOS", + "placeholder": "NOT_A_PIN" + }, + { + "name": "PIN_RF_TX_NMOS", + "type": "ACInput", + "label": "TX_NMOS", + "placeholder": "NOT_A_PIN" + }, + { + "name": "PIN_RF_TX_VCC", + "type": "ACInput", + "label": "TX_VCC", + "placeholder": "NOT_A_PIN" + }, + { + "name": "PIN_RF_TX_GND", + "type": "ACInput", + "label": "TX_GND", + "placeholder": "NOT_A_PIN" + }, + { + "name": "PIN_RF_TX_DATA", + "type": "ACInput", + "label": "TX_DATA", + "placeholder": "NOT_A_PIN" + }, + { + "name": "newline9", + "type": "ACElement", + "value": "
" + }, { "name": "save", "type": "ACSubmit", From 05b6b16460453c3a77a61c223f1292d40196010a Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Tue, 28 Apr 2020 17:35:26 +0200 Subject: [PATCH 31/46] Workaround 6_Credential When Autoconnect is disabled --- RFLink/6_Credentials.h | 1 + RFLink/6_WiFi_MQTT.cpp | 2 ++ RFLink/6_WiFi_MQTT.h | 3 +-- RFLink/9_AutoConnect.cpp | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/RFLink/6_Credentials.h b/RFLink/6_Credentials.h index 0e657137..71959b37 100644 --- a/RFLink/6_Credentials.h +++ b/RFLink/6_Credentials.h @@ -8,6 +8,7 @@ #ifndef CREDENTIALS_h #define CREDENTIALS_h +#include "RFLink.h" #ifndef AUTOCONNECT_ENABLED // local AP diff --git a/RFLink/6_WiFi_MQTT.cpp b/RFLink/6_WiFi_MQTT.cpp index db5dd838..e0e8ac2b 100644 --- a/RFLink/6_WiFi_MQTT.cpp +++ b/RFLink/6_WiFi_MQTT.cpp @@ -12,6 +12,8 @@ #include "6_WiFi_MQTT.h" #ifdef AUTOCONNECT_ENABLED #include "9_AutoConnect.h" +#else +#include "6_Credentials.h" #endif #ifndef AUTOCONNECT_ENABLED diff --git a/RFLink/6_WiFi_MQTT.h b/RFLink/6_WiFi_MQTT.h index dd7f42dc..50bb5e9c 100644 --- a/RFLink/6_WiFi_MQTT.h +++ b/RFLink/6_WiFi_MQTT.h @@ -24,13 +24,12 @@ extern String Adv_HostName; extern String Adv_Power; extern String LastMsg; #else -#include "6_Credentials.h" #ifdef ESP32 #include #elif ESP8266 #include #endif -#endif // !AUTOCONNECT_ENABLED +#endif // AUTOCONNECT_ENABLED #ifdef MQTT_ENABLED extern char MQTTbuffer[PRINT_BUFFER_SIZE]; // Buffer for MQTT message diff --git a/RFLink/9_AutoConnect.cpp b/RFLink/9_AutoConnect.cpp index 29bfe000..f9308de3 100644 --- a/RFLink/9_AutoConnect.cpp +++ b/RFLink/9_AutoConnect.cpp @@ -8,13 +8,13 @@ #include #include #include "RFLink.h" +#ifdef AUTOCONNECT_ENABLED + #include "1_Radio.h" #include "4_Display.h" // To allow displaying the last message #include "5_Plugin.h" #include "6_WiFi_MQTT.h" #include "9_AutoConnect.h" -#ifdef AUTOCONNECT_ENABLED - #ifdef ESP8266 #include #include From e5f6185a7879f772b66c47de88a72f61d3403fdf Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Tue, 28 Apr 2020 21:19:50 +0200 Subject: [PATCH 32/46] Update Plugin_047.c Issue #20 --- RFLink/Plugins/Plugin_047.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RFLink/Plugins/Plugin_047.c b/RFLink/Plugins/Plugin_047.c index 9122886c..214a1529 100644 --- a/RFLink/Plugins/Plugin_047.c +++ b/RFLink/Plugins/Plugin_047.c @@ -98,7 +98,7 @@ boolean Plugin_047(byte function, char *string) if (RawSignal.Pulses[x] < AURIOLV4_PULSEMIN) return false; - if (RawSignal.Pulses[x] > LACROSSE43_PULSEMINMAX) + if (RawSignal.Pulses[x] > AURIOLV4_PULSEMINMAX) return false; if (bitcounter < 32) From 2bf607ee57a39b693f26cf08e5e889579c170497 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Wed, 29 Apr 2020 19:09:58 +0200 Subject: [PATCH 33/46] Typo (nice one!) --- RFLink/1_Radio.h | 56 ++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/RFLink/1_Radio.h b/RFLink/1_Radio.h index e5889712..1f7131cf 100644 --- a/RFLink/1_Radio.h +++ b/RFLink/1_Radio.h @@ -44,44 +44,44 @@ extern boolean PULLUP_RF_RX_DATA; #endif #ifdef ESP32 -#define PIN_RF_RX_PMOS NOT_A_PIN_0 // High Side P-MOSFET, active on LOW level -#define PIN_RF_RX_NMOS NOT_A_PIN_0 // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_RX_VCC NOT_A_PIN_0 // Power to the receiver on this pin -#define PIN_RF_RX_GND NOT_A_PIN_0 // Ground to the receiver on this pin -#define PIN_RF_RX_NA NOT_A_PIN_0 // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA NOT_A_PIN_0 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_TX_PMOS NOT_A_PIN_0 // High Side P-MOSFET, active on LOW level -#define PIN_RF_TX_NMOS NOT_A_PIN_0 // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_TX_VCC NOT_A_PIN_0 // +5 volt / Vcc power to the transmitter on this pin -#define PIN_RF_TX_GND NOT_A_PIN_0 // Ground power to the transmitter on this pin -#define PIN_RF_TX_DATA NOT_A_PIN_0 // Data to the 433Mhz transmitter on this pin +#define PIN_RF_RX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_RX_NMOS_0 NOT_A_PIN // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_RX_VCC_0 NOT_A_PIN // Power to the receiver on this pin +#define PIN_RF_RX_GND_0 NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_RX_NA_0 NOT_A_PIN // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_DATA_0 NOT_A_PIN // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_TX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_TX_NMOS_0 NOT_A_PIN // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_TX_VCC_0 NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin +#define PIN_RF_TX_GND_0 NOT_A_PIN // Ground power to the transmitter on this pin +#define PIN_RF_TX_DATA_0 NOT_A_PIN // Data to the 433Mhz transmitter on this pin #endif #ifdef __AVR_ATmega328P__ -#define PIN_RF_RX_PMOS NOT_A_PIN_0 // High Side P-MOSFET, active on LOW level -#define PIN_RF_RX_NMOS NOT_A_PIN_0 // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_RX_VCC NOT_A_PIN_0 // Power to the receiver on this pin -#define PIN_RF_RX_GND NOT_A_PIN_0 // Ground to the receiver on this pin -#define PIN_RF_RX_NA NOT_A_PIN_0 // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_RX_NMOS_0 NOT_A_PIN // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_RX_VCC_0 NOT_A_PIN // Power to the receiver on this pin +#define PIN_RF_RX_GND_0 NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_RX_NA_0 NOT_A_PIN // Alt. RX_DATA. Forced as input #define PIN_RF_RX_DATA_0 2 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_TX_PMOS NOT_A_PIN_0 // High Side P-MOSFET, active on LOW level -#define PIN_RF_TX_NMOS NOT_A_PIN_0 // Low Side N-MOSFET, active on HIGH level -#define PIN_RF_TX_VCC NOT_A_PIN_0 // +5 volt / Vcc power to the transmitter on this pin -#define PIN_RF_TX_GND NOT_A_PIN_0 // Ground power to the transmitter on this pin -#define PIN_RF_TX_DATA NOT_A_PIN_0 // Data to the 433Mhz transmitter on this pin +#define PIN_RF_TX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_TX_NMOS_0 NOT_A_PIN // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_TX_VCC_0 NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin +#define PIN_RF_TX_GND_0 NOT_A_PIN // Ground power to the transmitter on this pin +#define PIN_RF_TX_DATA_0 NOT_A_PIN // Data to the 433Mhz transmitter on this pin #endif #ifdef __AVR_ATmega2560__ -#define PIN_RF_RX_PMOS NOT_A_PIN_0 // High Side P-MOSFET, active on LOW level -#define PIN_RF_RX_NMOS NOT_A_PIN_0 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_RX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_RX_NMOS_0 NOT_A_PIN // Low Side N-MOSFET, active on HIGH level #define PIN_RF_RX_VCC_0 16 // Power to the receiver on this pin -#define PIN_RF_RX_GND NOT_A_PIN_0 // Ground to the receiver on this pin -#define PIN_RF_RX_NA NOT_A_PIN_0 // Alt. RX_DATA. Forced as input +#define PIN_RF_RX_GND_0 NOT_A_PIN // Ground to the receiver on this pin +#define PIN_RF_RX_NA_0 NOT_A_PIN // Alt. RX_DATA. Forced as input #define PIN_RF_RX_DATA_0 19 // On this input, the 433Mhz-RF signal is received. LOW when no signal. -#define PIN_RF_TX_PMOS NOT_A_PIN_0 // High Side P-MOSFET, active on LOW level -#define PIN_RF_TX_NMOS NOT_A_PIN_0 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_TX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level +#define PIN_RF_TX_NMOS_0 NOT_A_PIN // Low Side N-MOSFET, active on HIGH level #define PIN_RF_TX_VCC_0 15 // +5 volt / Vcc power to the transmitter on this pin -#define PIN_RF_TX_GND NOT_A_PIN_0 // Ground power to the transmitter on this pin +#define PIN_RF_TX_GND_0 NOT_A_PIN // Ground power to the transmitter on this pin #define PIN_RF_TX_DATA_0 14 // Data to the 433Mhz transmitter on this pin #endif From 0abc1a9f9f9b2668b1386c3b03ceee36e461493f Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Wed, 29 Apr 2020 19:10:42 +0200 Subject: [PATCH 34/46] Added lib_deps --- platformio.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 8b299589..806f576d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,8 +26,10 @@ lib_deps = ESP8266WiFi PubSubClient Autoconnect - ;Wire - ;U8g2 + PageBuilder + ArduinoJson +; ;Wire +; ;U8g2 ;[env:nodemcuv2] ;platform = espressif8266 From 5f85bfa68600645f53951cc3a8f022e14748e3db Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Wed, 29 Apr 2020 19:12:03 +0200 Subject: [PATCH 35/46] CallReboot() for AVR --- RFLink/RFLink.ino | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index 6f9fbeb5..a3e759d5 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -35,6 +35,13 @@ void sendMsg(); // See at bottom #if (defined(__AVR_ATmega328P__) || defined(__AVR_ATmega2560__)) void (*Reboot)(void) = 0; // reset function on adress 0. + +void CallReboot(void) +{ + sendMsg(); + delay(1); + Reboot(); +} #endif #if (defined(ESP8266) || defined(ESP32)) From 57b76dbeebcd46048d5debd76640c4f04050ad57 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Wed, 29 Apr 2020 19:12:25 +0200 Subject: [PATCH 36/46] Typo (for AVR IDE) --- RFLink/Plugins/Plugin_004.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RFLink/Plugins/Plugin_004.c b/RFLink/Plugins/Plugin_004.c index ac437900..5dbc93b1 100644 --- a/RFLink/Plugins/Plugin_004.c +++ b/RFLink/Plugins/Plugin_004.c @@ -151,8 +151,8 @@ boolean Plugin_004(byte function, char *string) #endif // Plugin_004 #ifdef PLUGIN_TX_004 -#include "3_Serial.h" -#include "4_Display.h" +#include "../3_Serial.h" +#include "../4_Display.h" boolean PluginTX_004(byte function, char *string) { From f2d045e0f78101e01a1565799509bff2534ce5bd Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Wed, 29 Apr 2020 19:13:49 +0200 Subject: [PATCH 37/46] Moved PluginInit up in boot sequence --- RFLink/RFLink.ino | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index a3e759d5..1e1985fc 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -69,6 +69,9 @@ void setup() set_Radio_mode(Radio_OFF); + PluginInit(); + PluginTXInit(); + #if (!defined(AUTOCONNECT_ENABLED) && !defined(MQTT_ENABLED)) #if (defined(ESP32) || defined(ESP8266)) setup_WIFI_OFF(); @@ -106,10 +109,6 @@ void setup() splash_OLED(); #endif pbuffer[0] = 0; - - PluginInit(); - PluginTXInit(); - set_Radio_mode(Radio_RX); } From 7098a784a5773d6639ba6e1df8b1ce0018330b47 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Wed, 29 Apr 2020 19:17:44 +0200 Subject: [PATCH 38/46] Tinker with protocols.json This should marginaly also treat #24 --- RFLink/5_Plugin.cpp | 67 +++++++++++++++++++--------------------- RFLink/9_AutoConnect.cpp | 66 ++++++++++++++++----------------------- RFLink/9_AutoConnect.h | 1 + 3 files changed, 60 insertions(+), 74 deletions(-) diff --git a/RFLink/5_Plugin.cpp b/RFLink/5_Plugin.cpp index e0edc04d..57480d03 100644 --- a/RFLink/5_Plugin.cpp +++ b/RFLink/5_Plugin.cpp @@ -9,9 +9,15 @@ #include "RFLink.h" #include "2_Signal.h" #include "5_Plugin.h" -//#include //used to store current plugins states -#include // To save MQTT parameters +#ifdef AUTOCONNECT_ENABLED +#include "9_AutoConnect.h" +#ifdef ESP8266 +#include // To save plugins parameters #include +#elif ESP32 +#include +#endif +#endif boolean (*Plugin_ptr[PLUGIN_MAX])(byte, char *); // Receive plugins byte Plugin_id[PLUGIN_MAX]; @@ -550,7 +556,6 @@ void PluginInit(void) Plugin_ptr[x] = 0; Plugin_id[x] = 0; Plugin_State[x] = P_Enabled; - //EEPROM.get(x, Plugin_State[x]); } x = 0; @@ -1313,45 +1318,37 @@ void PluginInit(void) // read config file to desactivated protocols #ifdef AUTOCONNECT_ENABLED - Serial.println("mounting FS..."); - if (SPIFFS.begin()) + SPIFFS.begin(); + Serial.print(PROTOCOL_FILE); + File configFile = SPIFFS.open(PROTOCOL_FILE, "r"); + if (configFile) { - Serial.println("mounted file system"); - if (SPIFFS.exists("/protocols.json")) + StaticJsonDocument<6400> doc; + if (deserializeJson(doc, configFile)) + { + Serial.println(F(" failed to load")); + } + else { - //file exists, reading and loading - Serial.println("reading protocols file"); - File configFile = SPIFFS.open("/protocols.json", "r"); - if (configFile) + for (x = 0; x < PLUGIN_MAX; x++) { - Serial.println("opened protocols file"); - size_t size = configFile.size(); - if (size == 0) - { - Serial.println("History file empty"); - } - else - { - StaticJsonDocument<6400> doc; - DeserializationError error = deserializeJson(doc, configFile); - if (error) - { - Serial.println(F("Failed to read file, using default configuration")); - } - - for (x = 0; x < PLUGIN_MAX; x++) - { - if (doc[x][String(Plugin_id[x])] == 0) - { - Plugin_State[x] = P_Disabled; - } - } - configFile.close(); - } + if (doc[x][String(Plugin_id[x])] == 0) + Plugin_State[x] = P_Disabled; } + Serial.println(F(" loaded")); } + configFile.close(); + } + else + { + Serial.println(F(" open+r failed")); +#ifdef ESP32 + Serial.println(F("If you get error as 'SPIFFS: mount failed, -10025', Please modify with 'SPIFFS.begin(true)'.")); +#endif // ESP32 } + SPIFFS.end(); + #endif // AUTOCONNECT_ENABLED // Initialiseer alle plugins door aanroep met verwerkingsparameter PLUGIN_INIT diff --git a/RFLink/9_AutoConnect.cpp b/RFLink/9_AutoConnect.cpp index f9308de3..e27b0f37 100644 --- a/RFLink/9_AutoConnect.cpp +++ b/RFLink/9_AutoConnect.cpp @@ -6,7 +6,6 @@ // ************************************* // #include -#include #include "RFLink.h" #ifdef AUTOCONNECT_ENABLED @@ -18,12 +17,11 @@ #ifdef ESP8266 #include #include -//#include // Replace with WebServer.h for ESP32 -// #include typedef ESP8266WebServer WebServer; +#include // To save plugins parameters +#include #elif ESP32 #include -//#include #include #include typedef WebServer WebServer; @@ -66,15 +64,6 @@ uint8_t PIN_RF_TX_DATA; String loadParams(AutoConnectAux &aux, PageArgument &args); String saveParams(AutoConnectAux &aux, PageArgument &args); -void get_GPIO(String sGPIO) -{ - - sGPIO.trim(); - Serial.print("sGPIO *"); - Serial.print(sGPIO); - Serial.println("*"); -} - void rootPage() { @@ -83,16 +72,16 @@ void rootPage() { // On n'enregistre les values que si ce n'est pas le bouton "test" qui a été appuyé // === Debug Part === - String message = "Number of args received: "; - message += webServer.args(); //Get number of parameters - message += "\n"; //Add a new line - for (int i = 0; i < webServer.args(); i++) - { - message += "Arg nº" + (String)i + " – > "; //Include the current iteration value - message += webServer.argName(i) + ": "; //Get the name of the parameter - message += webServer.arg(i) + "\n"; //Get the value of the parameter - } - Serial.println(message); + // String message = "Number of args received: "; + // message += webServer.args(); //Get number of parameters + // message += "\n"; //Add a new line + // for (int i = 0; i < webServer.args(); i++) + // { + // message += "Arg nº" + (String)i + " – > "; //Include the current iteration value + // message += webServer.argName(i) + ": "; //Get the name of the parameter + // message += webServer.arg(i) + "\n"; //Get the value of the parameter + // } + // Serial.println(message); // ================== //const int capacity = JSON_ARRAY_SIZE(254) + 2 * JSON_OBJECT_SIZE(2); @@ -121,15 +110,20 @@ void rootPage() } } - File configFile = SPIFFS.open("/protocols.json", "w"); + SPIFFS.begin(); + File configFile = SPIFFS.open(PROTOCOL_FILE, "w"); + Serial.print(PROTOCOL_FILE); + String configString; serializeJson(doc, configString); configFile.print(configString); // === Debug Part === - Serial.println(configString); + // Serial.println(configString); // ================== + Serial.println(F(" saved")); configFile.close(); + SPIFFS.end(); } // This is the Home Page - Choose theme here : https://www.bootstrapcdn.com/bootswatch/?theme @@ -255,10 +249,6 @@ void rootPage() void setup_AutoConnect() { - - String test = "D12 "; - get_GPIO(test); - if (portal.load(FPSTR(AUX_settings))) { // we load all the settings from "/settings" uri AutoConnectAux &aux1 = *portal.aux(AUX_SETTING_URI); @@ -286,12 +276,13 @@ void setup_AutoConnect() Serial.println(F("No SSID recorded, starting soft AP mode")); config.immediateStart = true; config.autoRise = true; + ///////////////// + Serial.print(F("AP name set to ")); + Serial.println(config.apid); } //--------------------------------------------------------------------- portal.config(config); ///////////////// - Serial.print(F("AP name set to ")); - Serial.println(config.apid); Serial.print(F("hostname set to ")); Serial.println(config.hostName); ///////////////// @@ -324,7 +315,6 @@ void setup_AutoConnect() yield(); } } - //SPIFFS.end(); WebServer &webServer = portal.host(); webServer.on("/", rootPage); @@ -392,11 +382,11 @@ String loadParams(AutoConnectAux &aux, PageArgument &args) //static boolean initConfig = true; SPIFFS.begin(); - File my_file = SPIFFS.open(PARAM_FILE, "r"); Serial.print(PARAM_FILE); - if (my_file) + File paramFile = SPIFFS.open(PARAM_FILE, "r"); + if (paramFile) { - if (aux.loadElement(my_file)) + if (aux.loadElement(paramFile)) { getParams(aux); Serial.println(F(" loaded")); @@ -404,9 +394,8 @@ String loadParams(AutoConnectAux &aux, PageArgument &args) else { Serial.println(F(" failed to load")); - //if (initConfig) } - my_file.close(); + paramFile.close(); } else { @@ -416,7 +405,6 @@ String loadParams(AutoConnectAux &aux, PageArgument &args) #endif // ESP32 } SPIFFS.end(); - //initConfig = false; return String(""); } @@ -532,4 +520,4 @@ String saveParams(AutoConnectAux &aux, PageArgument &args) return String(""); } -#endif // AUTOCONNECT_ENABLE \ No newline at end of file +#endif // AUTOCONNECT_ENABLE diff --git a/RFLink/9_AutoConnect.h b/RFLink/9_AutoConnect.h index ae1b44c5..1ca2bb9d 100644 --- a/RFLink/9_AutoConnect.h +++ b/RFLink/9_AutoConnect.h @@ -51,6 +51,7 @@ // Adds MQTT tab to Autoconnect #define PARAM_FILE "/settings.json" +#define PROTOCOL_FILE "/protocols.json" #define AUX_SETTING_URI "/settings" #define AUX_SAVE_URI "/settings_save" //#define AUX_CLEAR_URI "/settings_clear" From c5300ac8e698d040ee5a944dc85f6c361619622f Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Wed, 29 Apr 2020 19:18:38 +0200 Subject: [PATCH 39/46] Corrections for AVR And others ... --- RFLink/4_Display.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/RFLink/4_Display.cpp b/RFLink/4_Display.cpp index aafedf59..b564967e 100644 --- a/RFLink/4_Display.cpp +++ b/RFLink/4_Display.cpp @@ -343,7 +343,7 @@ void display_RGBW(unsigned int input) char *ptr; const char c_delim[2] = ";"; -char c_label[10]; +char c_label[12]; boolean retrieve_Init10() { @@ -361,7 +361,7 @@ boolean retrieve_Init10() boolean retrieve_Name(const char *c_Name) { - // Newkaku + // Newkaku ... or else! ptr = strtok(NULL, c_delim); if (ptr != NULL) { @@ -549,6 +549,7 @@ int str2cmd(char *command) // } // } +#ifdef AUTOCONNECT_ENABLED uint8_t String2GPIO(String sGPIO) { byte num_part; @@ -633,4 +634,5 @@ String GPIO2String(uint8_t uGPIO) default: return "NOT_A_PIN"; } -} \ No newline at end of file +} +#endif //AUTOCONNECT_ENABLED From 635257ccaafa979a59a4bcdcbde0f96f73b6f879 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Wed, 29 Apr 2020 20:32:00 +0200 Subject: [PATCH 40/46] Cleanup forget --- RFLink/9_AutoConnect.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/RFLink/9_AutoConnect.cpp b/RFLink/9_AutoConnect.cpp index e27b0f37..9156c210 100644 --- a/RFLink/9_AutoConnect.cpp +++ b/RFLink/9_AutoConnect.cpp @@ -26,9 +26,6 @@ typedef ESP8266WebServer WebServer; #include typedef WebServer WebServer; #endif - -//#include // To acces Flash Memory -#include // To save MQTT parameters #include AutoConnect portal; From 9dac9a8cd4c3393c094de3d1fd0c483245c1ddba Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Wed, 29 Apr 2020 21:50:42 +0200 Subject: [PATCH 41/46] (Too) short string #25 --- RFLink/Plugins/Plugin_002.c | 2 +- RFLink/Plugins/Plugin_004.c | 2 +- RFLink/Plugins/Plugin_006.c | 2 +- RFLink/Plugins/Plugin_008.c | 2 +- RFLink/Plugins/Plugin_011.c | 2 +- RFLink/Plugins/Plugin_012.c | 2 +- RFLink/Plugins/Plugin_030.c | 2 +- RFLink/Plugins/Plugin_032.c | 2 +- RFLink/Plugins/Plugin_034.c | 10 +++++----- RFLink/Plugins/Plugin_040.c | 2 +- RFLink/Plugins/Plugin_041.c | 2 +- RFLink/Plugins/Plugin_042.c | 8 ++++---- RFLink/Plugins/Plugin_043.c | 4 ++-- RFLink/Plugins/Plugin_044.c | 2 +- RFLink/Plugins/Plugin_045.c | 2 +- RFLink/Plugins/Plugin_046.c | 2 +- RFLink/Plugins/Plugin_047.c | 2 +- 17 files changed, 25 insertions(+), 25 deletions(-) diff --git a/RFLink/Plugins/Plugin_002.c b/RFLink/Plugins/Plugin_002.c index 1792f697..7f1a8ede 100644 --- a/RFLink/Plugins/Plugin_002.c +++ b/RFLink/Plugins/Plugin_002.c @@ -171,7 +171,7 @@ boolean Plugin_002(byte function, char *string) // Output // ---------------------------------- data[2] = (data[2] & B1011); // get sensor type from bitstream - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", data[3], data[4]); if (data[2] == B0000) // Temperature diff --git a/RFLink/Plugins/Plugin_004.c b/RFLink/Plugins/Plugin_004.c index 5dbc93b1..a21fc76e 100644 --- a/RFLink/Plugins/Plugin_004.c +++ b/RFLink/Plugins/Plugin_004.c @@ -134,7 +134,7 @@ boolean Plugin_004(byte function, char *string) display_Header(); display_Name(PSTR("NewKaku")); display_IDn(((bitstream >> 6) & 0xFFFFFFFF), 8); //"%S%08lx" - char c_SWITCH[4]; + char c_SWITCH[5]; sprintf(c_SWITCH, "%1x", ((byte)(bitstream & 0x0f) + 1)); // No leading 0 display_SWITCHc(c_SWITCH); diff --git a/RFLink/Plugins/Plugin_006.c b/RFLink/Plugins/Plugin_006.c index 637c44f3..79aa0529 100644 --- a/RFLink/Plugins/Plugin_006.c +++ b/RFLink/Plugins/Plugin_006.c @@ -138,7 +138,7 @@ boolean Plugin_006(byte function, char *string) display_IDn(address, 4); //"%04x" - char c_SWITCH[4]; + char c_SWITCH[5]; sprintf(c_SWITCH, "%c%d", channel, subchan); display_SWITCHc(c_SWITCH); display_CMD((status >> 1) & B01, !(status & B01)); // #ALL #ON diff --git a/RFLink/Plugins/Plugin_008.c b/RFLink/Plugins/Plugin_008.c index eb0ef8e8..4bfc4a33 100644 --- a/RFLink/Plugins/Plugin_008.c +++ b/RFLink/Plugins/Plugin_008.c @@ -138,7 +138,7 @@ boolean Plugin_008(byte function, char *string) display_Name(PSTR("Kambrook")); display_IDn((address & 0xFFFFFF), 6); //"%S%06lx" - char c_SWITCH[4]; + char c_SWITCH[5]; sprintf(c_SWITCH, "%c%d", channel, subchan); display_SWITCHc(c_SWITCH); diff --git a/RFLink/Plugins/Plugin_011.c b/RFLink/Plugins/Plugin_011.c index 0e426251..24c81fb9 100644 --- a/RFLink/Plugins/Plugin_011.c +++ b/RFLink/Plugins/Plugin_011.c @@ -163,7 +163,7 @@ boolean Plugin_011(byte function, char *string) display_Header(); display_Name(PSTR("HomeConfort")); display_IDn((bitstream1 & 0xFFFFFF), 6); //"%S%06lx" - char c_SWITCH[4]; + char c_SWITCH[5]; sprintf(c_SWITCH, "%c%d", channel, subchan); display_SWITCHc(c_SWITCH); display_CMD((group & B01), (command & B01)); // #ALL , #ON diff --git a/RFLink/Plugins/Plugin_012.c b/RFLink/Plugins/Plugin_012.c index 00edc0f2..125a548d 100644 --- a/RFLink/Plugins/Plugin_012.c +++ b/RFLink/Plugins/Plugin_012.c @@ -210,7 +210,7 @@ boolean Plugin_012(byte function, char *string) { display_IDn(((unitcode << 8) | housecode), 8); // "%02x%02x" - char c_SWITCH[4]; + char c_SWITCH[5]; sprintf(c_SWITCH, "%02x%02x", unitcode, housecode); display_SWITCHc(c_SWITCH); // "%02x%02x" } diff --git a/RFLink/Plugins/Plugin_030.c b/RFLink/Plugins/Plugin_030.c index 71787f55..45051641 100644 --- a/RFLink/Plugins/Plugin_030.c +++ b/RFLink/Plugins/Plugin_030.c @@ -184,7 +184,7 @@ boolean Plugin_030(byte function, char *string) data[3] = (data[3]) & B0111; // prepare nibble to contain only the needed bits //================================================================================== rc = (data[1] << 4) | data[0]; - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%04X", (rc & 0x03) << 2 | (rc & 0xFC)); if ((data[2]) != B0110) diff --git a/RFLink/Plugins/Plugin_032.c b/RFLink/Plugins/Plugin_032.c index 5ea11709..7d3dfcbd 100644 --- a/RFLink/Plugins/Plugin_032.c +++ b/RFLink/Plugins/Plugin_032.c @@ -150,7 +150,7 @@ boolean Plugin_032(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("Alecto V4")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02x%02x", rc, rc2); display_IDc(c_ID); display_TEMP(temperature); diff --git a/RFLink/Plugins/Plugin_034.c b/RFLink/Plugins/Plugin_034.c index 352a93b5..b13a66f1 100644 --- a/RFLink/Plugins/Plugin_034.c +++ b/RFLink/Plugins/Plugin_034.c @@ -212,7 +212,7 @@ boolean Plugin_034(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("Cresta")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", data[1], channel); display_IDc(c_ID); display_WINDIR(winddirection); @@ -243,7 +243,7 @@ boolean Plugin_034(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("Cresta")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", data[1], channel); display_IDc(c_ID); display_TEMP(sensor_data); @@ -264,7 +264,7 @@ boolean Plugin_034(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("Cresta")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", data[1], channel); display_IDc(c_ID); display_RAIN(sensor_data); @@ -287,7 +287,7 @@ boolean Plugin_034(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("Cresta")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", data[1], channel); display_IDc(c_ID); display_TEMP(sensor_data); @@ -303,7 +303,7 @@ boolean Plugin_034(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("Cresta;DEBUG")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", data[1], channel); display_IDc(c_ID); display_Footer(); diff --git a/RFLink/Plugins/Plugin_040.c b/RFLink/Plugins/Plugin_040.c index 21acc27f..df87c9db 100644 --- a/RFLink/Plugins/Plugin_040.c +++ b/RFLink/Plugins/Plugin_040.c @@ -138,7 +138,7 @@ boolean Plugin_040(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("Mebus")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02x%02x", rc, channel); display_IDc(c_ID); display_TEMP(temperature); diff --git a/RFLink/Plugins/Plugin_041.c b/RFLink/Plugins/Plugin_041.c index e8ef118c..ec0a1dd3 100644 --- a/RFLink/Plugins/Plugin_041.c +++ b/RFLink/Plugins/Plugin_041.c @@ -175,7 +175,7 @@ boolean Plugin_041(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("LaCrosseV3")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", data[0], data[1]); display_IDc(c_ID); diff --git a/RFLink/Plugins/Plugin_042.c b/RFLink/Plugins/Plugin_042.c index edd84ae1..92a20157 100644 --- a/RFLink/Plugins/Plugin_042.c +++ b/RFLink/Plugins/Plugin_042.c @@ -231,7 +231,7 @@ boolean Plugin_042(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("UPM/Esic")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", rc, devicecode); display_IDc(c_ID); display_WINSP(winds); @@ -248,7 +248,7 @@ boolean Plugin_042(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("UPM/Esic")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", rc, devicecode); display_IDc(c_ID); display_RAIN(rain); @@ -271,7 +271,7 @@ boolean Plugin_042(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("UPM/Esic")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", rc, devicecode); display_IDc(c_ID); display_TEMP(temperature); @@ -294,7 +294,7 @@ boolean Plugin_042(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("UPM/Esic F2")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", rc, devicecode); display_IDc(c_ID); display_TEMP(temperature); diff --git a/RFLink/Plugins/Plugin_043.c b/RFLink/Plugins/Plugin_043.c index 7bcaf38e..22314813 100644 --- a/RFLink/Plugins/Plugin_043.c +++ b/RFLink/Plugins/Plugin_043.c @@ -222,7 +222,7 @@ boolean Plugin_043(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("LaCrosse")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", data[3], data[4]); display_IDc(c_ID); display_TEMP(temperature); @@ -242,7 +242,7 @@ boolean Plugin_043(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("LaCrosse")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", data[3], data[4]); display_IDc(c_ID); display_HUM(humidity, HUM_HEX); diff --git a/RFLink/Plugins/Plugin_044.c b/RFLink/Plugins/Plugin_044.c index 3edf1277..64bd9833 100644 --- a/RFLink/Plugins/Plugin_044.c +++ b/RFLink/Plugins/Plugin_044.c @@ -135,7 +135,7 @@ boolean Plugin_044(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("Auriol V3")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", rc, channel); display_IDc(c_ID); display_TEMP(temperature); diff --git a/RFLink/Plugins/Plugin_045.c b/RFLink/Plugins/Plugin_045.c index fd9ac32b..f175b6c2 100644 --- a/RFLink/Plugins/Plugin_045.c +++ b/RFLink/Plugins/Plugin_045.c @@ -124,7 +124,7 @@ boolean Plugin_045(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("Auriol")); - char c_ID[2]; + char c_ID[5]; sprintf(c_ID, "%02X", rc); display_IDc(c_ID); display_TEMP(temperature); diff --git a/RFLink/Plugins/Plugin_046.c b/RFLink/Plugins/Plugin_046.c index f1beea56..5cea08fd 100644 --- a/RFLink/Plugins/Plugin_046.c +++ b/RFLink/Plugins/Plugin_046.c @@ -183,7 +183,7 @@ boolean Plugin_046(byte function, char *string) display_Name(PSTR("Auriol V2")); else display_Name(PSTR("Xiron")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", rc, channel); display_IDc(c_ID); display_TEMP(temperature); diff --git a/RFLink/Plugins/Plugin_047.c b/RFLink/Plugins/Plugin_047.c index 214a1529..6911a7a5 100644 --- a/RFLink/Plugins/Plugin_047.c +++ b/RFLink/Plugins/Plugin_047.c @@ -170,7 +170,7 @@ boolean Plugin_047(byte function, char *string) //================================================================================== display_Header(); display_Name(PSTR("Auriol V4")); - char c_ID[4]; + char c_ID[5]; sprintf(c_ID, "%02X%02X", rc, channel); display_IDc(c_ID); display_TEMP(temperature); From ec32c08aad33cccc776585481e3227c98e960bb0 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Thu, 30 Apr 2020 10:50:05 +0200 Subject: [PATCH 42/46] Changed retrieve_xxx() ptr logic To be more flexible when testing multiple choice --- RFLink/4_Display.cpp | 137 +++++++++++++++++------------------- RFLink/4_Display.h | 2 +- RFLink/Plugins/Plugin_004.c | 3 +- 3 files changed, 66 insertions(+), 76 deletions(-) diff --git a/RFLink/4_Display.cpp b/RFLink/4_Display.cpp index b564967e..fe913b78 100644 --- a/RFLink/4_Display.cpp +++ b/RFLink/4_Display.cpp @@ -345,28 +345,18 @@ char *ptr; const char c_delim[2] = ";"; char c_label[12]; -boolean retrieve_Init10() +void retrieve_Init() { - // 10 ptr = strtok(InputBuffer_Serial, c_delim); - if (ptr != NULL) - { - if (strncasecmp(ptr, "10", strlen("10")) != 0) - return false; - return true; - } - else - return false; } boolean retrieve_Name(const char *c_Name) { - // Newkaku ... or else! - ptr = strtok(NULL, c_delim); if (ptr != NULL) { if (strncasecmp(ptr, c_Name, strlen(c_Name)) != 0) return false; + ptr = strtok(NULL, c_delim); return true; } else @@ -378,7 +368,6 @@ boolean retrieve_ID(unsigned long &ul_ID) // ID char c_ID[10]; - ptr = strtok(NULL, c_delim); if (ptr != NULL) { strcpy(c_label, "ID="); @@ -398,6 +387,7 @@ boolean retrieve_ID(unsigned long &ul_ID) ul_ID = strtoul(c_ID, NULL, HEX); ul_ID &= 0x03FFFFFF; + ptr = strtok(NULL, c_delim); return true; } else @@ -409,7 +399,6 @@ boolean retrieve_Switch(byte &b_Switch) // Switch char c_Switch[10]; - ptr = strtok(NULL, c_delim); if (ptr != NULL) { strcpy(c_label, "SWITCH="); @@ -430,6 +419,7 @@ boolean retrieve_Switch(byte &b_Switch) if (b_Switch > 0xF) return false; // invalid address + ptr = strtok(NULL, c_delim); return true; } else @@ -441,7 +431,6 @@ boolean retrieve_Command(byte &b_Cmd, byte &b_Cmd2) // Command char c_Cmd[10]; - ptr = strtok(NULL, c_delim); if (ptr != NULL) { strcpy(c_label, "SET_LEVEL="); @@ -491,6 +480,7 @@ boolean retrieve_Command(byte &b_Cmd, byte &b_Cmd2) break; } + ptr = strtok(NULL, c_delim); return true; } else @@ -500,7 +490,6 @@ boolean retrieve_Command(byte &b_Cmd, byte &b_Cmd2) boolean retrieve_End() { // End - ptr = strtok(NULL, c_delim); if (ptr != NULL) return false; return true; @@ -568,35 +557,35 @@ uint8_t String2GPIO(String sGPIO) switch (num_part) { - case 0: - return D0; - break; - case 1: - return D1; - break; - case 2: - return D2; - break; - case 3: - return D3; - break; - case 4: - return D4; - break; - case 5: - return D5; - break; - case 6: - return D6; - break; - case 7: - return D7; - break; - case 8: - return D8; - break; - default: - return NOT_A_PIN; + case 0: + return D0; + break; + case 1: + return D1; + break; + case 2: + return D2; + break; + case 3: + return D3; + break; + case 4: + return D4; + break; + case 5: + return D5; + break; + case 6: + return D6; + break; + case 7: + return D7; + break; + case 8: + return D8; + break; + default: + return NOT_A_PIN; } } @@ -604,35 +593,35 @@ String GPIO2String(uint8_t uGPIO) { switch (uGPIO) { - case D0: - return "D0"; - break; - case D1: - return "D1"; - break; - case D2: - return "D2"; - break; - case D3: - return "D3"; - break; - case D4: - return "D4"; - break; - case D5: - return "D5"; - break; - case D6: - return "D6"; - break; - case D7: - return "D7"; - break; - case D8: - return "D8"; - break; - default: - return "NOT_A_PIN"; + case D0: + return "D0"; + break; + case D1: + return "D1"; + break; + case D2: + return "D2"; + break; + case D3: + return "D3"; + break; + case D4: + return "D4"; + break; + case D5: + return "D5"; + break; + case D6: + return "D6"; + break; + case D7: + return "D7"; + break; + case D8: + return "D8"; + break; + default: + return "NOT_A_PIN"; } } #endif //AUTOCONNECT_ENABLED diff --git a/RFLink/4_Display.h b/RFLink/4_Display.h index 0e86929a..8ed71b4e 100644 --- a/RFLink/4_Display.h +++ b/RFLink/4_Display.h @@ -82,7 +82,7 @@ void display_METER(unsigned int); void display_VOLT(unsigned int); void display_RGBW(unsigned int); -boolean retrieve_Init10(); +void retrieve_Init(); boolean retrieve_Name(const char *); boolean retrieve_ID(unsigned long &); boolean retrieve_Switch(byte &); diff --git a/RFLink/Plugins/Plugin_004.c b/RFLink/Plugins/Plugin_004.c index a21fc76e..be345fa8 100644 --- a/RFLink/Plugins/Plugin_004.c +++ b/RFLink/Plugins/Plugin_004.c @@ -172,7 +172,8 @@ boolean PluginTX_004(byte function, char *string) byte Cmd_bitstream = 0; // 2 bits Command byte Cmd_dimmer = 0; // 4 bits Alt Command - if (!retrieve_Init10()) + retrieve_Init(); + if (!retrieve_Name("10")) return false; if (!retrieve_Name("Newkaku")) return false; From 860384c41104b70bb5339e047185bb5ad3f3604b Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Thu, 30 Apr 2020 14:50:46 +0200 Subject: [PATCH 43/46] Web Send Message stuff --- RFLink/3_Serial.cpp | 34 +++++++++++++++++++++++++++++++--- RFLink/3_Serial.h | 1 + RFLink/6_WiFi_MQTT.h | 1 - RFLink/9_AutoConnect.cpp | 30 ++++++++++++++++++++++++++---- RFLink/9_AutoConnect.h | 3 +++ RFLink/RFLink.ino | 5 +++++ 6 files changed, 66 insertions(+), 8 deletions(-) diff --git a/RFLink/3_Serial.cpp b/RFLink/3_Serial.cpp index f3dc6c28..bea38ea6 100644 --- a/RFLink/3_Serial.cpp +++ b/RFLink/3_Serial.cpp @@ -1,4 +1,4 @@ -/// ************************************* // +// ************************************* // // * Arduino Project RFLink-esp * // // * https://github.com/couin3/RFLink * // // * 2018..2020 Stormteam - Marc RIVES * // @@ -34,9 +34,9 @@ boolean CheckSerial() return false; } -boolean CheckMQTT(byte *mqtt_in) +boolean CheckMQTT(byte *byte_in) { - if (CopySerial((char *)mqtt_in)) + if (CopySerial((char *)byte_in)) { #ifdef SERIAL_ENABLED Serial.flush(); @@ -49,6 +49,34 @@ boolean CheckMQTT(byte *mqtt_in) return false; } +boolean CheckWeb(String &String_in) +{ + if (!String_in.isEmpty()) + { + String_in.trim(); + char char_in[INPUT_COMMAND_SIZE]; + String_in.toCharArray(char_in, String_in.length() + 1); + char_in[String_in.length() + 1] = 0; + + if (CopySerial(char_in)) + { +#ifdef SERIAL_ENABLED + Serial.flush(); + Serial.print(F("Message arrived [Web] ")); + Serial.println(InputBuffer_Serial); +#endif + if (CheckCmd()) + { + String_in.clear(); + return true; + } + } + String_in.clear(); + return false; + } + return false; +} + boolean CopySerial(char *src) { return (strncpy(InputBuffer_Serial, src, INPUT_COMMAND_SIZE - 2)); diff --git a/RFLink/3_Serial.h b/RFLink/3_Serial.h index e74b0937..0da984a1 100644 --- a/RFLink/3_Serial.h +++ b/RFLink/3_Serial.h @@ -18,5 +18,6 @@ extern char InputBuffer_Serial[INPUT_COMMAND_SIZE]; boolean CheckSerial(); boolean CheckMQTT(byte *); +boolean CheckWeb(String &); #endif \ No newline at end of file diff --git a/RFLink/6_WiFi_MQTT.h b/RFLink/6_WiFi_MQTT.h index 50bb5e9c..105daab5 100644 --- a/RFLink/6_WiFi_MQTT.h +++ b/RFLink/6_WiFi_MQTT.h @@ -22,7 +22,6 @@ extern String MQTT_TOPIC_IN; extern boolean MQTT_RETAINED; extern String Adv_HostName; extern String Adv_Power; -extern String LastMsg; #else #ifdef ESP32 #include diff --git a/RFLink/9_AutoConnect.cpp b/RFLink/9_AutoConnect.cpp index 9156c210..83b90dcb 100644 --- a/RFLink/9_AutoConnect.cpp +++ b/RFLink/9_AutoConnect.cpp @@ -2,6 +2,8 @@ // * Arduino Project RFLink-esp * // // * https://github.com/couin3/RFLink * // // * 2018..2020 Stormteam - Marc RIVES * // +// * 2020 Schmutzm, Autoconnect Stuff * // +// * 2020 Allexum, Web "Send" button * // // * More details in RFLink.ino file * // // ************************************* // @@ -43,6 +45,7 @@ boolean MQTT_RETAINED; String Adv_HostName; String Adv_Power; String LastMsg; +String CmdMsg; // Radio pins settings uint8_t PIN_RF_RX_PMOS; uint8_t PIN_RF_RX_NMOS; @@ -65,6 +68,13 @@ void rootPage() { WebServer &webServer = portal.host(); + + if (webServer.hasArg("BtnSend")) + { + // Récupération de la valeur dans la fenêtre Send + CmdMsg = webServer.arg(0); + } + if (webServer.hasArg("BtnSave")) { // On n'enregistre les values que si ce n'est pas le bouton "test" qui a été appuyé @@ -199,13 +209,25 @@ void rootPage() //========================================== content += "
"; content += ""; - + content += "
"; content += "
"; - content += "

"; + // Zone de saisaie du message à envoyer + content += "
"; + content += "
"; + content += "
Send Message
"; + content += "
"; + if (webServer.hasArg("BtnSend")) + content += ""; + else + content += ""; + content += "
"; + content += "
"; + content += "
"; + content += "
"; content += ""; - content += ""; // Table Header // é = é + content += ""; // Table Header // é = é content += ""; // Table content content += ""; for (byte x = 0; x < PLUGIN_MAX; x++) @@ -236,7 +258,7 @@ void rootPage() content += ""; // we add a last line to bottom of the table content += "
NameEnabled
Plugin NameEnabled
"; - content += ""; + content += ""; content += ""; content += ""; diff --git a/RFLink/9_AutoConnect.h b/RFLink/9_AutoConnect.h index 1ca2bb9d..d92883f2 100644 --- a/RFLink/9_AutoConnect.h +++ b/RFLink/9_AutoConnect.h @@ -13,6 +13,9 @@ #ifdef AUTOCONNECT_ENABLED +extern String LastMsg; +extern String CmdMsg; + #ifdef ESP8266 #include #elif ESP32 diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index 1e1985fc..421b4bd1 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -129,6 +129,11 @@ void loop() sendMsg(); #endif +#ifdef AUTOCONNECT_ENABLED + if(CheckWeb(CmdMsg)) + sendMsg(); +#endif + if (ScanEvent()) sendMsg(); From 6bcd7d09a47e70c2bbb35f581670e925dfaff7a7 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Thu, 30 Apr 2020 16:44:45 +0200 Subject: [PATCH 44/46] Code indent --- RFLink/RFLink.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index 421b4bd1..aa355181 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -130,8 +130,8 @@ void loop() #endif #ifdef AUTOCONNECT_ENABLED - if(CheckWeb(CmdMsg)) - sendMsg(); + if (CheckWeb(CmdMsg)) + sendMsg(); #endif if (ScanEvent()) From 39be3ee4ba6921d5b5c316550449a17fc724c64f Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Thu, 30 Apr 2020 16:45:19 +0200 Subject: [PATCH 45/46] Changed default Radio Pinout Cause D3 has to avoided --- RFLink/1_Radio.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RFLink/1_Radio.h b/RFLink/1_Radio.h index 1f7131cf..1120afaa 100644 --- a/RFLink/1_Radio.h +++ b/RFLink/1_Radio.h @@ -35,9 +35,9 @@ extern boolean PULLUP_RF_RX_DATA; #define PIN_RF_RX_VCC_0 NOT_A_PIN // Power to the receiver on this pin #define PIN_RF_RX_GND_0 NOT_A_PIN // Ground to the receiver on this pin #define PIN_RF_RX_NA_0 NOT_A_PIN // Alt. RX_DATA. Forced as input -#define PIN_RF_RX_DATA_0 D3 // On this input, the 433Mhz-RF signal is received. LOW when no signal. +#define PIN_RF_RX_DATA_0 D6 // On this input, the 433Mhz-RF signal is received. LOW when no signal. #define PIN_RF_TX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level -#define PIN_RF_TX_NMOS_0 D6 // Low Side N-MOSFET, active on HIGH level +#define PIN_RF_TX_NMOS_0 D7 // Low Side N-MOSFET, active on HIGH level #define PIN_RF_TX_VCC_0 NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin #define PIN_RF_TX_GND_0 NOT_A_PIN // Ground power to the transmitter on this pin #define PIN_RF_TX_DATA_0 D4 // Data to the 433Mhz transmitter on this pin From 99a6c062355d34bdcd070e3837073548ac4604a0 Mon Sep 17 00:00:00 2001 From: couin3 <35873376+couin3@users.noreply.github.com> Date: Fri, 1 May 2020 17:32:52 +0200 Subject: [PATCH 46/46] TX Plugins do not handle RF Radio power pins anymore --- RFLink/Plugins/Plugin_003.c | 24 ------------------------ RFLink/Plugins/Plugin_005.c | 8 -------- RFLink/Plugins/Plugin_006.c | 7 ------- RFLink/Plugins/Plugin_007.c | 8 -------- RFLink/Plugins/Plugin_008.c | 7 ------- RFLink/Plugins/Plugin_009.c | 8 -------- RFLink/Plugins/Plugin_010.c | 8 -------- RFLink/Plugins/Plugin_011.c | 14 -------------- RFLink/Plugins/Plugin_012.c | 7 ------- RFLink/Plugins/Plugin_015.c | 7 ------- RFLink/Plugins/Plugin_070.c | 8 -------- RFLink/Plugins/Plugin_073.c | 9 --------- RFLink/Plugins/Plugin_074.c | 8 -------- 13 files changed, 123 deletions(-) diff --git a/RFLink/Plugins/Plugin_003.c b/RFLink/Plugins/Plugin_003.c index 24a59f9c..96493d68 100644 --- a/RFLink/Plugins/Plugin_003.c +++ b/RFLink/Plugins/Plugin_003.c @@ -908,10 +908,6 @@ void Arc_Send(unsigned long bitstream) uint32_t fdatamask = 0x00000001; uint32_t fsendbuff; - digitalWrite(PIN_RF_RX_VCC, LOW); // Turn off power to the RF receiver - digitalWrite(PIN_RF_TX_VCC, HIGH); // Enable the 433Mhz transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { fsendbuff = bitstream; @@ -953,10 +949,6 @@ void Arc_Send(unsigned long bitstream) digitalWrite(PIN_RF_TX_DATA, LOW); // and lower the signal delayMicroseconds(fpulse * 31); } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // Turn the 433Mhz transmitter off - digitalWrite(PIN_RF_RX_VCC, HIGH); // Turn the 433Mhz receiver on - RFLinkHW(); } void NArc_Send(unsigned long bitstream) @@ -967,10 +959,6 @@ void NArc_Send(unsigned long bitstream) uint32_t fdatamask = 0x00000001; uint32_t fsendbuff; - digitalWrite(PIN_RF_RX_VCC, LOW); // Turn off power to the RF receiver - digitalWrite(PIN_RF_TX_VCC, HIGH); // Enable the 433Mhz transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { fsendbuff = bitstream; @@ -1012,10 +1000,6 @@ void NArc_Send(unsigned long bitstream) digitalWrite(PIN_RF_TX_DATA, LOW); // and lower the signal delayMicroseconds(fpulse * 31); } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // Turn thew 433Mhz transmitter off - digitalWrite(PIN_RF_RX_VCC, HIGH); // Turn the 433Mhz receiver on - RFLinkHW(); } void TriState_Send(unsigned long bitstream) @@ -1026,10 +1010,6 @@ void TriState_Send(unsigned long bitstream) uint32_t fdatamask = 0x00000003; uint32_t fsendbuff; - digitalWrite(PIN_RF_RX_VCC, LOW); // Turn off power to the RF receiver - digitalWrite(PIN_RF_TX_VCC, HIGH); // Enable the 433Mhz transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - // reverse data bits (2 by 2) for (unsigned short i = 0; i < 12; i++) { // reverse data bits (12 times 2 bits = 24 bits in total) @@ -1089,9 +1069,5 @@ void TriState_Send(unsigned long bitstream) digitalWrite(PIN_RF_TX_DATA, LOW); // and lower the signal delayMicroseconds(fpulse * 31); } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // Turn thew 433Mhz transmitter off - digitalWrite(PIN_RF_RX_VCC, HIGH); // Turn the 433Mhz receiver on - RFLinkHW(); } #endif //PLUGIN_TX_003 diff --git a/RFLink/Plugins/Plugin_005.c b/RFLink/Plugins/Plugin_005.c index cbee26a1..91fa6872 100644 --- a/RFLink/Plugins/Plugin_005.c +++ b/RFLink/Plugins/Plugin_005.c @@ -198,10 +198,6 @@ void Eurodomest_Send(unsigned long address) uint32_t fdatamask = 0x800000; uint32_t fsendbuff; - digitalWrite(PIN_RF_RX_VCC, LOW); // Turn off power to the RF receiver - digitalWrite(PIN_RF_TX_VCC, HIGH); // Enable the 433Mhz transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { fsendbuff = address; @@ -232,9 +228,5 @@ void Eurodomest_Send(unsigned long address) digitalWrite(PIN_RF_TX_DATA, LOW); // and lower the signal delayMicroseconds(fpulse * 32); } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // Turn the 433Mhz transmitter off - digitalWrite(PIN_RF_RX_VCC, HIGH); // Turn the 433Mhz receiver on - RFLinkHW(); } #endif //PLUGIN_TX_005 diff --git a/RFLink/Plugins/Plugin_006.c b/RFLink/Plugins/Plugin_006.c index 79aa0529..e5433acd 100644 --- a/RFLink/Plugins/Plugin_006.c +++ b/RFLink/Plugins/Plugin_006.c @@ -241,9 +241,6 @@ void Blyss_Send(unsigned long address, byte devtype) uint32_t fsendbuff; unsigned char RollingCode[] = {0x98, 0xDA, 0x1E, 0xE6, 0x67, 0x98}; - digitalWrite(PIN_RF_RX_VCC, LOW); // Power off the RF receiver - digitalWrite(PIN_RF_TX_VCC, HIGH); // Turn on the RF transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) byte temp = (millis() & 0xff); // used for the timestamp at the end of the RF packet for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { @@ -339,9 +336,5 @@ void Blyss_Send(unsigned long address, byte devtype) //delayMicroseconds(fpulse * 18); // delay between RF retransmits delay(24); // delay 23.8 ms } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // turn off the RF transmitter - digitalWrite(PIN_RF_RX_VCC, HIGH); // power on the RF receiver - RFLinkHW(); } #endif // PLUGIN_TX_006 diff --git a/RFLink/Plugins/Plugin_007.c b/RFLink/Plugins/Plugin_007.c index a76e980e..253369d8 100644 --- a/RFLink/Plugins/Plugin_007.c +++ b/RFLink/Plugins/Plugin_007.c @@ -361,10 +361,6 @@ void RSL2_Send(unsigned long address) uint32_t fdatamask = 0x80000000; uint32_t fsendbuff; - digitalWrite(PIN_RF_RX_VCC, LOW); // Spanning naar de RF ontvanger uit om interferentie met de zender te voorkomen. - digitalWrite(PIN_RF_TX_VCC, HIGH); // zet de 433Mhz zender aan - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { fsendbuff = address; @@ -401,9 +397,5 @@ void RSL2_Send(unsigned long address) digitalWrite(PIN_RF_TX_DATA, LOW); delayMicroseconds(fpulse * 14); } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // zet de 433Mhz zender weer uit - digitalWrite(PIN_RF_RX_VCC, HIGH); // Spanning naar de RF ontvanger weer aan. - RFLinkHW(); } #endif // PLUGIN_TX_007 diff --git a/RFLink/Plugins/Plugin_008.c b/RFLink/Plugins/Plugin_008.c index 4bfc4a33..18457585 100644 --- a/RFLink/Plugins/Plugin_008.c +++ b/RFLink/Plugins/Plugin_008.c @@ -217,9 +217,6 @@ void Kambrook_Send(unsigned long address) uint32_t fdatamask = 0x800000; uint32_t fsendbuff; - digitalWrite(PIN_RF_RX_VCC, LOW); // Spanning naar de RF ontvanger uit om interferentie met de zender te voorkomen. - digitalWrite(PIN_RF_TX_VCC, HIGH); // zet de 433Mhz zender aan - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { // -------------- @@ -298,9 +295,5 @@ void Kambrook_Send(unsigned long address) digitalWrite(PIN_RF_TX_DATA, LOW); delayMicroseconds(fpulse2 * 14); } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // zet de 433Mhz zender weer uit - digitalWrite(PIN_RF_RX_VCC, HIGH); // Spanning naar de RF ontvanger weer aan. - RFLinkHW(); } #endif // PLUGIN_008 diff --git a/RFLink/Plugins/Plugin_009.c b/RFLink/Plugins/Plugin_009.c index 604712f1..258e6727 100644 --- a/RFLink/Plugins/Plugin_009.c +++ b/RFLink/Plugins/Plugin_009.c @@ -465,10 +465,6 @@ void X10_Send(uint32_t address) uint32_t fdatamask = 0x80000000; uint32_t fsendbuff; - digitalWrite(PIN_RF_RX_VCC, LOW); // Disable RF receiver - digitalWrite(PIN_RF_TX_VCC, HIGH); // Enable RF transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { fsendbuff = address; @@ -506,10 +502,6 @@ void X10_Send(uint32_t address) digitalWrite(PIN_RF_TX_DATA, LOW); delayMicroseconds(fpulse * 20); } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // Disable RF transmitter - digitalWrite(PIN_RF_RX_VCC, HIGH); // Enable RF receiver - RFLinkHW(); return; } #endif //PLUGIN_TX_009 diff --git a/RFLink/Plugins/Plugin_010.c b/RFLink/Plugins/Plugin_010.c index f31f550b..1991d80f 100644 --- a/RFLink/Plugins/Plugin_010.c +++ b/RFLink/Plugins/Plugin_010.c @@ -246,10 +246,6 @@ void TRC02_Send(unsigned long address, int command) uint32_t fdatamask = 0x80000000; uint32_t fsendbuff; - digitalWrite(PIN_RF_RX_VCC, LOW); // Turn off power to the RF receiver - digitalWrite(PIN_RF_TX_VCC, HIGH); // Enable the 433Mhz transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { crc = 0; @@ -298,9 +294,5 @@ void TRC02_Send(unsigned long address, int command) delayMicroseconds(fpulse); } } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // Turn thew 433Mhz transmitter off - digitalWrite(PIN_RF_RX_VCC, HIGH); // Turn the 433Mhz receiver on - RFLinkHW(); } #endif //PLUGIN_TX_010 diff --git a/RFLink/Plugins/Plugin_011.c b/RFLink/Plugins/Plugin_011.c index 24c81fb9..3adb4524 100644 --- a/RFLink/Plugins/Plugin_011.c +++ b/RFLink/Plugins/Plugin_011.c @@ -281,9 +281,6 @@ void HomeConfort_Send(unsigned long data1, unsigned long data2) { // bitstream1 holds first 24 bits of the RF data, bitstream2 holds last 24 bits of the RF data // ------------------------------- // Prepare transmit - digitalWrite(PIN_RF_RX_VCC,LOW); // Turn off power to the RF receiver - digitalWrite(PIN_RF_TX_VCC,HIGH); // Enable the 433Mhz transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) // send bits for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { data1=bitstream1; @@ -338,10 +335,6 @@ void HomeConfort_Send(unsigned long data1, unsigned long data2) { } // End transmit - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC,LOW); // Turn thew 433Mhz transmitter off - digitalWrite(PIN_RF_RX_VCC,HIGH); // Turn the 433Mhz receiver on - RFLinkHW(); } void HomeConfort_Send(unsigned long data1, unsigned long data2) { @@ -366,9 +359,6 @@ void HomeConfort_Send(unsigned long data1, unsigned long data2) { // bitstream1 holds first 24 bits of the RF data, bitstream2 holds last 24 bits of the RF data // ------------------------------- // Prepare transmit - digitalWrite(PIN_RF_RX_VCC,LOW); // Turn off power to the RF receiver - digitalWrite(PIN_RF_TX_VCC,HIGH); // Enable the 433Mhz transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) // send bits for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { data1=bitstream1; @@ -426,10 +416,6 @@ void HomeConfort_Send(unsigned long data1, unsigned long data2) { } // End transmit - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC,LOW); // Turn thew 433Mhz transmitter off - digitalWrite(PIN_RF_RX_VCC,HIGH); // Turn the 433Mhz receiver on - RFLinkHW(); } */ /* diff --git a/RFLink/Plugins/Plugin_012.c b/RFLink/Plugins/Plugin_012.c index 125a548d..2f8eeee4 100644 --- a/RFLink/Plugins/Plugin_012.c +++ b/RFLink/Plugins/Plugin_012.c @@ -304,9 +304,6 @@ void Flamingo_Send(int fbutton, int fcmd) //fsendbuff3=0xDB58C5D0; //fsendbuff4=0xDBF40A90; } - digitalWrite(PIN_RF_RX_VCC, LOW); // Spanning naar de RF ontvanger uit om interferentie met de zender te voorkomen. - digitalWrite(PIN_RF_TX_VCC, HIGH); // zet de 433Mhz zender aan - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) for (int nRepeat = 0; nRepeat < fretrans; nRepeat++) { @@ -354,9 +351,5 @@ void Flamingo_Send(int fbutton, int fcmd) //digitalWrite(PIN_RF_TX_DATA, LOW); //delayMicroseconds(fpulse * 15); } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // zet de 433Mhz zender weer uit - digitalWrite(PIN_RF_RX_VCC, HIGH); // Spanning naar de RF ontvanger weer aan. - RFLinkHW(); } #endif //PLUGIN_TX_012 diff --git a/RFLink/Plugins/Plugin_015.c b/RFLink/Plugins/Plugin_015.c index cbd9f80a..c6ea9d48 100644 --- a/RFLink/Plugins/Plugin_015.c +++ b/RFLink/Plugins/Plugin_015.c @@ -229,9 +229,6 @@ void HomeEasyEU_Send(unsigned long address, unsigned long command) uint32_t fdatamask = 0x80000000; uint32_t fsendbuff; - digitalWrite(PIN_RF_RX_VCC, LOW); // Spanning naar de RF ontvanger uit om interferentie met de zender te voorkomen. - digitalWrite(PIN_RF_TX_VCC, HIGH); // zet de 433Mhz zender aan - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { // -------------- Send Home Easy preamble (0x63c) - 11 bits @@ -310,9 +307,5 @@ void HomeEasyEU_Send(unsigned long address, unsigned long command) digitalWrite(PIN_RF_TX_DATA, LOW); // and lower the signal delayMicroseconds(fpulse * 26); } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // zet de 433Mhz zender weer uit - digitalWrite(PIN_RF_RX_VCC, HIGH); // Spanning naar de RF ontvanger weer aan. - RFLinkHW(); } #endif // PLUGIN_TX_015 diff --git a/RFLink/Plugins/Plugin_070.c b/RFLink/Plugins/Plugin_070.c index 2e2efffe..ad5bd4ef 100644 --- a/RFLink/Plugins/Plugin_070.c +++ b/RFLink/Plugins/Plugin_070.c @@ -145,10 +145,6 @@ void SelectPlus_Send(unsigned long address) uint32_t fdatamask = 0x10000; uint32_t fsendbuff; - digitalWrite(PIN_RF_RX_VCC, LOW); // Power off the RF receiver (if wired that way) to protect against interference - digitalWrite(PIN_RF_TX_VCC, HIGH); // Enable 433Mhz transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { fsendbuff = address; @@ -184,9 +180,5 @@ void SelectPlus_Send(unsigned long address) delayMicroseconds(fpulse * 16); // delay between RF transmits } } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // Disable the 433Mhz transmitter - digitalWrite(PIN_RF_RX_VCC, HIGH); // Enable the 433Mhz receiver - RFLinkHW(); } #endif // PLUGIN_070 diff --git a/RFLink/Plugins/Plugin_073.c b/RFLink/Plugins/Plugin_073.c index 9b6a1667..9a7e8ba4 100644 --- a/RFLink/Plugins/Plugin_073.c +++ b/RFLink/Plugins/Plugin_073.c @@ -141,10 +141,6 @@ void Deltronic_Send(unsigned long address) periodLong = 2 * period; periodSync = 36 * period; - digitalWrite(PIN_RF_RX_VCC, LOW); // Power off the RF receiver (if wired that way) to protect against interference - digitalWrite(PIN_RF_TX_VCC, HIGH); // Enable 433Mhz transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - // Send seperator digitalWrite(PIN_RF_TX_DATA, HIGH); delayMicroseconds(period); @@ -184,11 +180,6 @@ void Deltronic_Send(unsigned long address) digitalWrite(PIN_RF_TX_DATA, HIGH); delayMicroseconds(period); } - digitalWrite(PIN_RF_TX_DATA, LOW); - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // Disable the 433Mhz transmitter - digitalWrite(PIN_RF_RX_VCC, HIGH); // Enable the 433Mhz receiver - RFLinkHW(); } #endif // PLUGIN_TX_073 diff --git a/RFLink/Plugins/Plugin_074.c b/RFLink/Plugins/Plugin_074.c index 4abae39c..624bb228 100644 --- a/RFLink/Plugins/Plugin_074.c +++ b/RFLink/Plugins/Plugin_074.c @@ -148,10 +148,6 @@ void RL02_Send(unsigned long address) uint32_t fdatamask = 0x00000001; uint32_t fsendbuff; - digitalWrite(PIN_RF_RX_VCC, LOW); // Turn off power to the RF receiver - digitalWrite(PIN_RF_TX_VCC, HIGH); // Enable the 433Mhz transmitter - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - for (int nRepeat = 0; nRepeat <= fretrans; nRepeat++) { fsendbuff = address; @@ -219,9 +215,5 @@ void RL02_Send(unsigned long address) digitalWrite(PIN_RF_TX_DATA, LOW); // and lower the signal delayMicroseconds(fpulse * 31); } - delayMicroseconds(TRANSMITTER_STABLE_DELAY); // short delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms) - digitalWrite(PIN_RF_TX_VCC, LOW); // Turn thew 433Mhz transmitter off - digitalWrite(PIN_RF_RX_VCC, HIGH); // Turn the 433Mhz receiver on - RFLinkHW(); } #endif // PLUGIN_TX_074