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

+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