Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple RF modules simulatenously #2130

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/use/rf.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ Note that with CC1101 this frequency will be used as the default sending frequen

Switching of the active transceiver (RTL_433 receiver only) module is available between the RF, RF2, and (RTL_433 or Pilight) gateway modules, allowing for changing of signal decoders without redeploying the OpenMQTTGateway package. Sending a JSON message to the command topic will change the active transceiver module.

To change the RF gateway module, which will receive, send a json message to the RF gateway module command subject (home/OpenMQTTGateway/commands/MQTTtoRF/config) with the corresponding value of the key "active"
To change the RF gateway module, which will receive, send a json message to the RF gateway module command subject (home/OpenMQTTGateway/commands/MQTTtoRF/config) with the corresponding value of the key "active". Add these numbers together to enable multiple modules (e.g. to enable Pilight and RF, send 3, since 1 (for Pilight) + 2 (for RF) = 3).

1 - PiLight<br>
2 - RF<br>
3 - RTL_433<br>
4 - RF2
4 - RTL_433<br>
8 - RF2

Example to receive from the RF gateway:
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoRF/config" -m '{"active":2}'`
Expand Down
128 changes: 52 additions & 76 deletions main/ZcommonRF.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
/*
Theengs OpenMQTTGateway - We Unite Sensors in One Open-Source Interface

Act as a wifi or ethernet gateway between your BLE/433mhz/infrared IR signal and an MQTT broker
Act as a wifi or ethernet gateway between your BLE/433mhz/infrared IR signal and an MQTT broker
Send and receiving command by MQTT

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
Expand Down Expand Up @@ -70,99 +70,75 @@ bool validFrequency(float mhz) {

int currentReceiver = ACTIVE_NONE;

# if !defined(ZgatewayRFM69) && !defined(ZactuatorSomfy)
// Check if a receiver is available
bool validReceiver(int receiver) {
switch (receiver) {
# ifdef ZgatewayPilight
case ACTIVE_PILIGHT:
return true;
# endif
# ifdef ZgatewayRF
case ACTIVE_RF:
return true;
# endif
# ifdef ZgatewayRTL_433
case ACTIVE_RTL:
return true;
# endif
# ifdef ZgatewayRF2
case ACTIVE_RF2:
return true;
# endif
default:
Log.error(F("ERROR: stored receiver %d not available" CR), receiver);
}
return false;
}
# endif

void disableCurrentReceiver() {
Log.trace(F("disableCurrentReceiver: %d" CR), currentReceiver);
switch (currentReceiver) {
case ACTIVE_NONE:
break;
if (currentReceiver == ACTIVE_NONE) {
return;
}
bool recognized = false;
# ifdef ZgatewayPilight
case ACTIVE_PILIGHT:
disablePilightReceive();
break;
if ((currentReceiver & ACTIVE_PILIGHT) == ACTIVE_PILIGHT) {
disablePilightReceive();
recognized = true;
}
# endif
# ifdef ZgatewayRF
case ACTIVE_RF:
disableRFReceive();
break;
if ((currentReceiver & ACTIVE_RF) == ACTIVE_RF) {
disableRFReceive();
recognized = true;
}
# endif
# ifdef ZgatewayRTL_433
case ACTIVE_RTL:
disableRTLreceive();
break;
if ((currentReceiver & ACTIVE_RTL) == ACTIVE_RTL) {
disableRTLreceive();
recognized = true;
}
# endif
# ifdef ZgatewayRF2
case ACTIVE_RF2:
disableRF2Receive();
break;
if ((currentReceiver & ACTIVE_RF2) == ACTIVE_RF2) {
disableRF2Receive();
recognized = true;
}
# endif
default:
Log.error(F("ERROR: unsupported receiver %d" CR), RFConfig.activeReceiver);
if (!recognized) {
Log.error(F("ERROR: unsupported receiver %d" CR), currentReceiver); // This should be currentReceiver, not RFConfig.activeReceiver
}
}

void enableActiveReceiver() {
Log.trace(F("enableActiveReceiver: %d" CR), RFConfig.activeReceiver);
switch (RFConfig.activeReceiver) {
initCC1101(); // Okay to do this even with an invalid receiver selected, right?
bool recognized = false;
# ifdef ZgatewayPilight
case ACTIVE_PILIGHT:
initCC1101();
enablePilightReceive();
currentReceiver = ACTIVE_PILIGHT;
break;
if ((RFConfig.activeReceiver & ACTIVE_PILIGHT) == ACTIVE_PILIGHT) {
enablePilightReceive();
recognized = true;
}
# endif
# ifdef ZgatewayRF
case ACTIVE_RF:
initCC1101();
enableRFReceive();
currentReceiver = ACTIVE_RF;
break;
if ((RFConfig.activeReceiver & ACTIVE_RF) == ACTIVE_RF) {
enableRFReceive();
recognized = true;
}
# endif
# ifdef ZgatewayRTL_433
case ACTIVE_RTL:
initCC1101();
enableRTLreceive();
currentReceiver = ACTIVE_RTL;
break;
if ((RFConfig.activeReceiver & ACTIVE_RTL) == ACTIVE_RTL) {
enableRTLreceive();
recognized = true;
}
# endif
# ifdef ZgatewayRF2
case ACTIVE_RF2:
initCC1101();
enableRF2Receive();
currentReceiver = ACTIVE_RF2;
break;
if ((RFConfig.activeReceiver & ACTIVE_RF2) == ACTIVE_RF2) {
enableRF2Receive();
recognized = true;
}
# endif
case ACTIVE_RECERROR:
Log.error(F("ERROR: no receiver selected" CR));
break;
default:
Log.error(F("ERROR: unsupported receiver %d" CR), RFConfig.activeReceiver);
if (recognized) {
currentReceiver = RFConfig.activeReceiver;
} else if (RFConfig.activeReceiver == ACTIVE_RECERROR) {
Log.error(F("ERROR: no receiver selected" CR));
} else {
Log.error(F("ERROR: unsupported receiver %d" CR), RFConfig.activeReceiver);
}
}

Expand All @@ -173,7 +149,7 @@ String stateRFMeasures() {
RFdata["active"] = RFConfig.activeReceiver;
# if defined(ZradioCC1101) || defined(ZradioSX127x)
RFdata["frequency"] = RFConfig.frequency;
if (RFConfig.activeReceiver == ACTIVE_RTL) {
if ((RFConfig.activeReceiver & ACTIVE_RTL) == ACTIVE_RTL) {
# ifdef ZgatewayRTL_433
RFdata["rssithreshold"] = (int)getRTLrssiThreshold();
RFdata["rssi"] = (int)getRTLCurrentRSSI();
Expand Down
4 changes: 2 additions & 2 deletions main/ZgatewayPilight.ino
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ extern void disablePilightReceive() {
extern void enablePilightReceive() {
Log.notice(F("Switching to Pilight Receiver: %F" CR), RFConfig.frequency);
Log.notice(F("RF_EMITTER_GPIO: %d " CR), RF_EMITTER_GPIO);
Log.notice(F("RF_RECEIVER_GPIO: %d " CR), RF_RECEIVER_GPIO);
Log.notice(F("RF_PILIGHT_RECEIVER_GPIO: %d " CR), RF_PILIGHT_RECEIVER_GPIO);
Log.trace(F("ZgatewayPilight command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoPilight);

initCC1101();
Expand All @@ -305,7 +305,7 @@ extern void enablePilightReceive() {
rf.setPulseTrainCallBack(pilightRawCallback);
}
# endif
rf.initReceiver(RF_RECEIVER_GPIO);
rf.initReceiver(RF_PILIGHT_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();
rf.enableReceiver();
loadPilightConfig();
Expand Down
6 changes: 3 additions & 3 deletions main/ZgatewayRF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void XtoRF(const char* topicOri, const char* datacallback) {
# ifdef ZradioCC1101 // set Receive on and Transmitt off
ELECHOUSE_cc1101.SetRx(RFConfig.frequency);
mySwitch.disableTransmit();
mySwitch.enableReceive(RF_RECEIVER_GPIO);
mySwitch.enableReceive(RF_RF_RECEIVER_GPIO);
# endif
}
# endif
Expand Down Expand Up @@ -275,14 +275,14 @@ void enableRFReceive() {
Log.notice(F("Enable RF Receiver: %FMhz" CR), RFConfig.frequency);
//RF init parameters
Log.notice(F("RF_EMITTER_GPIO: %d " CR), RF_EMITTER_GPIO);
Log.notice(F("RF_RECEIVER_GPIO: %d " CR), RF_RECEIVER_GPIO);
Log.notice(F("RF_RF_RECEIVER_GPIO: %d " CR), RF_RF_RECEIVER_GPIO);

# ifdef RF_DISABLE_TRANSMIT
mySwitch.disableTransmit();
# else
mySwitch.enableTransmit(RF_EMITTER_GPIO);
# endif
receiveInterupt = RF_RECEIVER_GPIO;
receiveInterupt = RF_RF_RECEIVER_GPIO;
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT);
mySwitch.enableReceive(receiveInterupt);
Log.trace(F("ZgatewayRF command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRF);
Expand Down
4 changes: 2 additions & 2 deletions main/ZgatewayRF2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ void disableRF2Receive() {

void enableRF2Receive() {
Log.trace(F("enableRF2Receive" CR));
NewRemoteReceiver::init(RF_RECEIVER_GPIO, 2, rf2Callback);
NewRemoteReceiver::init(RF_RF2_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.notice(F("RF_RF2_RECEIVER_GPIO: %d " CR), RF_RF2_RECEIVER_GPIO);
Log.trace(F("ZgatewayRF2 command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRF2);
pinMode(RF_EMITTER_GPIO, OUTPUT);
digitalWrite(RF_EMITTER_GPIO, LOW);
Expand Down
4 changes: 2 additions & 2 deletions main/ZwebUI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1101,10 +1101,10 @@ std::map<int, String> activeReceiverOptions = {
{2, "RF"},
# endif
# ifdef ZgatewayRTL_433
{3, "RTL_433"},
{4, "RTL_433"},
# endif
# if defined(ZgatewayRF2) && !defined(ZradioSX127x)
{4, "RF2 (restart required)"}
{8, "RF2 (restart required)"}
# endif
};

Expand Down
28 changes: 21 additions & 7 deletions main/config_RF.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ const char parameters[51][4][24] = {
* Active Module
* 1 = ZgatewayPilight
* 2 = ZgatewayRF
* 3 = ZgatewayRTL_433
* 4 = ZgatewayRF2
* 4 = ZgatewayRTL_433
* 8 = ZgatewayRF2
*/

