Active Receiver Switching (#936)

* PR #934

* Active Receiver Switching

Switching of the active receiver module is available between the RF,
RF2, RTL_433 and Pilight Gateway modules, allowing for changing of
signal decoders without redploying the openMQTTGateway package.
Sending a JSON message to the command topic of the desired receiver
will change the active receiver module.

Other minor adjustments/improvements

1 - Improved startup serial logging that includes
- OpenMQTTGateway Version
- OpenMQTTGateway Modules

2 - Trace logging of full Gateway module command topic
 - Enabled in RF, RF2, PiLight and RTL_433

3 - Updated RTL_433 Documentation to only include enabled ASK/OOK
device decoders

4 - Trace logging of MQTT Callback topic

* Regression testing

* Adding valueAsASubject support to rtl_433_ESP
- model and id keys are appended to message topic

* Increased memory size for receiver switching in blocking build all

Co-authored-by: Northern Man <sgracey@Heisenberg.local>
This commit is contained in:
Northern ManandNorthern Man authored and GitHub committed 2021-05-10 19:36:25 -05:00
1 parent 9fb3d90da9
commit f69906861d
8 files changed
+476 -170

No files matched your search

+65 -18
View File
@@ -74,22 +74,18 @@ void pilightCallback(const String& protocol, const String& message, int status,
}
void setupPilight() {
# ifndef ZgatewayRF&& ZgatewayRF2 //receiving with Pilight is not compatible with ZgatewayRF or RF2 or RF315 as far as I can tell
# ifdef ZradioCC1101 //receiving with CC1101
# ifdef ZradioCC1101 //receiving with CC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
rf.enableReceiver();
# endif
# endif
rf.setCallback(pilightCallback);
rf.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();
Log.notice(F("RF_EMITTER_GPIO: %d " CR), RF_EMITTER_GPIO);
Log.notice(F("RF_RECEIVER_GPIO: %d " CR), RF_RECEIVER_GPIO);
Log.trace(F("ZgatewayPilight command topic: %s%s" CR), mqtt_topic, subjectMQTTtoPilight);
Log.trace(F("ZgatewayPilight setup done " CR));
# else
Log.trace(F("ZgatewayPilight setup cannot be done, comment first ZgatewayRF && ZgatewayRF2" CR));
# endif
}
void PilighttoMQTT() {
@@ -97,15 +93,12 @@ void PilighttoMQTT() {
}
void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
rf.disableReceiver();
# endif
if (cmpToMainTopic(topicOri, subjectMQTTtoPilight)) {
Log.trace(F("MQTTtoPilight json data analysis" CR));
const char* message = Pilightdata["message"];
const char* protocol = Pilightdata["protocol"];
const char* raw = Pilightdata["raw"];
float tempMhz = Pilightdata["mhz"];
bool success = false;
if (raw) {
uint16_t codes[MAXPULSESTREAMLENGTH];
int repeats = rf.stringToRepeats(raw);
@@ -122,8 +115,13 @@ 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
rf.disableReceiver();
# endif
rf.sendPulseTrain(codes, msgLength, repeats);
Log.notice(F("MQTTtoPilight raw ok" CR));
success = true;
} else {
Log.trace(F("MQTTtoPilight raw KO" CR));
switch (msgLength) {
@@ -142,12 +140,18 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
}
Log.error(F("Invalid JSON: raw data malformed" CR));
}
} else if (message && protocol) {
}
if (message && protocol) {
Log.trace(F("MQTTtoPilight msg & protocol ok" CR));
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
rf.disableReceiver();
# endif
int msgLength = rf.send(protocol, message);
if (msgLength > 0) {
Log.trace(F("Adv data MQTTtoPilight push state via PilighttoMQTT" CR));
pub(subjectGTWPilighttoMQTT, Pilightdata);
success = true;
} else {
switch (msgLength) {
case ESPiLight::ERROR_UNAVAILABLE_PROTOCOL:
@@ -166,13 +170,56 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
Log.error(F("Invalid JSON: can't read message/protocol" CR));
}
}
} else {
Log.error(F("MQTTtoPilight failed json read" CR));
}
}
if (Pilightdata.containsKey("active")) {
Log.trace(F("PiLight active:" CR));
activeReceiver = ACTIVE_PILIGHT; // Enable PILIGHT Gateway
success = true;
}
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY); // set Receive on
rf.enableReceiver();
if (Pilightdata.containsKey("mhz") && validFrequency(tempMhz)) {
receiveMhz = tempMhz;
Log.notice(F("PiLight Receive mhz: %F" CR), receiveMhz);
success = true;
}
# endif
if (success) {
pub(subjectGTWPilighttoMQTT, Pilightdata); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
} else {
pub(subjectGTWPilighttoMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
Log.error(F("MQTTtoPilight Fail json" CR));
}
enableActiveReceiver();
}
}
extern void disablePilightReceive() {
Log.trace(F("disablePilightReceive" CR));
rf.initReceiver(-1);
rf.disableReceiver();
};
extern void enablePilightReceive() {
# ifdef ZradioCC1101
Log.notice(F("Switching to Pilight Receiver: %F" CR), receiveMhz);
# else
Log.notice(F("Switching to Pilight Receiver" CR));
# endif
# ifdef ZgatewayRF
disableRFReceive();
# endif
# ifdef ZgatewayRF2
disableRF2Receive();
# endif
# ifdef ZgatewayRTL_433
disableRTLreceive();
# endif
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
rf.setCallback(pilightCallback);
rf.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();
};
#endif
+49 -23
View File
@@ -70,6 +70,7 @@ void setupRF() {
# endif
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT);
mySwitch.enableReceive(RF_RECEIVER_GPIO);
Log.trace(F("ZgatewayRF command topic: %s%s" CR), mqtt_topic, subjectMQTTtoRF);
Log.trace(F("ZgatewayRF setup done" CR));
}
@@ -204,42 +205,67 @@ void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding
pub(subjectGTWRFtoMQTT, RFdata); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT); // Restore the default value
} else {
bool success = false;
if (RFdata.containsKey("active")) {
Log.trace(F("RF active:" CR));
activeReceiver = ACTIVE_RF;
success = true;
}
# ifdef ZradioCC1101 // set Receive on and Transmitt off
float tempMhz = RFdata["mhz"];
if (tempMhz != 0 && validFrequency((int)tempMhz)) {
if (RFdata.containsKey("mhz") && validFrequency(tempMhz)) {
receiveMhz = tempMhz;
Log.notice(F("Receive mhz: %F" CR), receiveMhz);
success = true;
}
# endif
if (success) {
pub(subjectGTWRFtoMQTT, RFdata); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
} else {
# ifndef ARDUINO_AVR_UNO // Space issues with the UNO
pub(subjectGTWRFtoMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
# endif
Log.error(F("MQTTtoRF Fail json" CR));
}
# else
# ifndef ARDUINO_AVR_UNO // Space issues with the UNO
pub(subjectGTWRFtoMQTT, "{\"Status\": \"error\"}"); // Fail feedback
# endif
Log.error(F("MQTTtoRF Fail json" CR));
# endif
}
enableActiveReceiver();
}
# ifdef ZradioCC1101 // set Receive on and Transmitt off
ELECHOUSE_cc1101.SetRx(receiveMhz);
mySwitch.disableTransmit();
mySwitch.enableReceive(RF_RECEIVER_GPIO);
# endif
}
# endif
#endif
#ifdef ZradioCC1101
bool validFrequency(int mhz) {
// CC1101 valid frequencies 300-348 MHZ, 387-464MHZ and 779-928MHZ.
if (mhz >= 300 && mhz <= 348)
return true;
if (mhz >= 387 && mhz <= 464)
return true;
if (mhz >= 779 && mhz <= 928)
return true;
return false;
int receiveInterupt = -1;
void disableRFReceive() {
Log.trace(F("disableRFReceive %d" CR), receiveInterupt);
if (receiveInterupt != -1) {
receiveInterupt = -1;
mySwitch.disableReceive();
}
}
void enableRFReceive() {
# ifdef ZradioCC1101
Log.notice(F("Switching to RF Receiver: %F" CR), receiveMhz);
# else
Log.notice(F("Switching to RF Receiver" CR));
# endif
# ifndef ARDUINO_AVR_UNO // Space issues with the UNO
# ifdef ZgatewayPilight
disablePilightReceive();
# endif
# ifdef ZgatewayRTL_433
disableRTLreceive();
# endif
# endif
# ifdef ZgatewayRF2
disableRF2Receive();
# endif
# ifdef ZradioCC1101 // set Receive on and Transmitt off
ELECHOUSE_cc1101.SetRx(receiveMhz);
# endif
mySwitch.disableTransmit();
receiveInterupt = RF_RECEIVER_GPIO;
mySwitch.enableReceive(RF_RECEIVER_GPIO);
}
#endif
+62 -17
View File
@@ -56,17 +56,16 @@ struct RF2rxd {
RF2rxd rf2rd;
void setupRF2() {
# ifndef ZgatewayRF //receiving with RF2 is not compatible with ZgatewayRF
# ifdef ZradioCC1101 //receiving with CC1101
# ifdef ZradioCC1101 //receiving with CC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
# endif
ELECHOUSE_cc1101.setMHZ(receiveMhz);
ELECHOUSE_cc1101.SetRx(receiveMhz);
# endif
NewRemoteReceiver::init(RF_RECEIVER_GPIO, 2, rf2Callback);
Log.notice(F("RF_EMITTER_GPIO: %d " CR), RF_EMITTER_GPIO);
Log.notice(F("RF_RECEIVER_GPIO: %d " CR), RF_RECEIVER_GPIO);
Log.trace(F("ZgatewayRF2 command topic: %s%s" CR), mqtt_topic, subjectMQTTtoRF2);
Log.trace(F("ZgatewayRF2 setup done " CR));
# endif
pinMode(RF_EMITTER_GPIO, OUTPUT);
digitalWrite(RF_EMITTER_GPIO, LOW);
}
@@ -253,7 +252,7 @@ void MQTTtoRF2(char* topicOri, char* datacallback) {
}
}
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY); // set Receive on
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
NewRemoteReceiver::enable();
# endif
}
@@ -261,15 +260,16 @@ void MQTTtoRF2(char* topicOri, char* datacallback) {
# ifdef jsonReceiving
void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding
# ifdef ZradioCC1101
NewRemoteReceiver::disable();
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
# endif
if (cmpToMainTopic(topicOri, subjectMQTTtoRF2)) {
Log.trace(F("MQTTtoRF2 json" CR));
int boolSWITCHTYPE = RF2data["switchType"] | 99;
bool success = false;
if (boolSWITCHTYPE != 99) {
# ifdef ZradioCC1101
NewRemoteReceiver::disable();
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
# endif
Log.trace(F("MQTTtoRF2 switch type ok" CR));
bool isDimCommand = boolSWITCHTYPE == 2;
unsigned long valueCODE = RF2data["address"];
@@ -304,17 +304,62 @@ void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding
Log.notice(F("MQTTtoRF2 OK" CR));
NewRemoteReceiver::enable();
// Publish state change back to MQTT
pub(subjectGTWRF2toMQTT, RF2data);
success = true;
}
}
if (RF2data.containsKey("active")) {
Log.trace(F("RF2 active:" CR));
activeReceiver = ACTIVE_RF2;
success = true;
}
# ifdef ZradioCC1101 // set Receive on and Transmitt off
float tempMhz = RF2data["mhz"];
if (RF2data.containsKey("mhz") && validFrequency(tempMhz)) {
receiveMhz = tempMhz;
Log.notice(F("Receive mhz: %F" CR), receiveMhz);
success = true;
}
# endif
if (success) {
pub(subjectGTWRF2toMQTT, RF2data); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
} else {
# ifndef ARDUINO_AVR_UNO // Space issues with the UNO
pub(subjectGTWRF2toMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
# endif
Log.error(F("MQTTtoRF2 failed json read" CR));
}
enableActiveReceiver();
}
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY); // set Receive on
NewRemoteReceiver::enable();
# endif
}
# endif
void disableRF2Receive() {
Log.trace(F("disableRF2Receive" CR));
NewRemoteReceiver::deinit();
NewRemoteReceiver::init(-1, 2, rf2Callback); // mark _interupt with -1
NewRemoteReceiver::deinit();
}
void enableRF2Receive() {
# ifdef ZradioCC1101
Log.notice(F("Switching to RF2 Receiver: %F" CR), receiveMhz);
# else
Log.notice(F("Switching to RF2 Receiver" CR));
# endif
# ifdef ZgatewayPilight
disablePilightReceive();
# endif
# ifdef ZgatewayRTL_433
disableRTLreceive();
# endif
# ifdef ZgatewayRF
disableRFReceive();
# endif
NewRemoteReceiver::init(RF_RECEIVER_GPIO, 2, rf2Callback);
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
}
#endif
+50 -22
View File
@@ -27,7 +27,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "User_config.h"
#ifdef ZgatewayRTL_433
# include <rtl_433_ESP.h>
@@ -42,7 +41,19 @@ void rtl_433_Callback(char* message) {
DynamicJsonBuffer jsonBuffer2(JSON_MSG_BUFFER);
JsonObject& RFrtl_433_ESPdata = jsonBuffer2.parseObject(message);
pub(subjectRTL_433toMQTT, RFrtl_433_ESPdata);
String topic = String(subjectRTL_433toMQTT);
# ifdef valueAsASubject
String model = RFrtl_433_ESPdata["model"];
String id = RFrtl_433_ESPdata["id"];
if (model != 0) {
topic = topic + "/" + model;
if (id != 0) {
topic = topic + "/" + id;
}
}
# endif
pub((char*)topic.c_str(), RFrtl_433_ESPdata);
# ifdef MEMORY_DEBUG
Log.trace(F("Post rtl_433_Callback: %d" CR), ESP.getFreeHeap());
# endif
@@ -51,9 +62,8 @@ void rtl_433_Callback(char* message) {
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));
Log.trace(F("ZgatewayRTL_433 command topic: %s%s" CR), mqtt_topic, subjectMQTTtoRTL_433);
Log.notice(F("ZgatewayRTL_433 setup done " CR));
}
void RTL_433Loop() {
@@ -62,41 +72,59 @@ void RTL_433Loop() {
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
float tempMhz = RTLdata["mhz"];
bool success = false;
if (RTLdata.containsKey("mhz") && validFrequency(tempMhz)) {
receiveMhz = tempMhz;
Log.notice(F("RTL_433 Receive mhz: %F" CR), receiveMhz);
pub(subjectRTL_433toMQTT, RTLdata);
} else if (minimumRssi != 0) {
success = true;
}
if (RTLdata.containsKey("active")) {
Log.trace(F("RTL_433 active:" CR));
activeReceiver = ACTIVE_RTL; // Enable RTL_433 Gateway
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);
pub(subjectRTL_433toMQTT, RTLdata);
} else if (debug >= 0 && debug <= 4) {
success = true;
}
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);
pub(subjectRTL_433toMQTT, RTLdata);
} else if (status >= 0) {
Log.notice(F("RTL_433 get status: %d" CR), status);
rtl_433.getStatus(status);
success = true;
}
if (RTLdata.containsKey("status")) {
Log.notice(F("RTL_433 get status:" CR));
rtl_433.getStatus(1);
success = true;
}
if (success) {
pub(subjectRTL_433toMQTT, RTLdata);
} else {
pub(subjectRTL_433toMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
Log.error(F("MQTTtoRTL_433 Fail json" CR));
}
enableActiveReceiver();
}
}
extern void enableRTLreceive() {
Log.trace(F("enableRTLreceive: %F" CR), receiveMhz);
Log.notice(F("Switching to RTL_433 Receiver: %FMhz" CR), receiveMhz);
# ifdef ZgatewayRF
disableRFReceive();
# endif
# ifdef ZgatewayRF2
disableRF2Receive();
# endif
# ifdef ZgatewayPilight
disablePilightReceive();
# endif
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();
}
+71
View File
@@ -34,18 +34,24 @@ extern void setupRF();
extern void RFtoMQTT();
extern void MQTTtoRF(char* topicOri, char* datacallback);
extern void MQTTtoRF(char* topicOri, JsonObject& RFdata);
extern void disableRFReceive();
extern void enableRFReceive();
#endif
#ifdef ZgatewayRF2
extern void setupRF2();
extern void RF2toMQTT();
extern void MQTTtoRF2(char* topicOri, char* datacallback);
extern void MQTTtoRF2(char* topicOri, JsonObject& RFdata);
extern void disableRF2Receive();
extern void enableRF2Receive();
#endif
#ifdef ZgatewayPilight
extern void setupPilight();
extern void PilighttoMQTT();
extern void MQTTtoPilight(char* topicOri, char* datacallback);
extern void MQTTtoPilight(char* topicOri, JsonObject& RFdata);
extern void disablePilightReceive();
extern void enablePilightReceive();
#endif
#ifdef ZgatewayRTL_433
extern void RTL_433Loop();
@@ -136,4 +142,69 @@ float receiveMhz = CC1101_FREQUENCY;
# endif
#endif
#if defined(ZgatewayRF) || defined(ZgatewayPilight) || defined(ZgatewayRTL_433) || defined(ZgatewayRF2)
/**
* Active Receiver Module
* 1 = ZgatewayPilight
* 2 = ZgatewayRF
* 3 = ZgatewayRTL_433
* 4 = ZgatewayRF2
*/
int activeReceiver = 0;
# define ACTIVE_RECERROR 0
# define ACTIVE_PILIGHT 1
# define ACTIVE_RF 2
# define ACTIVE_RTL 3
# define ACTIVE_RF2 4
# ifdef ZradioCC1101
bool validFrequency(float mhz) {
// CC1101 valid frequencies 300-348 MHZ, 387-464MHZ and 779-928MHZ.
if (mhz >= 300 && mhz <= 348)
return true;
if (mhz >= 387 && mhz <= 464)
return true;
if (mhz >= 779 && mhz <= 928)
return true;
return false;
}
# endif
int currentReceiver = -1;
extern void stateMeasures(); // Send a status message
void enableActiveReceiver() {
// if (currentReceiver != activeReceiver) {
Log.trace(F("enableActiveReceiver: %d" CR), activeReceiver);
switch (activeReceiver) {
# ifdef ZgatewayPilight
case ACTIVE_PILIGHT:
enablePilightReceive();
break;
# endif
# ifdef ZgatewayRF
case ACTIVE_RF:
enableRFReceive();
break;
# endif
# ifdef ZgatewayRTL_433
case ACTIVE_RTL:
enableRTLreceive();
break;
# endif
# ifdef ZgatewayRF2
case ACTIVE_RF2:
enableRF2Receive();
break;
# endif
# ifndef ARDUINO_AVR_UNO // Space issues with the UNO
default:
Log.error(F("ERROR: unsupported receiver %d" CR), activeReceiver);
# endif
}
currentReceiver = activeReceiver;
}
#endif
#endif
+41 -7
View File
@@ -531,7 +531,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
// In order to republish this payload, a copy must be made
// as the orignal payload buffer will be overwritten whilst
// constructing the PUBLISH packet.
Log.trace(F("Hey I got a callback " CR));
Log.trace(F("Hey I got a callback %s" CR), topic);
// Allocate the correct amount of memory for the payload copy
byte* p = (byte*)malloc(length + 1);
// Copy the payload to the new buffer
@@ -568,6 +568,7 @@ void setup() {
# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK)
setupM5();
# endif
Log.notice(F("OpenMQTTGateway Version: " OMG_VERSION CR));
# endif
# ifdef ESP32_ETHERNET
@@ -654,14 +655,24 @@ void setup() {
#ifdef ZgatewayRF
setupRF();
modules.add(ZgatewayRF);
# define ACTIVE_RECEIVER ACTIVE_RF
#endif
#ifdef ZgatewayRF2
setupRF2();
modules.add(ZgatewayRF2);
# ifdef ACTIVE_RECEIVER
# undef ACTIVE_RECEIVER
# endif
# define ACTIVE_RECEIVER ACTIVE_RF2
#endif
#ifdef ZgatewayPilight
setupPilight();
modules.add(ZgatewayPilight);
disablePilightReceive();
# ifdef ACTIVE_RECEIVER
# undef ACTIVE_RECEIVER
# endif
# define ACTIVE_RECEIVER ACTIVE_PILIGHT
#endif
#ifdef ZgatewayWeatherStation
setupWeatherStation();
@@ -737,9 +748,27 @@ void setup() {
#ifdef ZgatewayRTL_433
setupRTL_433();
modules.add(ZgatewayRTL_433);
# ifdef ACTIVE_RECEIVER
# undef ACTIVE_RECEIVER
# endif
# define ACTIVE_RECEIVER ACTIVE_RTL
#endif
#if defined(ZgatewayRTL_433) || defined(ZgatewayRF) || defined(ZgatewayPilight) || defined(ZgatewayRF2)
# ifdef DEFAULT_RECEIVER // Allow defining of default receiver as a compiler directive
activeReceiver = DEFAULT_RECEIVER;
# else
activeReceiver = ACTIVE_RECEIVER;
# endif
enableActiveReceiver();
#endif
Log.trace(F("mqtt_max_packet_size: %d" CR), mqtt_max_packet_size);
Log.notice(F("Setup OpenMQTTGateway end" CR));
#ifndef ARDUINO_AVR_UNO // Space issues with the UNO
char jsonChar[100];
modules.printTo((char*)jsonChar, modules.measureLength() + 1);
Log.notice(F("OpenMQTTGateway modules: %s" CR), jsonChar);
#endif
Log.notice(F("************** Setup OpenMQTTGateway end **************" CR));
}
#if defined(ESP8266) || defined(ESP32)
@@ -1410,13 +1439,18 @@ void stateMeasures() {
SYSdata["m5batchargecurrent"] = (float)M5.Axp.GetBatChargeCurrent();
SYSdata["m5apsvoltage"] = (float)M5.Axp.GetAPSVoltage();
# endif
# if defined(ZgatewayRF) || defined(ZgatewayPilight) || defined(ZgatewayRTL_433) || defined(ZgatewayRF2)
SYSdata["actRec"] = (int)activeReceiver;
# endif
# ifdef ZradioCC1101
SYSdata["mhz"] = (int)receiveMhz;
SYSdata["mhz"] = (float)receiveMhz;
# endif
# if defined(ZgatewayRTL_433)
SYSdata["RTLminRssi"] = (int)getRTLMinimumRSSI();
SYSdata["RTLRssi"] = (int)getRTLCurrentRSSI();
SYSdata["RTLCnt"] = (int)getRTLMessageCount();
if (activeReceiver == ACTIVE_RTL) {
SYSdata["RTLminRssi"] = (int)getRTLMinimumRSSI();
SYSdata["RTLRssi"] = (int)getRTLCurrentRSSI();
SYSdata["RTLCnt"] = (int)getRTLMessageCount();
}
# endif
SYSdata.set("modules", modules);
pub(subjectSYStoMQTT, SYSdata);
@@ -1614,4 +1648,4 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
}
#endif
}
}
}