diff --git a/RFLink/1_Radio.cpp b/RFLink/1_Radio.cpp new file mode 100644 index 00000000..a91dacbc --- /dev/null +++ b/RFLink/1_Radio.cpp @@ -0,0 +1,123 @@ +// ************************************* // +// * Arduino Project RFLink-esp * // +// * https://github.com/couin3/RFLink * // +// * 2018..2020 Stormteam - Marc RIVES * // +// * More details in RFLink.ino file * // +// ************************************* // + +#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; +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; +#endif //AUTOCONNECT_ENABLED + +// Prototype +void enableRX(); +void disableRX(); +void enableTX(); +void disableTX(); + +Radio_State current_State = Radio_NA; + +void set_Radio_mode(Radio_State new_State) +{ + 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() +{ + // 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..1120afaa --- /dev/null +++ b/RFLink/1_Radio.h @@ -0,0 +1,98 @@ +// ************************************* // +// * 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 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 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 +#endif + +#ifdef ESP32 +#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_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_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_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_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_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_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 + +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/2_Signal.cpp b/RFLink/2_Signal.cpp index 59fa9498..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" @@ -256,7 +257,7 @@ boolean FetchSignal() */ /*********************************************************************************************\ Send rawsignal buffer to RF * DEPRICATED * DO NOT USE - \*********************************************************************************************/ +\*********************************************************************************************/ /* void RawSendRF(void) { // * DEPRICATED * DO NOT USE * int x; @@ -285,4 +286,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..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 { @@ -34,4 +43,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/3_Serial.cpp b/RFLink/3_Serial.cpp index 6540f87c..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 * // @@ -6,120 +6,258 @@ // ************************************* // #include -// #include "3_Serial.h" +#include "RFLink.h" +#include "1_Radio.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 CopySerial(char *); /*********************************************************************************************/ -/* + 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 + if (ReadSerial()) + { +#ifdef SERIAL_ENABLED + Serial.flush(); + Serial.print(F("Message arrived [Serial] ")); + Serial.println(InputBuffer_Serial); +#endif + if (CheckCmd()) + return true; + } + return false; +} + +boolean CheckMQTT(byte *byte_in) +{ + if (CopySerial((char *)byte_in)) + { +#ifdef SERIAL_ENABLED + Serial.flush(); + Serial.print(F("Message arrived [MQTT] ")); + Serial.println(InputBuffer_Serial); +#endif + if (CheckCmd()) + return true; + } + 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; - InputBuffer_Serial[0] = 0; // erase serial buffer string + 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)); +} +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 - while (millis() < FocusTimer) { // standby - if (Serial.available()) { + if (Serial.available()) + { + SerialInByteCounter = 0; + + 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; - - 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()) + 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; +} + +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 + // ------------------------------------------------------- + set_Radio_mode(Radio_TX); + + if (PluginTXCall(0, InputBuffer_Serial)) + ValidCommand = 1; + else // Answer that an invalid command was received? + ValidCommand = 2; + set_Radio_mode(Radio_RX); + } + } + } // if > 7 + if (ValidCommand != 0) + { + display_Header(); + if (ValidCommand == 1) + display_Name(PSTR("OK")); + else + 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..0da984a1 100644 --- a/RFLink/3_Serial.h +++ b/RFLink/3_Serial.h @@ -9,9 +9,15 @@ #define Serial_h #include -#include "RFLink.h" -//extern char InputBuffer_Serial[INPUT_COMMAND_SIZE]; // Buffer for Seriel data -// boolean CheckSerial(); +#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]; + +boolean CheckSerial(); +boolean CheckMQTT(byte *); +boolean CheckWeb(String &); #endif \ No newline at end of file diff --git a/RFLink/4_Display.cpp b/RFLink/4_Display.cpp index 18396aa0..fe913b78 100644 --- a/RFLink/4_Display.cpp +++ b/RFLink/4_Display.cpp @@ -6,6 +6,8 @@ // ************************************* // #include +#include "RFLink.h" +#include "3_Serial.h" #include "4_Display.h" byte PKSequenceNumber = 0; // 1 byte packet counter @@ -335,34 +337,291 @@ void display_RGBW(unsigned int input) strcat(pbuffer, dbuffer); } +// --------------------- // +// get label shared func // +// --------------------- // + +char *ptr; +const char c_delim[2] = ";"; +char c_label[12]; + +void retrieve_Init() +{ + ptr = strtok(InputBuffer_Serial, c_delim); +} + +boolean retrieve_Name(const char *c_Name) +{ + if (ptr != NULL) + { + if (strncasecmp(ptr, c_Name, strlen(c_Name)) != 0) + return false; + ptr = strtok(NULL, c_delim); + return true; + } + else + return false; +} + +boolean retrieve_ID(unsigned long &ul_ID) +{ + // ID + char c_ID[10]; + + 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; + + ptr = strtok(NULL, c_delim); + return true; + } + else + return false; +} + +boolean retrieve_Switch(byte &b_Switch) +{ + // Switch + char c_Switch[10]; + + 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 + + ptr = strtok(NULL, c_delim); + return true; + } + else + return false; +} + +boolean retrieve_Command(byte &b_Cmd, byte &b_Cmd2) +{ + // Command + char c_Cmd[10]; + + 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; + } + + ptr = strtok(NULL, c_delim); + return true; + } + else + return false; +} + +boolean retrieve_End() +{ + // End + if (ptr != NULL) + return false; + return true; +} + /*********************************************************************************************\ 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; +\*********************************************************************************************/ +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++; +// } +// } + +#ifdef AUTOCONNECT_ENABLED +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; } -*/ +} -void replacechar(char *str, char orig, char rep) +String GPIO2String(uint8_t uGPIO) { - char *ix = str; - int n = 0; - while ((ix = strchr(ix, orig)) != NULL) - { - *ix++ = rep; - n++; - } -} \ No newline at end of file + 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"; + } +} +#endif //AUTOCONNECT_ENABLED diff --git a/RFLink/4_Display.h b/RFLink/4_Display.h index 5ff67b75..8ed71b4e 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 @@ -22,12 +23,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 +60,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,7 +82,30 @@ void display_METER(unsigned int); void display_VOLT(unsigned int); void display_RGBW(unsigned int); -// int str2cmd(char *command) -void replacechar(char *, char, char); +void retrieve_Init(); +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); + +uint8_t String2GPIO(String); +String GPIO2String(uint8_t uGPIO); #endif \ No newline at end of file diff --git a/RFLink/5_Plugin.cpp b/RFLink/5_Plugin.cpp index a68f3902..57480d03 100644 --- a/RFLink/5_Plugin.cpp +++ b/RFLink/5_Plugin.cpp @@ -24,6 +24,10 @@ byte Plugin_id[PLUGIN_MAX]; byte Plugin_State[PLUGIN_MAX]; String Plugin_Description[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) @@ -1312,7 +1316,6 @@ void PluginInit(void) Plugin_ptr[x++] = &Plugin_255; #endif - // read config file to desactivated protocols #ifdef AUTOCONNECT_ENABLED @@ -1352,449 +1355,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 +#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]; - -enum PState {P_Forbidden, P_Disabled, P_Enabled, P_Mandatory}; extern byte Plugin_State[PLUGIN_MAX]; extern String Plugin_Description[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) 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); +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 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 e35e01c9..e0e8ac2b 100644 --- a/RFLink/6_WiFi_MQTT.cpp +++ b/RFLink/6_WiFi_MQTT.cpp @@ -7,13 +7,13 @@ #include #include "RFLink.h" - +#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" +#else +#include "6_Credentials.h" #endif #ifndef AUTOCONNECT_ENABLED @@ -39,8 +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); +static String WIFI_PWR = String(WIFI_PWR_0); void setup_WIFI() { @@ -76,25 +78,20 @@ void setup_WIFI() void setup_MQTT() { - if (MQTT_PORT == "") MQTT_PORT = "1883"; // just in case .... + if (MQTT_PORT == "") + MQTT_PORT = "1883"; // just in case .... 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); +} +#ifdef AUTOCONNECT_ENABLED void reconnect() { // MQTT connection (documented way from AutoConnect : https://github.com/Hieromon/AutoConnect/tree/master/examples/mqttRSSI_NA) @@ -103,23 +100,28 @@ void reconnect() { // MQTTClient.setServer(serverName.c_str(), Mqtt_Port.toInt()); - Serial.println(String("Attempting MQTT broker:") + MQTT_SERVER.c_str()); + Serial.print(F("Attempting MQTT broker : ")); + Serial.println(MQTT_SERVER.c_str()); if (MQTTClient.connect(MQTT_ID.c_str(), MQTT_USER.c_str(), MQTT_PSWD.c_str())) { // Once connected, resubscribe - // MQTTClient.subscribe(MQTT_TOPIC_IN.c_str()); - Serial.println("MQTT connection Established"); //+ String(clientId)); - // ... and resubscribe - //return true; + MQTTClient.subscribe(MQTT_TOPIC_IN.c_str()); + Serial.print(F("MQTT connection Established : ")); + Serial.println(MQTT_ID.c_str()); + MQTTClient.subscribe(MQTT_TOPIC_IN.c_str()); } else { - Serial.println("Connection mqttserver:" + String(MQTT_SERVER.c_str())); - Serial.println("Connection Mqtt_ID:" + String(MQTT_ID.c_str())); - Serial.println("Connection Mqtt_Username:" + String(MQTT_USER.c_str())); - Serial.println("Connection Mqtt_Password: ********"); - Serial.println("Connection failed:" + String(MQTTClient.state())); + Serial.print(F("Connection MQTT_Server : ")); + Serial.println(MQTT_SERVER.c_str()); + Serial.print(F("Connection MQTT_ID : ")); + Serial.println(MQTT_ID.c_str()); + Serial.print(F("Connection MQTT_Username : ")); + Serial.println(MQTT_USER.c_str()); + Serial.print(F("Connection MQTT_Password : ********")); + Serial.print(F("Connection failed : ")); + Serial.println(MQTTClient.state()); if (!--retry) break; delay(500); @@ -127,40 +129,33 @@ void reconnect() } } - - -// 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())) -// { -// Serial.println(F("Connected")); -// // Once connected, resubscribe -// // MQTTClient.subscribe(ac_MQTT_TOPIC_IN.c_str()); -// } -// else -// { -// Serial.print(F("\nFailed, rc=")); -// Serial.print(MQTTClient.state()); -// Serial.println(F("\tTry again in 5 seconds")); -// // Wait 5 seconds before retrying -// for (byte i = 0; i < 10; i++) -// delay(500); // delay(5000) may cause hang -// if (!--retry) -// break; -// delay(500); -// } - -// } -// } +#else +void reconnect() +{ + // Loop until we're reconnected + // delay(1); + while (!MQTTClient.connected()) + { + Serial.print(F("Attempting MQTT connection...")); + // Attempt to connect + if (MQTTClient.connect(MQTT_ID.c_str(), MQTT_USER.c_str(), MQTT_PSWD.c_str())) + { + Serial.println(F("Connected")); + // Once connected, resubscribe + MQTTClient.subscribe(MQTT_TOPIC_IN.c_str()); + } + else + { + Serial.print(F("\nFailed, rc=")); + Serial.print(MQTTClient.state()); + Serial.println(F("\tTry again in 5 seconds")); + // Wait 5 seconds before retrying + for (byte i = 0; i < 10; i++) + delay(500); // delay(5000) may cause hang + } + } +} +#endif // AUTOCONNECT_ENABLED void publishMsg() { diff --git a/RFLink/6_WiFi_MQTT.h b/RFLink/6_WiFi_MQTT.h index 8ded26d2..105daab5 100644 --- a/RFLink/6_WiFi_MQTT.h +++ b/RFLink/6_WiFi_MQTT.h @@ -11,13 +11,24 @@ #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; +#else #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/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 4b52d909..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 @@ -46,7 +47,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/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(); diff --git a/RFLink/9_AutoConnect.cpp b/RFLink/9_AutoConnect.cpp index 19258c4f..417fcce2 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 * // // ************************************* // @@ -9,6 +11,7 @@ #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" @@ -42,6 +45,20 @@ 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; +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); @@ -50,6 +67,13 @@ String saveParams(AutoConnectAux &aux, PageArgument &args); 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é @@ -163,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
"; @@ -184,13 +208,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++) @@ -221,7 +257,7 @@ void rootPage() content += ""; // we add a last line to bottom of the table content += "
NameEnabled
Plugin NameEnabled
"; - content += ""; + content += ""; content += ""; content += ""; @@ -258,12 +294,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); ///////////////// @@ -296,7 +333,6 @@ void setup_AutoConnect() yield(); } } - //SPIFFS.end(); WebServer &webServer = portal.host(); webServer.on("/", rootPage); @@ -319,7 +355,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(); @@ -340,6 +376,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 @@ -350,11 +400,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")); @@ -362,9 +412,8 @@ String loadParams(AutoConnectAux &aux, PageArgument &args) else { Serial.println(F(" failed to load")); - //if (initConfig) } - my_file.close(); + paramFile.close(); } else { @@ -374,7 +423,6 @@ String loadParams(AutoConnectAux &aux, PageArgument &args) #endif // ESP32 } SPIFFS.end(); - //initConfig = false; return String(""); } @@ -413,7 +461,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(); } @@ -448,6 +502,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 @@ -457,4 +538,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 b7717866..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 @@ -56,18 +59,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(); @@ -82,7 +73,7 @@ void HandleLastMsg(); static const char AUX_settings[] PROGMEM = R"raw( [ { - "title": "MQTT settings", + "title": "RFLink settings", "uri": "/settings", "menu": true, "element": [ @@ -127,14 +118,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", @@ -221,6 +210,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", 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_004.c b/RFLink/Plugins/Plugin_004.c index 1f8a80fe..be345fa8 100644 --- a/RFLink/Plugins/Plugin_004.c +++ b/RFLink/Plugins/Plugin_004.c @@ -141,7 +141,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 @@ -151,12 +151,13 @@ boolean Plugin_004(byte function, char *string) #endif // Plugin_004 #ifdef PLUGIN_TX_004 -void AC_Send(unsigned long data, byte cmd); +#include "../3_Serial.h" +#include "../4_Display.h" 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; @@ -164,214 +165,47 @@ boolean PluginTX_004(byte function, char *string) //10;NewKaku;306070b;f;ON; //10;NewKaku;306070b;10;ON; //01234567890123456789012 - if (strncasecmp(InputBuffer_Serial + 3, "NEWKAKU;", 8) == 0) - { - byte x = 18; // pointer to the switch number - if (InputBuffer_Serial[17] != ';') - { - if (InputBuffer_Serial[18] != ';') - { - return false; - } - else - { - x = 19; - } - } - unsigned long bitstream = 0L; - unsigned long tempaddress = 0L; - byte cmd = 0; - //byte c=0; // MRI commented - byte Address = 0; // Address 1..16 + 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 - // ----- - 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 - { - return false; - } - } - 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 - // ----- - 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. + retrieve_Init(); + if (!retrieve_Name("10")) + return false; + if (!retrieve_Name("Newkaku")) + return false; + if (!retrieve_ID(ID_bitstream)) + return false; + if (!retrieve_Switch(Switch_bitstream)) + return false; + if (!retrieve_Command(Cmd_bitstream, Cmd_dimmer)) + return false; + if (!retrieve_End()) + return false; - // Dimming of groups is also possible but not supported yet! - // when level=0 is it better to transmit just the off command ? + // --------------- 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"); - 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 ------------ - AC_Send(bitstream, cmd); - success = true; - } - // -------------------------------------- - return success; -} -void AC_Send(unsigned long data, byte cmd) -{ - int fpulse = 260; // Pulse width in microseconds - int fretrans = 10; // Number of code retransmissions + bitstream = (ID_bitstream << 6); // 26 bits on top + bitstream |= Switch_bitstream; // Complete transmitted address + // bitstream &= 0xFFFFFFCF; // Bit 4 and 5 are left for cmd + bitstream |= (Cmd_bitstream << 4); - unsigned long bitstream = 0L; - byte command; - // 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); // 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); // 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(); + + + // bitstream now contains the AC/NewKAKU-bits that have to be transmitted + // --------------- NEWKAKU SEND ------------ + + AC_Send(bitstream, Cmd_dimmer); + + // -------------------------------------- + return true; } + #endif // Plugin_TX_004 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 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 4c7904ed..d1fcd68c 100644 --- a/RFLink/RFLink.h +++ b/RFLink/RFLink.h @@ -8,83 +8,11 @@ #ifndef RFLink_h #define RFLink_h -// -#define BUILDNR 0x02 // 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 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 -#define PLUGIN_TX_MAX 0 // 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. - -/* -#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 -#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 -#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 -#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 -#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 -#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)) @@ -96,7 +24,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_0 false // Retained option #endif @@ -106,4 +34,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) -#endif // RFLink_h +void CallReboot(void); + +#endif diff --git a/RFLink/RFLink.ino b/RFLink/RFLink.ino index e2354083..aa355181 100644 --- a/RFLink/RFLink.ino +++ b/RFLink/RFLink.ino @@ -18,7 +18,9 @@ // **************************************************************************** #include #include "RFLink.h" +#include "1_Radio.h" #include "2_Signal.h" +#include "3_Serial.h" #include "4_Display.h" #include "5_Plugin.h" #include "6_WiFi_MQTT.h" @@ -29,12 +31,27 @@ #include #endif //**************************************************************************************************************************************** +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 -void sendMsg(); // See at bottom +#if (defined(ESP8266) || defined(ESP32)) +void CallReboot(void) +{ + sendMsg(); + delay(1); + ESP.restart(); +} +#endif void setup() { @@ -50,24 +67,10 @@ 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); + set_Radio_mode(Radio_OFF); PluginInit(); + PluginTXInit(); #if (!defined(AUTOCONNECT_ENABLED) && !defined(MQTT_ENABLED)) #if (defined(ESP32) || defined(ESP8266)) @@ -106,23 +109,37 @@ void setup() splash_OLED(); #endif pbuffer[0] = 0; - - delay(100); + set_Radio_mode(Radio_RX); } void loop() { #ifdef AUTOCONNECT_ENABLED loop_AutoConnect(); -#endif -#ifdef MQTT_ENABLED if (WiFi.status() == WL_CONNECTED) { - checkMQTTloop(); - } #endif - if (ScanEvent()) +#ifdef MQTT_ENABLED + checkMQTTloop(); sendMsg(); +#endif + +#ifdef SERIAL_ENABLED + if (CheckSerial()) + sendMsg(); +#endif + +#ifdef AUTOCONNECT_ENABLED + if (CheckWeb(CmdMsg)) + sendMsg(); +#endif + + if (ScanEvent()) + sendMsg(); + +#ifdef AUTOCONNECT_ENABLED + } +#endif } void sendMsg() @@ -136,7 +153,7 @@ void sendMsg() publishMsg(); #endif #ifdef AUTOCONNECT_ENABLED - LastMsg = pbuffer; + LastMsg = pbuffer; #endif #ifdef OLED_ENABLED print_OLED(); @@ -144,4 +161,5 @@ void sendMsg() pbuffer[0] = 0; } } + /*********************************************************************************************/ diff --git a/platformio.ini b/platformio.ini index 06a05181..83145d34 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,10 +24,11 @@ upload_speed = 921600 lib_deps = ESP8266WiFi PubSubClient + Autoconnect PageBuilder ArduinoJson - ;Wire - ;U8g2 +; ;Wire +; ;U8g2 ;[env:nodemcuv2] ;platform = espressif8266