Update of rtl_433_ESP to version 0.1.3 - Support for SX127X transceiver module (#1291)

The main features of the upgrade to 0.1.3 of rtl_433_ESP are

1 - Change Transceiver Library to RadioLib

2 - Add support for SX127X transceiver module ( I used the 433 Mhz version of this Heltec module for development ).

3 - Added automatic calibration of the RSSI Signal detection Threshold

4 - Removed dependency on loop for start and end of signal detection, and moved to a ESP32 Task

5 - Moved received signal decoding to a ESP32 Task

6 - Identified Blueline PowerCost Monitor decoder as source of significant memory overhead and disabled.

7 - Multi Receiver support has been validated with RF, RF2 and PiLight
This commit is contained in:
Northern Man authored and GitHub committed 2022-10-20 11:14:45 -05:00
1 parent c570eead82
commit 8bc65d62dc
10 files changed
+186 -73

No files matched your search

+1 -1
View File
@@ -478,7 +478,7 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
# define STRTO_UL_ULL strtoul
#endif
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation)
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation) || defined(ZgatewayRTL_433)
// variable to avoid duplicates
# ifndef time_avoid_duplicate
# define time_avoid_duplicate 3000 // if you want to avoid duplicate MQTT message received set this to > 0, the value is the time in milliseconds during which we don't publish duplicates
+9 -9
View File
@@ -1,19 +1,19 @@
/*
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
/*
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Send and receiving command by MQTT
HELTEC ESP32 LORA - SSD1306 / Onboard 0.96-inch 128*64 dot matrix OLED display
Copyright: (c)Florian ROBERT
Contributors:
- 1technophile
- NorthernMan54
This file is part of OpenMQTTGateway.
OpenMQTTGateway is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
@@ -255,4 +255,4 @@ void OledSerial::drawLogo(int logoSize, int circle1X, int circle1Y, bool circle1
delay(50);
}
#endif
#endif
+9 -2
View File
@@ -187,7 +187,10 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
int msgLength = rf.stringToPulseTrain(raw, codes, MAXPULSESTREAMLENGTH);
if (msgLength > 0) {
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
disableActiveReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(receiveMhz); // set Transmit on
rf.disableReceiver();
# endif
rf.sendPulseTrain(codes, msgLength, repeats);
@@ -215,7 +218,10 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
if (message && protocol) {
Log.trace(F("MQTTtoPilight msg & protocol ok" CR));
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
disableActiveReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(receiveMhz); // set Transmit on
rf.disableReceiver();
# endif
int msgLength = rf.send(protocol, message);
@@ -287,6 +293,7 @@ extern void enablePilightReceive() {
# endif
# ifdef ZradioCC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
rf.setCallback(pilightCallback);
+3
View File
@@ -176,6 +176,7 @@ void RFtoMQTT() {
# if simpleReceiving
void MQTTtoRF(char* topicOri, char* datacallback) {
# ifdef ZradioCC1101 // set Receive off and Transmitt on
disableActiveReceiver();
ELECHOUSE_cc1101.SetTx(receiveMhz);
# endif
mySwitch.disableReceive();
@@ -251,6 +252,7 @@ void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding
# ifdef ZradioCC1101 // set Receive off and Transmitt on
float trMhz = RFdata["mhz"] | CC1101_FREQUENCY;
if (validFrequency((int)trMhz)) {
disableActiveReceiver();
ELECHOUSE_cc1101.SetTx(trMhz);
Log.notice(F("Transmit mhz: %F" CR), trMhz);
}
@@ -321,6 +323,7 @@ void enableRFReceive() {
# endif
# ifdef ZradioCC1101 // set Receive on and Transmitt off
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz);
# endif
mySwitch.disableTransmit();
+8 -1
View File
@@ -152,6 +152,9 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
void MQTTtoRF2(char* topicOri, char* datacallback) {
# ifdef ZradioCC1101
NewRemoteReceiver::disable();
disableActiveReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
# endif
@@ -268,6 +271,9 @@ void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding
if (boolSWITCHTYPE != 99) {
# ifdef ZradioCC1101
NewRemoteReceiver::disable();
disableActiveReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
# endif
Log.trace(F("MQTTtoRF2 switch type ok" CR));
@@ -356,10 +362,11 @@ void enableRF2Receive() {
disableRFReceive();
# endif
NewRemoteReceiver::init(RF_RECEIVER_GPIO, 2, rf2Callback);
# ifdef ZradioCC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
NewRemoteReceiver::init(RF_RECEIVER_GPIO, 2, rf2Callback);
}
#endif
+34 -18
View File
@@ -28,17 +28,12 @@
*/
#include "User_config.h"
#ifdef ZgatewayRTL_433
# ifndef ZradioCC1101
# error "CC1101 is the only supported receiver module for RTL_433 and needs to be enabled."
# endif
# include <rtl_433_ESP.h>
char messageBuffer[JSON_MSG_BUFFER];
rtl_433_ESP rtl_433(-1); // use -1 to disable transmitter
# include <ELECHOUSE_CC1101_SRC_DRV.h>
rtl_433_ESP rtl_433(-1);
void rtl_433_Callback(char* message) {
DynamicJsonDocument jsonBuffer2(JSON_MSG_BUFFER);
@@ -49,6 +44,7 @@ void rtl_433_Callback(char* message) {
return;
}
unsigned long MQTTvalue = (int)RFrtl_433_ESPdata["id"] + round(RFrtl_433_ESPdata["temperature_C"]);
String topic = String(subjectRTL_433toMQTT);
# if valueAsATopic
String model = RFrtl_433_ESPdata["model"];
@@ -61,14 +57,16 @@ void rtl_433_Callback(char* message) {
}
# endif
pub((char*)topic.c_str(), RFrtl_433_ESPdata);
if (!isAduplicateSignal(MQTTvalue)) {
pub((char*)topic.c_str(), RFrtl_433_ESPdata);
storeSignalValue(MQTTvalue);
}
# ifdef MEMORY_DEBUG
Log.trace(F("Post rtl_433_Callback: %d" CR), ESP.getFreeHeap());
# endif
}
void setupRTL_433() {
rtl_433.initReceiver(RF_RECEIVER_GPIO, receiveMhz);
rtl_433.setCallback(rtl_433_Callback, messageBuffer, JSON_MSG_BUFFER);
Log.trace(F("ZgatewayRTL_433 command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRTL_433);
Log.notice(F("ZgatewayRTL_433 setup done " CR));
@@ -93,16 +91,24 @@ extern void MQTTtoRTL_433(char* topicOri, JsonObject& RTLdata) {
success = true;
}
if (RTLdata.containsKey("rssi")) {
int minimumRssi = RTLdata["rssi"] | 0;
Log.notice(F("RTL_433 minimum RSSI: %d" CR), minimumRssi);
rtl_433.setMinimumRSSI(minimumRssi);
int rssiThreshold = RTLdata["rssi"] | 0;
Log.notice(F("RTL_433 RSSI Threshold Delta: %d " CR), rssiThreshold);
rtl_433.setRSSIThreshold(rssiThreshold);
success = true;
}
# if defined(RF_SX1276) || defined(RF_SX1278)
if (RTLdata.containsKey("ookThreshold")) {
int newOokThreshold = RTLdata["ookThreshold"] | 0;
Log.notice(F("RTL_433 ookThreshold %d" CR), newOokThreshold);
rtl_433.setOOKThreshold(newOokThreshold);
success = true;
}
# endif
if (RTLdata.containsKey("debug")) {
int debug = RTLdata["debug"] | -1;
Log.notice(F("RTL_433 set debug: %d" CR), debug);
rtl_433.setDebug(debug);
rtl_433.initReceiver(RF_RECEIVER_GPIO, receiveMhz);
// rtl_433.setDebug(debug);
rtl_433.initReceiver(RF_MODULE_RECEIVER_GPIO, receiveMhz);
success = true;
}
if (RTLdata.containsKey("status")) {
@@ -131,9 +137,9 @@ extern void enableRTLreceive() {
# ifdef ZgatewayPilight
disablePilightReceive();
# endif
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
rtl_433.enableReceiver(RF_RECEIVER_GPIO);
pinMode(RF_EMITTER_GPIO, OUTPUT); // Set this here, because if this is the RX pin it was reset to INPUT by Serial.end();
rtl_433.initReceiver(RF_MODULE_RECEIVER_GPIO, receiveMhz);
rtl_433.enableReceiver(RF_MODULE_RECEIVER_GPIO);
}
extern void disableRTLreceive() {
@@ -142,8 +148,12 @@ extern void disableRTLreceive() {
rtl_433.disableReceiver();
}
extern int getRTLMinimumRSSI() {
return rtl_433.minimumRssi;
extern int getRTLrssiThreshold() {
return rtl_433.rssiThreshold;
}
extern int getRTLAverageRSSI() {
return rtl_433.averageRssi;
}
extern int getRTLCurrentRSSI() {
@@ -154,4 +164,10 @@ extern int getRTLMessageCount() {
return rtl_433.messageCount;
}
# if defined(RF_SX1276) || defined(RF_SX1278)
extern int getOOKThresh() {
return rtl_433.OokFixedThreshold;
}
# endif
#endif
+8 -8
View File
@@ -1,19 +1,19 @@
/*
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Send and receiving command by MQTT
HELTEC ESP32 LORA - SSD1306 / Onboard 0.96-inch 128*64 dot matrix OLED display
Copyright: (c)Florian ROBERT
Contributors:
- 1technophile
- NorthernMan54
This file is part of OpenMQTTGateway.
OpenMQTTGateway is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
@@ -113,4 +113,4 @@ protected:
extern OledSerial Oled;
#endif
#endif
+34 -7
View File
@@ -63,13 +63,9 @@ extern void setupRTL_433();
extern void MQTTtoRTL_433(char* topicOri, JsonObject& RTLdata);
extern void enableRTLreceive();
extern void disableRTLreceive();
extern int getRTLMinimumRSSI();
extern int getRTLrssiThreshold();
extern int getRTLCurrentRSSI();
extern int getRTLMessageCount();
/**
* minimumRssi minimum RSSI value to enable receiver
*/
int minimumRssi = 0;
#endif
/*-------------------RF topics & parameters----------------------*/
//433Mhz MQTT Subjects and keys
@@ -118,7 +114,7 @@ int minimumRssi = 0;
# define CC1101_FREQUENCY 433.92
#endif
// Allow ZGatewayRF Module to change receive frequency of CC1101 Transceiver module
#ifdef ZradioCC1101
#if defined(ZradioCC1101) || defined(ZradioSX127x)
float receiveMhz = CC1101_FREQUENCY;
#endif
@@ -164,7 +160,7 @@ int activeReceiver = 0;
# define ACTIVE_RTL 3
# define ACTIVE_RF2 4
# ifdef ZradioCC1101
# if defined(ZradioCC1101) || defined(ZradioSX127x)
bool validFrequency(float mhz) {
// CC1101 valid frequencies 300-348 MHZ, 387-464MHZ and 779-928MHZ.
if (mhz >= 300 && mhz <= 348)
@@ -265,6 +261,37 @@ void enableActiveReceiver(bool isBoot) {
}
currentReceiver = activeReceiver;
}
void disableActiveReceiver() {
Log.trace(F("disableActiveReceiver: %d" CR), activeReceiver);
switch (activeReceiver) {
# ifdef ZgatewayPilight
case ACTIVE_PILIGHT:
disablePilightReceive();
break;
# endif
# ifdef ZgatewayRF
case ACTIVE_RF:
disableRFReceive();
break;
# endif
# ifdef ZgatewayRTL_433
case ACTIVE_RTL:
disableRTLreceive();
break;
# endif
# ifdef ZgatewayRF2
case ACTIVE_RF2:
disableRF2Receive();
break;
# endif
# ifndef ARDUINO_AVR_UNO // Space issues with the UNO
default:
Log.error(F("ERROR: unsupported receiver %d" CR), activeReceiver);
# endif
}
}
#endif
#endif
+23 -21
View File
@@ -28,7 +28,7 @@
#include "User_config.h"
// Macros and structure to enable the duplicates removing on the following gateways
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation)
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation) || defined(ZgatewayRTL_433)
// array to store previous received RFs, IRs codes and their timestamps
struct ReceivedSignal {
SIGNAL_SIZE_UL_ULL value;
@@ -260,7 +260,7 @@ void revert_hex_data(const char* in, char* out, int l) {
out[l - 1] = '\0';
}
/**
/**
* Retrieve an unsigned long value from a char array extract representing hexadecimal data, reversed or not,
* This value can represent a negative value if canBeNegative is set to true
*/
@@ -295,10 +295,10 @@ bool to_bool(String const& s) { // thanks Chris Jester-Young from stackoverflow
/**
* @brief Publish the payload on default MQTT topic.
*
*
* @param topicori suffix to add on default MQTT Topic
* @param payload the message to sends
* @param retainFlag true if you what a retain
* @param retainFlag true if you what a retain
*/
void pub(const char* topicori, const char* payload, bool retainFlag) {
String topic = String(mqtt_topic) + String(gateway_name) + String(topicori);
@@ -307,7 +307,7 @@ void pub(const char* topicori, const char* payload, bool retainFlag) {
/**
* @brief Publish the payload on default MQTT topic
*
*
* @param topicori suffix to add on default MQTT Topic
* @param data The Json Object that rapresent the message
*/
@@ -363,7 +363,7 @@ void pub(const char* topicori, JsonObject& data) {
/**
* @brief Publish the payload on default MQTT topic
*
*
* @param topicori suffix to add on default MQTT Topic
* @param payload the message to sends
*/
@@ -374,10 +374,10 @@ void pub(const char* topicori, const char* payload) {
/**
* @brief Publish the payload on the topic with a retantion
*
*
* @param topic The topic where to publish
* @param data The Json Object that rapresent the message
* @param retain true if you what a retain
* @param retain true if you what a retain
*/
void pub_custom_topic(const char* topic, JsonObject& data, boolean retain) {
String buffer = "";
@@ -387,7 +387,7 @@ void pub_custom_topic(const char* topic, JsonObject& data, boolean retain) {
/**
* @brief Low level MQTT functions without retain
*
*
* @param topic the topic
* @param payload the payload
*/
@@ -397,8 +397,8 @@ void pubMQTT(const char* topic, const char* payload) {
/**
* @brief Very Low level MQTT functions with retain Flag
*
* @param topic the topic
*
* @param topic the topic
* @param payload the payload
* @param retainFlag true if retain the retain Flag
*/
@@ -1521,14 +1521,12 @@ void loop() {
#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH)
loopM5();
#endif
// Function that doesn't need an active connection
#if defined(ZboardHELTEC)
loopHELTEC();
#endif
}
/**
/**
* Calculate uptime and take into account the millis() rollover
*/
unsigned long uptime() {
@@ -1610,14 +1608,18 @@ void stateMeasures() {
# if defined(ZgatewayRF) || defined(ZgatewayPilight) || defined(ZgatewayRTL_433) || defined(ZgatewayRF2)
SYSdata["actRec"] = (int)activeReceiver;
# endif
# ifdef ZradioCC1101
# if defined(ZradioCC1101) || defined(ZradioSX127x)
SYSdata["mhz"] = (float)receiveMhz;
# endif
# if defined(ZgatewayRTL_433)
if (activeReceiver == ACTIVE_RTL) {
SYSdata["RTLminRssi"] = (int)getRTLMinimumRSSI();
SYSdata["RTLRssiThresh"] = (int)getRTLrssiThreshold();
SYSdata["RTLRssi"] = (int)getRTLCurrentRSSI();
SYSdata["RTLAVGRssi"] = (int)getRTLAverageRSSI();
SYSdata["RTLCnt"] = (int)getRTLMessageCount();
# ifdef ZradioSX127x
SYSdata["RTLOOKThresh"] = (int)getOOKThresh();
# endif
}
# endif
SYSdata["modules"] = modules;
@@ -1625,8 +1627,8 @@ void stateMeasures() {
}
#endif
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation)
/**
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation) || defined(ZgatewayRTL_433)
/**
* Store signal values from RF, IR, SRFB or Weather stations so as to avoid duplicates
*/
void storeSignalValue(SIGNAL_SIZE_UL_ULL MQTTvalue) {
@@ -1646,7 +1648,7 @@ void storeSignalValue(SIGNAL_SIZE_UL_ULL MQTTvalue) {
}
}
/**
/**
* get oldest time index from the values array from RF, IR, SRFB or Weather stations so as to avoid duplicates
*/
int getMin() {
@@ -1661,7 +1663,7 @@ int getMin() {
return minindex;
}
/**
/**
* Check if signal values from RF, IR, SRFB or Weather stations are duplicates
*/
bool isAduplicateSignal(SIGNAL_SIZE_UL_ULL value) {
@@ -1670,7 +1672,7 @@ bool isAduplicateSignal(SIGNAL_SIZE_UL_ULL value) {
if (receivedSignal[i].value == value) {
unsigned long now = millis();
if (now - receivedSignal[i].time < time_avoid_duplicate) { // change
Log.notice(F("no pub. dupl" CR));
Log.trace(F("no pub. dupl" CR));
return true;
}
}