struct RFConfig_s {
Expand All @@ -210,8 +210,8 @@ struct RFConfig_s {
#define ACTIVE_RECERROR 0
#define ACTIVE_PILIGHT 1
#define ACTIVE_RF 2
#define ACTIVE_RTL 3
#define ACTIVE_RF2 4
#define ACTIVE_RTL 4
#define ACTIVE_RF2 8

RFConfig_s RFConfig;

Expand All @@ -223,11 +223,25 @@ RFConfig_s RFConfig;
#endif

/*-------------------PIN DEFINITIONS----------------------*/
#ifndef RF_RECEIVER_GPIO
#ifndef RF_PILIGHT_RECEIVER_GPIO
# ifdef ESP8266
# define RF_RECEIVER_GPIO 0 // D3 on nodemcu // put 4 with rf bridge direct mod
# define RF_PILIGHT_RECEIVER_GPIO 0 // D3 on nodemcu // put 4 with rf bridge direct mod
# elif ESP32
# define RF_RECEIVER_GPIO 27 // D27 on DOIT ESP32
# define RF_PILIGHT_RECEIVER_GPIO 27 // D27 on DOIT ESP32
# endif
#endif
#ifndef RF_RF_RECEIVER_GPIO
# ifdef ESP8266
# define RF_RF_RECEIVER_GPIO 0 // D3 on nodemcu // put 4 with rf bridge direct mod
# elif ESP32
# define RF_RF_RECEIVER_GPIO 27 // D27 on DOIT ESP32
# endif
#endif
#ifndef RF_RF2_RECEIVER_GPIO
# ifdef ESP8266
# define RF_RF2_RECEIVER_GPIO 0 // D3 on nodemcu // put 4 with rf bridge direct mod
# elif ESP32
# define RF_RF2_RECEIVER_GPIO 27 // D27 on DOIT ESP32
# endif
#endif

Expand Down
Loading