Initial pull request for rtl_433 support (#886)
* Initial pull request for rtl_433 support Co-authored-by: NorthernMan54 <sgracey@Bart.local>
This commit is contained in:
1 parent
bcd45d68f4
commit
57bc108da4
7 files changed
+315
-3
No files matched your search
@@ -352,6 +352,7 @@ uint8_t wifiProtocol = 0; // default mode, automatic selection
|
||||
// key used for launching commands to the gateway
|
||||
#define restartCmd "restart"
|
||||
#define eraseCmd "erase"
|
||||
#define statusCmd "status"
|
||||
|
||||
// uncomment the line below to integrate msg value into the subject when receiving
|
||||
//#define valueAsASubject true
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
OpenMQTTGateway - ESP8266 or Arduino program for home automation
|
||||
|
||||
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
This gateway enables to:
|
||||
- receive MQTT data from a topic and send RF 433Mhz signal corresponding to the received MQTT data
|
||||
- publish MQTT data to a different topic related to received 433Mhz signal
|
||||
- leverage the rtl_433 device decoders on a ESP32 device
|
||||
|
||||
Copyright: (c)Florian ROBERT
|
||||
|
||||
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
|
||||
(at your option) any later version.
|
||||
|
||||
OpenMQTTGateway is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZgatewayRTL_433
|
||||
|
||||
# include <rtl_433_ESP.h>
|
||||
|
||||
# define CC1101_FREQUENCY 433.92
|
||||
# define ONBOARD_LED 2
|
||||
|
||||
char messageBuffer[JSON_MSG_BUFFER];
|
||||
|
||||
rtl_433_ESP rtl_433(-1); // use -1 to disable transmitter
|
||||
|
||||
# include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
|
||||
void rtl_433_Callback(char* message) {
|
||||
DynamicJsonBuffer jsonBuffer2(JSON_MSG_BUFFER);
|
||||
JsonObject& RFrtl_433_ESPdata = jsonBuffer2.parseObject(message);
|
||||
|
||||
pub(subjectRTL_433toMQTT, RFrtl_433_ESPdata);
|
||||
# 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.notice(F("ZgatewayRTL_433 command topic: %s%s" CR), mqtt_topic, subjectMQTTtoRTL_433);
|
||||
enableRTLreceive();
|
||||
Log.trace(F("ZgatewayRTL_433 setup done " CR));
|
||||
}
|
||||
|
||||
void RTL_433Loop() {
|
||||
rtl_433.loop();
|
||||
}
|
||||
|
||||
extern void MQTTtoRTL_433(char* topicOri, JsonObject& RTLdata) {
|
||||
if (cmpToMainTopic(topicOri, subjectMQTTtoRTL_433)) {
|
||||
Log.trace(F("MQTTtoRTL_433 %s" CR), topicOri);
|
||||
float tempMhz = RTLdata["mhz"] | 0;
|
||||
int minimumRssi = RTLdata["rssi"] | 0;
|
||||
int debug = RTLdata["debug"] | -1;
|
||||
int status = RTLdata["status"] | -1;
|
||||
if (tempMhz != 0 && validFrequency((int)tempMhz)) {
|
||||
// activeReceiver = RTL; // Enable RTL_433 Gateway
|
||||
receiveMhz = tempMhz;
|
||||
Log.notice(F("RTL_433 Receive mhz: %F" CR), receiveMhz);
|
||||
pub(subjectRTL_433toMQTT, RTLdata);
|
||||
} else if (minimumRssi != 0) {
|
||||
Log.notice(F("RTL_433 minimum RSSI: %d" CR), minimumRssi);
|
||||
rtl_433.setMinimumRSSI(minimumRssi);
|
||||
pub(subjectRTL_433toMQTT, RTLdata);
|
||||
} else if (debug >= 0 && debug <= 4) {
|
||||
Log.notice(F("RTL_433 set debug: %d" CR), debug);
|
||||
rtl_433.setDebug(debug);
|
||||
rtl_433.initReceiver(RF_RECEIVER_GPIO, receiveMhz);
|
||||
pub(subjectRTL_433toMQTT, RTLdata);
|
||||
} else if (status >= 0) {
|
||||
Log.notice(F("RTL_433 get status: %d" CR), status);
|
||||
rtl_433.getStatus(status);
|
||||
pub(subjectRTL_433toMQTT, RTLdata);
|
||||
} else {
|
||||
pub(subjectRTL_433toMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
|
||||
Log.error(F("MQTTtoRTL_433 Fail json" CR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern void enableRTLreceive() {
|
||||
Log.trace(F("enableRTLreceive: %F" CR), receiveMhz);
|
||||
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
|
||||
rtl_433.enableReceiver(RF_RECEIVER_GPIO);
|
||||
// rtl_433.initReceiver(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();
|
||||
}
|
||||
|
||||
extern void disableRTLreceive() {
|
||||
Log.trace(F("disableRTLreceive" CR));
|
||||
rtl_433.enableReceiver(-1);
|
||||
rtl_433.disableReceiver();
|
||||
}
|
||||
|
||||
extern int getRTLMinimumRSSI() {
|
||||
return rtl_433.minimumRssi;
|
||||
}
|
||||
|
||||
extern int getRTLCurrentRSSI() {
|
||||
return rtl_433.currentRssi;
|
||||
}
|
||||
|
||||
extern int getRTLMessageCount() {
|
||||
return rtl_433.messageCount;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -47,6 +47,20 @@ extern void PilighttoMQTT();
|
||||
extern void MQTTtoPilight(char* topicOri, char* datacallback);
|
||||
extern void MQTTtoPilight(char* topicOri, JsonObject& RFdata);
|
||||
#endif
|
||||
#ifdef ZgatewayRTL_433
|
||||
extern void RTL_433Loop();
|
||||
extern void setupRTL_433();
|
||||
extern void MQTTtoRTL_433(char* topicOri, JsonObject& RTLdata);
|
||||
extern void enableRTLreceive();
|
||||
extern void disableRTLreceive();
|
||||
extern int getRTLMinimumRSSI();
|
||||
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
|
||||
#define subjectMQTTtoRF "/commands/MQTTto433"
|
||||
@@ -80,6 +94,11 @@ extern void MQTTtoPilight(char* topicOri, JsonObject& RFdata);
|
||||
#define subjectGTWPilighttoMQTT "/PilighttoMQTT"
|
||||
#define repeatPilightwMQTT false // do we repeat a received signal by using mqtt with Pilight gateway
|
||||
|
||||
/*-------------------RTL_433 topics & parameters----------------------*/
|
||||
//433Mhz RTL_433 MQTT Subjects and keys
|
||||
#define subjectMQTTtoRTL_433 "/commands/MQTTtoRTL_433"
|
||||
#define subjectRTL_433toMQTT "/RTL_433toMQTT"
|
||||
|
||||
/*-------------------CC1101 frequency----------------------*/
|
||||
//Match frequency to the hardware version of the radio if ZradioCC1101 is used.
|
||||
#ifndef CC1101_FREQUENCY
|
||||
|
||||
+24
-1
@@ -57,7 +57,7 @@ StaticJsonBuffer<JSON_MSG_BUFFER> modulesBuffer;
|
||||
JsonArray& modules = modulesBuffer.createArray();
|
||||
|
||||
// Modules config inclusion
|
||||
#if defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZgatewayPilight) || defined(ZactuatorSomfy)
|
||||
#if defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZgatewayPilight) || defined(ZactuatorSomfy) || defined(ZgatewayRTL_433)
|
||||
# include "config_RF.h"
|
||||
#endif
|
||||
#ifdef ZgatewayWeatherStation
|
||||
@@ -720,6 +720,10 @@ void setup() {
|
||||
#endif
|
||||
#ifdef ZsensorSHTC3
|
||||
setupSHTC3();
|
||||
#endif
|
||||
#ifdef ZgatewayRTL_433
|
||||
setupRTL_433();
|
||||
modules.add(ZgatewayRTL_433);
|
||||
#endif
|
||||
Log.trace(F("mqtt_max_packet_size: %d" CR), mqtt_max_packet_size);
|
||||
Log.notice(F("Setup OpenMQTTGateway end" CR));
|
||||
@@ -1352,6 +1356,9 @@ void loop() {
|
||||
#endif
|
||||
#ifdef ZactuatorPWM
|
||||
PWMLoop();
|
||||
#endif
|
||||
#ifdef ZgatewayRTL_433
|
||||
RTL_433Loop();
|
||||
#endif
|
||||
} else {
|
||||
connectMQTT();
|
||||
@@ -1388,6 +1395,9 @@ void stateMeasures() {
|
||||
uint32_t freeMem;
|
||||
freeMem = ESP.getFreeHeap();
|
||||
SYSdata["freemem"] = freeMem;
|
||||
# ifdef ESP32
|
||||
SYSdata["freestack"] = uxTaskGetStackHighWaterMark(NULL);
|
||||
# endif
|
||||
# ifdef ESP32_ETHERNET
|
||||
SYSdata["mac"] = (char*)ETH.macAddress().c_str();
|
||||
SYSdata["ip"] = ip2CharArray(ETH.localIP());
|
||||
@@ -1433,6 +1443,14 @@ void stateMeasures() {
|
||||
SYSdata["m5batpower"] = (float)M5.Axp.GetBatPower();
|
||||
SYSdata["m5batchargecurrent"] = (float)M5.Axp.GetBatChargeCurrent();
|
||||
SYSdata["m5apsvoltage"] = (float)M5.Axp.GetAPSVoltage();
|
||||
# endif
|
||||
# ifdef ZradioCC1101
|
||||
SYSdata["mhz"] = (int)receiveMhz;
|
||||
# endif
|
||||
# if defined(ZgatewayRTL_433)
|
||||
SYSdata["RTLminRssi"] = (int)getRTLMinimumRSSI();
|
||||
SYSdata["RTLRssi"] = (int)getRTLCurrentRSSI();
|
||||
SYSdata["RTLCnt"] = (int)getRTLMessageCount();
|
||||
# endif
|
||||
SYSdata.set("modules", modules);
|
||||
pub(subjectSYStoMQTT, SYSdata);
|
||||
@@ -1512,6 +1530,9 @@ void receivingMQTT(char* topicOri, char* datacallback) {
|
||||
#ifdef ZgatewayPilight // ZgatewayPilight is only defined with json publishing due to its numerous parameters
|
||||
MQTTtoPilight(topicOri, jsondata);
|
||||
#endif
|
||||
#ifdef ZgatewayRTL_433 // ZgatewayRTL_433 is only defined with json publishing due to its numerous parameters
|
||||
MQTTtoRTL_433(topicOri, jsondata);
|
||||
#endif
|
||||
#ifdef jsonReceiving
|
||||
# ifdef ZgatewayLORA
|
||||
MQTTtoLORA(topicOri, jsondata);
|
||||
@@ -1609,6 +1630,8 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
||||
# ifndef ESPWifiManualSetup
|
||||
setup_wifimanager(true);
|
||||
# endif
|
||||
} else if (strstr(cmd, statusCmd) != NULL) { //erase and restart
|
||||
stateMeasures();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user