[RTL_433][BREAKING] Beta support for FSK modulation, webUI frequency and active receiver change (#1812)

* [FSK] Add Lilygo Heltec environment with FSK modulation

Enable RTL_433 frequency and active receiver change with WebUI
Add FSK environment for Heltec and Lilygo
This commit is contained in:
Florian authored and GitHub committed 2023-12-01 13:16:03 -06:00
1 parent eb5b8fa291
commit 7db2e93c28
15 files changed
+742 -559

No files matched your search

+8 -9
View File
@@ -34,9 +34,6 @@
# endif
void setupSomfy() {
# ifdef ZradioCC1101 //using with CC1101
ELECHOUSE_cc1101.Init();
# endif
pinMode(RF_EMITTER_GPIO, OUTPUT);
digitalWrite(RF_EMITTER_GPIO, LOW);
@@ -54,10 +51,13 @@ void setupSomfy() {
# if jsonReceiving
void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) {
if (cmpToMainTopic(topicOri, subjectMQTTtoSomfy)) {
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY_SOMFY);
# endif
Log.trace(F("MQTTtoSomfy json data analysis" CR));
float txFrequency = jsonData["frequency"] | RFConfig.frequency;
# ifdef ZradioCC1101 // set Receive off and Transmitt on
disableCurrentReceiver();
ELECHOUSE_cc1101.SetTx(txFrequency);
Log.notice(F("Transmit frequency: %F" CR), txFrequency);
# endif
const int remoteIndex = jsonData["remote"];
if (remoteIndex >= SOMFY_REMOTE_NUM) {
@@ -72,9 +72,8 @@ void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) {
EEPROMRollingCodeStorage rollingCodeStorage(EEPROM_ADDRESS_START + remoteIndex * 2);
SomfyRemote somfyRemote(RF_EMITTER_GPIO, somfyRemotes[remoteIndex], &rollingCodeStorage);
somfyRemote.sendCommand(command, repeat);
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
initCC1101();
enableActiveReceiver();
}
}
# endif
+334
View File
@@ -0,0 +1,334 @@
/*
OpenMQTTGateway - ESP8266 or Arduino program for home automation
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
(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"
#if defined(ZgatewayRF) || defined(ZgatewayPilight) || defined(ZgatewayRTL_433) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
# ifndef ARDUINO_AVR_UNO
# ifdef ZradioCC1101
# include <ELECHOUSE_CC1101_SRC_DRV.h>
# endif
void initCC1101() {
# ifdef ZradioCC1101 //receiving with CC1101
// Loop on getCC1101() until it returns true and break after 10 attempts
for (int i = 0; i < 10; i++) {
if (ELECHOUSE_cc1101.getCC1101()) {
Log.notice(F("C1101 spi Connection OK" CR));
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(RFConfig.frequency);
break;
} else {
Log.error(F("C1101 spi Connection Error" CR));
delay(500);
}
}
# endif
}
void setupCommonRF() {
RFConfig_init();
RFConfig_load();
}
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;
}
int currentReceiver = ACTIVE_NONE;
# if !defined(ZgatewayRFM69) && !defined(ZactuatorSomfy)
# if defined(ESP8266) || defined(ESP32)
// 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
# endif
void disableCurrentReceiver() {
Log.trace(F("disableCurrentReceiver: %d" CR), currentReceiver);
switch (currentReceiver) {
case ACTIVE_NONE:
break;
# 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), RFConfig.activeReceiver);
# endif
}
}
void enableActiveReceiver() {
Log.trace(F("enableActiveReceiver: %d" CR), RFConfig.activeReceiver);
switch (RFConfig.activeReceiver) {
# ifdef ZgatewayPilight
case ACTIVE_PILIGHT:
initCC1101();
enablePilightReceive();
currentReceiver = ACTIVE_PILIGHT;
break;
# endif
# ifdef ZgatewayRF
case ACTIVE_RF:
initCC1101();
enableRFReceive();
currentReceiver = ACTIVE_RF;
break;
# endif
# ifdef ZgatewayRTL_433
case ACTIVE_RTL:
initCC1101();
enableRTLreceive();
currentReceiver = ACTIVE_RTL;
break;
# endif
# ifdef ZgatewayRF2
case ACTIVE_RF2:
initCC1101();
enableRF2Receive();
currentReceiver = ACTIVE_RF2;
break;
# endif
case ACTIVE_RECERROR:
Log.error(F("ERROR: no receiver selected" CR));
break;
# ifndef ARDUINO_AVR_UNO // Space issues with the UNO
default:
Log.error(F("ERROR: unsupported receiver %d" CR), RFConfig.activeReceiver);
# endif
}
}
String stateRFMeasures() {
//Publish RTL_433 state
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject RFdata = jsonBuffer.to<JsonObject>();
RFdata["active"] = RFConfig.activeReceiver;
# if defined(ZradioCC1101) || defined(ZradioSX127x)
RFdata["frequency"] = RFConfig.frequency;
if (RFConfig.activeReceiver == ACTIVE_RTL) {
# ifdef ZgatewayRTL_433
RFdata["rssithreshold"] = (int)getRTLrssiThreshold();
RFdata["rssi"] = (int)getRTLCurrentRSSI();
RFdata["avgrssi"] = (int)getRTLAverageRSSI();
RFdata["count"] = (int)getRTLMessageCount();
# endif
# ifdef ZradioSX127x
RFdata["ookthreshold"] = (int)getOOKThresh();
# endif
}
# endif
pub(subjectcommonRFtoMQTT, RFdata);
String output;
serializeJson(RFdata, output);
return output;
}
void RFConfig_fromJson(JsonObject& RFdata) {
bool success = false;
if (RFdata.containsKey("frequency") && validFrequency(RFdata["frequency"])) {
Config_update(RFdata, "frequency", RFConfig.frequency);
Log.notice(F("RF Receive mhz: %F" CR), RFConfig.frequency);
success = true;
}
if (RFdata.containsKey("active")) {
Log.notice(F("RF receiver active: %d" CR), RFConfig.activeReceiver);
Config_update(RFdata, "active", RFConfig.activeReceiver);
success = true;
}
# ifdef ZgatewayRTL_433
if (RFdata.containsKey("rssithreshold")) {
Log.notice(F("RTL_433 RSSI Threshold : %d " CR), RFConfig.rssiThreshold);
Config_update(RFdata, "rssithreshold", RFConfig.rssiThreshold);
rtl_433.setRSSIThreshold(RFConfig.rssiThreshold);
success = true;
}
# if defined(RF_SX1276) || defined(RF_SX1278)
if (RFdata.containsKey("ookthreshold")) {
Config_update(RFdata, "ookthreshold", RFConfig.newOokThreshold);
Log.notice(F("RTL_433 ookThreshold %d" CR), RFConfig.newOokThreshold);
rtl_433.setOOKThreshold(RFConfig.newOokThreshold);
success = true;
}
# endif
if (RFdata.containsKey("status")) {
Log.notice(F("RF get status:" CR));
rtl_433.getStatus();
success = true;
}
if (!success) {
Log.error(F("MQTTtoRF Fail json" CR));
}
# endif
disableCurrentReceiver();
enableActiveReceiver();
# ifdef ESP32
if (RFdata.containsKey("erase") && RFdata["erase"].as<bool>()) {
// Erase config from NVS (non-volatile storage)
preferences.begin(Gateway_Short_Name, false);
if (preferences.isKey("RFConfig")) {
int result = preferences.remove("RFConfig");
Log.notice(F("RF config erase result: %d" CR), result);
preferences.end();
return; // Erase prevails on save, so skipping save
} else {
Log.notice(F("RF config not found" CR));
preferences.end();
}
}
if (RFdata.containsKey("save") && RFdata["save"].as<bool>()) {
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject jo = jsonBuffer.to<JsonObject>();
jo["frequency"] = RFConfig.frequency;
jo["active"] = RFConfig.activeReceiver;
// Don't save those for now, need to be tested
# ifdef ZgatewayRTL_433
//jo["rssithreshold"] = RFConfig.rssiThreshold;
//jo["ookthreshold"] = RFConfig.newOokThreshold;
# endif
// Save config into NVS (non-volatile storage)
String conf = "";
serializeJson(jsonBuffer, conf);
preferences.begin(Gateway_Short_Name, false);
int result = preferences.putString("RFConfig", conf);
preferences.end();
Log.notice(F("RF Config_save: %s, result: %d" CR), conf.c_str(), result);
}
# endif
}
void RFConfig_init() {
RFConfig.frequency = RF_FREQUENCY;
RFConfig.activeReceiver = ACTIVE_RECEIVER;
RFConfig.rssiThreshold = 0;
RFConfig.newOokThreshold = 0;
}
void RFConfig_load() {
# ifdef ESP32
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
preferences.begin(Gateway_Short_Name, true);
if (preferences.isKey("RFConfig")) {
auto error = deserializeJson(jsonBuffer, preferences.getString("RFConfig", "{}"));
preferences.end();
if (error) {
Log.error(F("RF Config deserialization failed: %s, buffer capacity: %u" CR), error.c_str(), jsonBuffer.capacity());
return;
}
if (jsonBuffer.isNull()) {
Log.warning(F("RF Config is null" CR));
return;
}
JsonObject jo = jsonBuffer.as<JsonObject>();
RFConfig_fromJson(jo);
Log.notice(F("RF Config loaded" CR));
} else {
preferences.end();
Log.notice(F("RF Config not found using default" CR));
enableActiveReceiver();
}
# else
enableActiveReceiver();
# endif
}
void MQTTtoRFset(char* topicOri, JsonObject& RFdata) {
if (cmpToMainTopic(topicOri, subjectMQTTtoRFset)) {
Log.trace(F("MQTTtoRF json set" CR));
/*
* Configuration modifications priorities:
* First `init=true` and `load=true` commands are executed (if both are present, INIT prevails on LOAD)
* Then parameters included in json are taken in account
* Finally `erase=true` and `save=true` commands are executed (if both are present, ERASE prevails on SAVE)
*/
if (RFdata.containsKey("init") && RFdata["init"].as<bool>()) {
// Restore the default (initial) configuration
RFConfig_init();
} else if (RFdata.containsKey("load") && RFdata["load"].as<bool>()) {
// Load the saved configuration, if not initialised
RFConfig_load();
}
// Load config from json if available
RFConfig_fromJson(RFdata);
stateRFMeasures();
}
}
# else
void RFConfig_init() {}
void RFConfig_load() {}
void MQTTtoRFset(char* topicOri, JsonObject& RFdata) {}
void enableActiveReceiver() {}
# endif
#endif
+21 -67
View File
@@ -112,21 +112,6 @@ void pilightRawCallback(const uint16_t* pulses, size_t length) {
}
# endif
void setupPilight() {
# ifdef ZradioCC1101 //receiving with CC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
# 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%s" CR), mqtt_topic, gateway_name, subjectMQTTtoPilight);
Log.trace(F("ZgatewayPilight setup done " CR));
}
void savePilightConfig() {
Log.trace(F("saving Pilight config" CR));
DynamicJsonDocument json(4096);
@@ -211,10 +196,19 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
}
} else if (cmpToMainTopic(topicOri, subjectMQTTtoPilight)) {
const char* message = Pilightdata["message"];
Log.notice(F("MQTTtoPilight message: %s" CR), message);
const char* protocol = Pilightdata["protocol"];
Log.notice(F("MQTTtoPilight protocol: %s" CR), protocol);
const char* raw = Pilightdata["raw"];
float tempMhz = Pilightdata["mhz"];
float txFrequency = Pilightdata["frequency"] | RFConfig.frequency;
bool success = false;
disableCurrentReceiver();
initCC1101();
# ifdef ZradioCC1101 // set Receive off and Transmitt on
ELECHOUSE_cc1101.SetTx(txFrequency);
Log.notice(F("Transmit frequency: %F" CR), txFrequency);
# endif
pinMode(RF_EMITTER_GPIO, OUTPUT);
if (raw) {
uint16_t codes[MAXPULSESTREAMLENGTH];
int repeats = rf.stringToRepeats(raw);
@@ -231,13 +225,6 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
}
int msgLength = rf.stringToPulseTrain(raw, codes, MAXPULSESTREAMLENGTH);
if (msgLength > 0) {
# ifdef ZradioCC1101
disableActiveReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(receiveMhz); // set Transmit on
rf.disableReceiver();
# endif
rf.sendPulseTrain(codes, msgLength, repeats);
Log.notice(F("MQTTtoPilight raw ok" CR));
success = true;
@@ -262,18 +249,11 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
}
if (message && protocol) {
Log.trace(F("MQTTtoPilight msg & protocol ok" CR));
# ifdef ZradioCC1101
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);
if (msgLength > 0) {
Log.trace(F("Adv data MQTTtoPilight push state via PilighttoMQTT" CR));
Pilightdata["origin"] = subjectGTWPilighttoMQTT;
handleJsonEnqueue(Pilightdata);
// Acknowledgement
pub(subjectGTWPilighttoMQTT, message);
success = true;
} else {
switch (msgLength) {
@@ -294,26 +274,11 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
}
}
}
if (Pilightdata.containsKey("active")) {
Log.trace(F("PiLight active:" CR));
activeReceiver = ACTIVE_PILIGHT; // Enable PILIGHT gateway
success = true;
}
# ifdef ZradioCC1101
if (Pilightdata.containsKey("mhz") && validFrequency(tempMhz)) {
receiveMhz = tempMhz;
Log.notice(F("PiLight Receive mhz: %F" CR), receiveMhz);
success = true;
}
# endif
if (success) {
// 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
pub(subjectGTWPilighttoMQTT, Pilightdata);
} else {
if (!success) {
pub(subjectGTWPilighttoMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
Log.error(F("MQTTtoPilight Fail json" CR));
}
enableActiveReceiver(false);
enableActiveReceiver();
}
}
@@ -324,25 +289,13 @@ extern void disablePilightReceive() {
};
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
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.trace(F("ZgatewayPilight command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoPilight);
initCC1101();
# ifdef ZradioCC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
rf.setCallback(pilightCallback);
# ifdef Pilight_rawEnabled
if (pilightRawEnabled) {
@@ -353,5 +306,6 @@ extern void enablePilightReceive() {
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();
Log.trace(F("ZgatewayPilight setup done " CR));
};
#endif
+26 -90
View File
@@ -106,31 +106,6 @@ void RFtoMQTTdiscovery(SIGNAL_SIZE_UL_ULL MQTTvalue) {
}
# endif
void setupRF() {
//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);
# ifdef ZradioCC1101 //receiving with CC1101
if (ELECHOUSE_cc1101.getCC1101()) {
Log.notice(F("C1101 spi Connection OK" CR));
} else {
Log.error(F("C1101 spi Connection Error" CR));
}
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz);
# endif
# ifdef RF_DISABLE_TRANSMIT
mySwitch.disableTransmit();
# else
mySwitch.enableTransmit(RF_EMITTER_GPIO);
# endif
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT);
mySwitch.enableReceive(RF_RECEIVER_GPIO);
Log.trace(F("ZgatewayRF command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRF);
Log.trace(F("ZgatewayRF setup done" CR));
}
void RFtoMQTT() {
if (mySwitch.available()) {
StaticJsonDocument<JSON_MSG_BUFFER> RFdataBuffer;
@@ -161,7 +136,7 @@ void RFtoMQTT() {
RFdata["raw"] = rawDump;
# endif
# ifdef ZradioCC1101 // set Receive off and Transmitt on
RFdata["mhz"] = receiveMhz;
RFdata["frequency"] = RFConfig.frequency;
# endif
mySwitch.resetAvailable();
@@ -187,9 +162,9 @@ void RFtoMQTT() {
# if simpleReceiving
void MQTTtoRF(char* topicOri, char* datacallback) {
# ifdef ZradioCC1101 // set Receive off and Transmitt on
disableActiveReceiver();
ELECHOUSE_cc1101.SetTx(receiveMhz);
Log.notice(F("Transmit mhz: %F" CR), receiveMhz);
disableCurrentReceiver();
ELECHOUSE_cc1101.SetTx(RFConfig.frequency);
Log.notice(F("Transmit frequency: %F" CR), RFConfig.frequency);
# endif
mySwitch.disableReceive();
mySwitch.enableTransmit(RF_EMITTER_GPIO);
@@ -241,7 +216,7 @@ void MQTTtoRF(char* topicOri, char* datacallback) {
pub(subjectGTWRFtoMQTT, datacallback); // 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
}
# ifdef ZradioCC1101 // set Receive on and Transmitt off
ELECHOUSE_cc1101.SetRx(receiveMhz);
ELECHOUSE_cc1101.SetRx(RFConfig.frequency);
mySwitch.disableTransmit();
mySwitch.enableReceive(RF_RECEIVER_GPIO);
# endif
@@ -261,20 +236,16 @@ void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding
Log.notice(F("RF Protocol:%d" CR), valuePRT);
Log.notice(F("RF Pulse Lgth: %d" CR), valuePLSL);
Log.notice(F("Bits nb: %d" CR), valueBITS);
# ifdef ZradioCC1101 // set Receive off and Transmitt on
disableActiveReceiver();
# ifdef ZradioCC1101
disableCurrentReceiver();
initCC1101();
int txPower = RFdata["txpower"] | RF_CC1101_TXPOWER;
ELECHOUSE_cc1101.setPA((int)txPower);
Log.notice(F("CC1101 TX Power: %d" CR), txPower);
float trMhz = RFdata["mhz"] | CC1101_FREQUENCY;
if (validFrequency((int)trMhz)) {
ELECHOUSE_cc1101.SetTx(trMhz);
Log.notice(F("Transmit mhz: %F" CR), trMhz);
}
float txFrequency = RFdata["frequency"] | RFConfig.frequency;
ELECHOUSE_cc1101.SetTx(txFrequency);
Log.notice(F("Transmit frequency: %F" CR), txFrequency);
# endif
mySwitch.disableReceive();
mySwitch.enableTransmit(RF_EMITTER_GPIO);
mySwitch.setRepeatTransmit(valueRPT);
mySwitch.setProtocol(valuePRT, valuePLSL);
@@ -283,32 +254,9 @@ void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding
// 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
pub(subjectGTWRFtoMQTT, RFdata);
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 (RFdata.containsKey("mhz") && validFrequency(tempMhz)) {
receiveMhz = tempMhz;
Log.notice(F("Receive mhz: %F" CR), receiveMhz);
success = true;
}
# endif
if (success) {
// 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
pub(subjectGTWRFtoMQTT, RFdata);
} else {
# ifndef ARDUINO_AVR_UNO // Space issues with the UNO
pub(subjectGTWRFtoMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
# endif
Log.error(F("MQTTtoRF Fail json" CR));
}
}
enableActiveReceiver(false);
enableActiveReceiver();
}
}
# endif
@@ -317,36 +265,24 @@ int receiveInterupt = -1;
void disableRFReceive() {
Log.trace(F("disableRFReceive %d" CR), receiveInterupt);
if (receiveInterupt != -1) {
receiveInterupt = -1;
mySwitch.disableReceive();
}
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
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);
# ifdef ZradioCC1101 // set Receive on and Transmitt off
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz);
# endif
# ifdef RF_DISABLE_TRANSMIT
mySwitch.disableTransmit();
# else
mySwitch.enableTransmit(RF_EMITTER_GPIO);
# endif
receiveInterupt = RF_RECEIVER_GPIO;
mySwitch.enableReceive(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);
Log.trace(F("ZgatewayRF setup done" CR));
}
#endif
+13 -62
View File
@@ -55,21 +55,6 @@ struct RF2rxd {
RF2rxd rf2rd;
void setupRF2() {
# ifdef ZradioCC1101 //receiving with CC1101
ELECHOUSE_cc1101.Init();
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%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRF2);
Log.trace(F("ZgatewayRF2 setup done " CR));
pinMode(RF_EMITTER_GPIO, OUTPUT);
digitalWrite(RF_EMITTER_GPIO, LOW);
}
# ifdef ZmqttDiscovery
//Register for autodiscover in Home Assistant
void RF2toMQTTdiscovery(JsonObject& data) {
@@ -148,13 +133,9 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
# if simpleReceiving
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
initCC1101();
// RF DATA ANALYSIS
//We look into the subject to see if a special RF protocol is defined
@@ -253,7 +234,7 @@ void MQTTtoRF2(char* topicOri, char* datacallback) {
}
}
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
ELECHOUSE_cc1101.SetRx(RFConfig.frequency); // set Receive on
NewRemoteReceiver::enable();
# endif
}
@@ -267,13 +248,9 @@ void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding
int boolSWITCHTYPE = RF2data["switchType"] | 99;
bool success = false;
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
initCC1101();
Log.trace(F("MQTTtoRF2 switch type ok" CR));
bool isDimCommand = boolSWITCHTYPE == 2;
unsigned long valueCODE = RF2data["address"];
@@ -311,19 +288,6 @@ void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding
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) {
// 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
pub(subjectRF2toMQTT, RF2data);
@@ -333,39 +297,26 @@ void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding
# endif
Log.error(F("MQTTtoRF2 failed json read" CR));
}
enableActiveReceiver(false);
enableActiveReceiver();
}
}
# endif
void disableRF2Receive() {
Log.trace(F("disableRF2Receive" CR));
NewRemoteReceiver::deinit();
NewRemoteReceiver::init(-1, 2, rf2Callback); // mark _interupt with -1
NewRemoteReceiver::deinit();
NewRemoteReceiver::disable();
}
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
# ifdef ZradioCC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
Log.trace(F("enableRF2Receive" CR));
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%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRF2);
pinMode(RF_EMITTER_GPIO, OUTPUT);
digitalWrite(RF_EMITTER_GPIO, LOW);
Log.trace(F("ZgatewayRF2 setup done " CR));
}
#endif
+3 -65
View File
@@ -40,8 +40,6 @@
char messageBuffer[JSON_MSG_BUFFER];
rtl_433_ESP rtl_433;
# ifdef ZmqttDiscovery
SemaphoreHandle_t semaphorecreateOrUpdateDeviceRTL_433;
std::vector<RTL_433device*> RTL_433devices;
@@ -273,7 +271,7 @@ void setupRTL_433() {
semaphorecreateOrUpdateDeviceRTL_433 = xSemaphoreCreateBinary();
xSemaphoreGive(semaphorecreateOrUpdateDeviceRTL_433);
# endif
Log.trace(F("ZgatewayRTL_433 command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRTL_433);
Log.trace(F("ZgatewayRTL_433 command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRFset);
Log.notice(F("ZgatewayRTL_433 setup done " CR));
}
@@ -281,69 +279,9 @@ void RTL_433Loop() {
rtl_433.loop();
}
extern void MQTTtoRTL_433(char* topicOri, JsonObject& RTLdata) {
if (cmpToMainTopic(topicOri, subjectMQTTtoRTL_433)) {
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);
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 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_MODULE_RECEIVER_GPIO, receiveMhz);
success = true;
}
if (RTLdata.containsKey("status")) {
Log.notice(F("RTL_433 get status:" CR));
rtl_433.getStatus();
success = true;
}
if (success) {
pub(subjectRTL_433toMQTT, RTLdata);
} else {
pub(subjectRTL_433toMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
Log.error(F("[rtl_433] MQTTtoRTL_433 Fail json" CR));
}
enableActiveReceiver(false);
}
}
extern void enableRTLreceive() {
Log.notice(F("Switching to RTL_433 Receiver: %FMhz" CR), receiveMhz);
# ifdef ZgatewayRF
disableRFReceive();
# endif
# ifdef ZgatewayRF2
disableRF2Receive();
# endif
# ifdef ZgatewayPilight
disablePilightReceive();
# endif
rtl_433.initReceiver(RF_MODULE_RECEIVER_GPIO, receiveMhz);
Log.notice(F("Enable RTL_433 Receiver: %FMhz" CR), RFConfig.frequency);
rtl_433.initReceiver(RF_MODULE_RECEIVER_GPIO, RFConfig.frequency);
rtl_433.enableReceiver();
}
+142 -7
View File
@@ -947,54 +947,72 @@ void handleLA() {
if (server.hasArg("save")) {
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject WEBtoLORA = jsonBuffer.to<JsonObject>();
bool update = false;
if (server.hasArg("lf")) {
WEBtoLORA["frequency"] = server.arg("lf");
update = true;
}
if (server.hasArg("lt")) {
WEBtoLORA["txpower"] = server.arg("lt");
update = true;
}
if (server.hasArg("ls")) {
WEBtoLORA["spreadingfactor"] = server.arg("ls");
update = true;
}
if (server.hasArg("lb")) {
WEBtoLORA["signalbandwidth"] = server.arg("lb");
update = true;
}
if (server.hasArg("lc")) {
WEBtoLORA["codingrate"] = server.arg("lc");
update = true;
}
if (server.hasArg("ll")) {
WEBtoLORA["preamblelength"] = server.arg("ll");
update = true;
}
if (server.hasArg("lw")) {
WEBtoLORA["syncword"] = server.arg("lw");
update = true;
}
if (server.hasArg("lr")) {
WEBtoLORA["enablecrc"] = server.arg("lr");
update = true;
} else {
WEBtoLORA["enablecrc"] = false;
update = true;
}
if (server.hasArg("li")) {
WEBtoLORA["invertiq"] = server.arg("li");
update = true;
} else {
WEBtoLORA["invertiq"] = false;
update = true;
}
if (server.hasArg("ok")) {
WEBtoLORA["onlyknown"] = server.arg("ok");
update = true;
} else {
WEBtoLORA["onlyknown"] = false;
update = true;
}
if (update) {
Log.notice(F("[WebUI] Save data" CR));
WEBtoLORA["save"] = true;
LORAConfig_fromJson(WEBtoLORA);
stateLORAMeasures();
Log.trace(F("[WebUI] LORAConfig end" CR));
}
LORAConfig_fromJson(WEBtoLORA);
}
}
char jsonChar[100];
@@ -1056,8 +1074,121 @@ void handleLA() {
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
response += String(buffer);
server.send(200, "text/html", response);
stateLORAMeasures();
Log.trace(F("[WebUI] LORAConfig end" CR));
}
# elif defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
# include <map>
std::map<int, String> activeReceiverOptions = {
{0, "Inactive"},
# if defined(ZgatewayPilight) && !defined(ZradioSX127x)
{1, "PiLight"},
# endif
# if defined(ZgatewayRF) && !defined(ZradioSX127x)
{2, "RF"},
# endif
# ifdef ZgatewayRTL_433
{3, "RTL_433"},
# endif
# if defined(ZgatewayRF2) && !defined(ZradioSX127x)
{4, "RF2 (restart required)"}
# endif
};
bool isValidReceiver(int receiverId) {
// Check if the receiverId exists in the activeReceiverOptions map
return activeReceiverOptions.find(receiverId) != activeReceiverOptions.end();
}
String generateActiveReceiverOptions(int currentSelection) {
String optionsHtml = "";
for (const auto& option : activeReceiverOptions) {
optionsHtml += "<option value='" + String(option.first) + "'";
if (currentSelection == option.first) {
optionsHtml += " selected";
}
optionsHtml += ">" + option.second + "</option>";
}
return optionsHtml;
}
/**
* @brief /RF - Configure RF Page
* T: handleRF: uri: /rf, args: 2, method: 1
* T: handleRF Arg: 0, rf=868.30
* T: handleRF Arg: 1, oo=0
* T: handleRF Arg: 2, rs=0
* T: handleRF Arg: 3, dg=0
* T: handleRF Arg: 4, ar=0
* T: handleRF Arg: 4, save=
*/
void handleRF() {
WEBUI_TRACE_LOG(F("handleRF: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
WEBUI_SECURE
bool update = false;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject WEBtoRF = jsonBuffer.to<JsonObject>();
if (server.args()) {
for (uint8_t i = 0; i < server.args(); i++) {
WEBUI_TRACE_LOG(F("handleRF Arg: %d, %s=%s" CR), i, server.argName(i).c_str(), server.arg(i).c_str());
}
if (server.hasArg("save")) {
if (server.hasArg("rf")) {
String freqStr = server.arg("rf");
RFConfig.frequency = freqStr.toFloat();
if (validFrequency(RFConfig.frequency)) {
WEBtoRF["frequency"] = RFConfig.frequency;
update = true;
} else {
Log.warning(F("[WebUI] Invalid Frequency" CR));
}
}
if (server.hasArg("ar")) {
int selectedReceiver = server.arg("ar").toInt();
if (isValidReceiver(selectedReceiver)) { // Assuming isValidReceiver is a validation function
RFConfig.activeReceiver = selectedReceiver;
WEBtoRF["activereceiver"] = RFConfig.activeReceiver;
update = true;
} else {
Log.warning(F("[WebUI] Invalid Active Receiver" CR));
}
}
if (server.hasArg("oo")) {
RFConfig.newOokThreshold = server.arg("oo").toInt();
WEBtoRF["ookthreshold"] = RFConfig.newOokThreshold;
update = true;
}
if (server.hasArg("rs")) {
RFConfig.rssiThreshold = server.arg("rs").toInt();
WEBtoRF["rssithreshold"] = RFConfig.rssiThreshold;
update = true;
}
if (update) {
Log.notice(F("[WebUI] Save data" CR));
WEBtoRF["save"] = true;
RFConfig_fromJson(WEBtoRF);
stateRFMeasures();
Log.trace(F("[WebUI] RFConfig end" CR));
}
}
}
String activeReceiverHtml = generateActiveReceiverOptions(RFConfig.activeReceiver);
char jsonChar[100];
serializeJson(modules, jsonChar, measureJson(modules) + 1);
char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Configure RF").c_str());
String response = String(buffer);
response += String(script);
response += String(style);
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_rf_body, jsonChar, gateway_name, RFConfig.frequency, activeReceiverHtml.c_str());
response += String(buffer);
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
response += String(buffer);
server.send(200, "text/html", response);
}
# endif
@@ -1228,6 +1359,10 @@ void handleIN() {
# if defined(ZgatewayLORA)
informationDisplay += "1<BR>LORA}2}1";
informationDisplay += stateLORAMeasures();
# endif
# if defined(ZgatewayRF)
informationDisplay += "1<BR>RF}2}1";
informationDisplay += stateRFMeasures();
# endif
informationDisplay += "1<BR>WebUI}2}1";
informationDisplay += stateWebUIStatus();
@@ -1494,6 +1629,8 @@ void WebUISetup() {
server.on("/wu", handleWU); // Configure WebUI
# ifdef ZgatewayLORA
server.on("/la", handleLA); // Configure LORA
# elif defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
server.on("/rf", handleRF); // Configure RF
# endif
# if defined(ZgatewayCloud)
server.on("/cl", handleCL); // Configure Cloud
@@ -1666,8 +1803,6 @@ void webUIPubPrint(const char* topicori, JsonObject& data) {
// WEBUI_TRACE_LOG(F("[ webUIPubPrint ] switch %s " CR), message->title);
switch (webUIHash(message->title)) {
case webUIHash("SYStoMQTT"): {
// {"uptime":456356,"version":"lilygo-rtl_433-test-A-v1.1.1-25-g574177d[lily-cloud]","freemem":125488,"mqttport":"1883","mqttsecure":false,"freestack":3752,"rssi":-36,"SSID":"The_Beach","BSSID":"64:A5:C3:69:C3:38","ip":"192.168.1.239","mac":"4C:75:25:A8:D5:D8","actRec":3,"mhz":433.92,"RTLRssiThresh":-98,"RTLRssi":-108,"RTLAVGRssi":-107,"RTLCnt":121707,"RTLOOKThresh":90,"modules":["LILYGO_OLED","CLOUD","rtl_433"]}
// Line 1
if (data["version"]) {
+41 -169
View File
@@ -29,10 +29,6 @@
#include <Arduino.h>
#include <ArduinoJson.h>
#if defined(ESP8266) || defined(ESP32)
# include <EEPROM.h>
#endif
#ifdef ZgatewayRF
extern void setupRF();
extern void RFtoMQTT();
@@ -42,7 +38,6 @@ 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);
@@ -58,9 +53,11 @@ extern void disablePilightReceive();
extern void enablePilightReceive();
#endif
#ifdef ZgatewayRTL_433
# include <rtl_433_ESP.h>
rtl_433_ESP rtl_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 getRTLrssiThreshold();
@@ -134,13 +131,14 @@ const char parameters[40][4][24] = {
#endif
/*-------------------RF topics & parameters----------------------*/
//433Mhz MQTT Subjects and keys
#define subjectMQTTtoRF "/commands/MQTTto433"
#define subjectRFtoMQTT "/433toMQTT"
#define subjectGTWRFtoMQTT "/433toMQTT"
#define RFprotocolKey "433_" // protocol will be defined if a subject contains RFprotocolKey followed by a value of 1 digit
#define RFbitsKey "RFBITS_" // bits will be defined if a subject contains RFbitsKey followed by a value of 2 digits
#define repeatRFwMQTT false // do we repeat a received signal by using MQTT with RF gateway
#define RFpulselengthKey "PLSL_" // pulselength will be defined if a subject contains RFprotocolKey followed by a value of 3 digits
#define subjectMQTTtoRF "/commands/MQTTto433"
#define subjectRFtoMQTT "/433toMQTT"
#define subjectcommonRFtoMQTT "/RFtoMQTT"
#define subjectGTWRFtoMQTT "/433toMQTT"
#define RFprotocolKey "433_" // protocol will be defined if a subject contains RFprotocolKey followed by a value of 1 digit
#define RFbitsKey "RFBITS_" // bits will be defined if a subject contains RFbitsKey followed by a value of 2 digits
#define repeatRFwMQTT false // do we repeat a received signal by using MQTT with RF gateway
#define RFpulselengthKey "PLSL_" // pulselength will be defined if a subject contains RFprotocolKey followed by a value of 3 digits
// subject monitored to listen traffic processed by other gateways to store data and avoid ntuple
#define subjectMultiGTWRF "+/+/433toMQTT"
//RF number of signal repetition - Can be overridden by specifying "repeat" in a JSON message.
@@ -171,18 +169,39 @@ const char parameters[40][4][24] = {
/*-------------------RTL_433 topics & parameters----------------------*/
//433Mhz RTL_433 MQTT Subjects and keys
#define subjectMQTTtoRTL_433 "/commands/MQTTtoRTL_433"
#define subjectMQTTtoRFset "/commands/MQTTtoRF/config"
#define subjectRTL_433toMQTT "/RTL_433toMQTT"
/*-------------------CC1101 frequency----------------------*/
//Match frequency to the hardware version of the radio if ZradioCC1101 is used.
#ifndef CC1101_FREQUENCY
# define CC1101_FREQUENCY 433.92
#endif
// Allow ZGatewayRF Module to change receive frequency of CC1101 Transceiver module
#if defined(ZradioCC1101) || defined(ZradioSX127x)
float receiveMhz = CC1101_FREQUENCY;
/*-------------------RF frequency----------------------*/
//Match frequency to the hardware version of the radio used.
#ifndef RF_FREQUENCY
# define RF_FREQUENCY 433.92
#endif
/**
* Active Module
* 1 = ZgatewayPilight
* 2 = ZgatewayRF
* 3 = ZgatewayRTL_433
* 4 = ZgatewayRF2
*/
struct RFConfig_s {
float frequency;
int rssiThreshold;
int newOokThreshold;
int activeReceiver;
};
#define ACTIVE_NONE -1
#define ACTIVE_RECERROR 0
#define ACTIVE_PILIGHT 1
#define ACTIVE_RF 2
#define ACTIVE_RTL 3
#define ACTIVE_RF2 4
RFConfig_s RFConfig;
/*-------------------CC1101 DefaultTXPower----------------------*/
//Adjust the default TX-Power for sending radio if ZradioCC1101 is used.
//The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
@@ -217,151 +236,4 @@ 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
# 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)
return true;
if (mhz >= 387 && mhz <= 464)
return true;
if (mhz >= 779 && mhz <= 928)
return true;
return false;
}
# endif
int currentReceiver = -1;
# if !defined(ZgatewayRFM69) && !defined(ZactuatorSomfy)
# if defined(ESP8266) || defined(ESP32)
// 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
# endif
void enableActiveReceiver(bool isBoot) {
// Save currently active receiver and restore after reboot.
// Only works with ESP and if there is no conflict.
# if !defined(ZgatewayRFM69) && !defined(ZactuatorSomfy)
# if defined(ESP8266) || defined(ESP32)
# define _ACTIVE_RECV_MAGIC 0xA1B2C3D4
struct {
uint64_t magic;
int receiver;
} data;
EEPROM.begin(sizeof(data));
EEPROM.get(0, data);
if (isBoot && data.magic == _ACTIVE_RECV_MAGIC && validReceiver(data.receiver)) {
activeReceiver = data.receiver;
} else {
data.magic = _ACTIVE_RECV_MAGIC;
data.receiver = activeReceiver;
EEPROM.put(0, data);
}
EEPROM.end();
# endif
# endif
// 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;
}
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
+1 -1
View File
@@ -40,6 +40,6 @@ const uint32_t somfyRemotes[SOMFY_REMOTE_NUM] = {0x5184c8};
#define subjectMQTTtoSomfy "/commands/MQTTtoSomfy"
/*-------------------INTERNAL DEFINITIONS----------------------*/
#define CC1101_FREQUENCY_SOMFY 433.42
#define RF_FREQUENCY_SOMFY 433.42
#endif
+25
View File
@@ -57,6 +57,8 @@
#define configure_5 "<p><form action='lo' method='get'><button>Configure Logging</button></form></p>"
#ifdef ZgatewayLORA
# define configure_6 "<p><form action='la' method='get'><button>Configure LORA</button></form></p>"
#elif defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
# define configure_6 "<p><form action='rf' method='get'><button>Configure RF</button></form></p>"
#else
# define configure_6
#endif
@@ -110,6 +112,29 @@ const char config_logging_body[] = body_header "<fieldset class=\"set1\"><legend
const char config_webui_body[] = body_header "<fieldset class=\"set1\"><legend><span><b>Configure WebUI</b></span></legend><form method='get' action='wu'><p><b>Display Metric</b><br><input id='dm' type='checkbox' %s></p><p><b>Secure WebUI</b><br><input id='sw' type='checkbox' %s></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;
const char config_rf_body[] = body_header
"<fieldset class=\"set1\">"
"<legend><span><b>Configure RF</b></span></legend>"
"<form method='get' action='rf'>"
"<p><b>Frequency</b><br>"
"<input type='number' id='rf' name='rf' step='any' value='%.3f'></p>"
// Active library dropdown
"<p><b>Active library</b><br>"
"<select id='ar' name='ar'>%s</select></p>"
/* // Need testing
"<p><b>OOK Threshold</b><br>"
"<input type='number' id='oo' name='oo' step='any' value='%d'></p>"
"<p><b>RSSI Threshold</b><br>"
"<input type='number' id='rs' name='rs' step='any' value='%d'></p>"
*/
"<br><button name='save' type='submit' class='button bgrn'>Save</button>"
"</form>"
"</fieldset>" body_footer_config_menu;
const char config_lora_body[] = body_header
"<fieldset class=\"set1\">"
"<legend><span><b>Configure LORA</b></span></legend>"
+16 -34
View File
@@ -1189,7 +1189,11 @@ void setup() {
client.setCallback(callback);
delay(1500);
#if defined(ZgatewayRF) || defined(ZgatewayPilight) || defined(ZgatewayRTL_433) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
# ifndef ARDUINO_AVR_UNO
setupCommonRF();
# endif
#endif
#ifdef ZsensorBME280
setupZsensorBME280();
modules.add(ZsensorBME280);
@@ -1235,12 +1239,10 @@ void setup() {
modules.add(ZgatewayLORA);
#endif
#ifdef ZgatewayRF
setupRF();
modules.add(ZgatewayRF);
# define ACTIVE_RECEIVER ACTIVE_RF
#endif
#ifdef ZgatewayRF2
setupRF2();
modules.add(ZgatewayRF2);
# ifdef ACTIVE_RECEIVER
# undef ACTIVE_RECEIVER
@@ -1248,9 +1250,7 @@ void setup() {
# define ACTIVE_RECEIVER ACTIVE_RF2
#endif
#ifdef ZgatewayPilight
setupPilight();
modules.add(ZgatewayPilight);
disablePilightReceive();
# ifdef ACTIVE_RECEIVER
# undef ACTIVE_RECEIVER
# endif
@@ -1305,6 +1305,10 @@ void setup() {
modules.add(ZactuatorPWM);
#endif
#ifdef ZactuatorSomfy
# ifdef ACTIVE_RECEIVER
# undef ACTIVE_RECEIVER
# endif
# define ACTIVE_RECEIVER ACTIVE_NONE
setupSomfy();
modules.add(ZactuatorSomfy);
#endif
@@ -1336,20 +1340,12 @@ void setup() {
setupSHTC3();
#endif
#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(true);
setupRTL_433();
modules.add(ZgatewayRTL_433);
#endif
Log.trace(F("mqtt_max_packet_size: %d" CR), mqtt_max_packet_size);
@@ -2084,6 +2080,9 @@ void loop() {
# ifdef ZgatewayLORA
stateLORAMeasures();
# endif
# if defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
stateRFMeasures();
# endif
# if defined(ZwebUI) && defined(ESP32)
stateWebUIStatus();
# endif
@@ -2441,23 +2440,6 @@ String stateMeasures() {
SYSdata["m5batpower"] = (float)M5.Axp.GetBatPower();
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
# if defined(ZradioCC1101) || defined(ZradioSX127x)
SYSdata["mhz"] = (float)receiveMhz;
# endif
# if defined(ZgatewayRTL_433)
if (activeReceiver == ACTIVE_RTL) {
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;
@@ -2563,8 +2545,8 @@ 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);
#if defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
MQTTtoRFset(topicOri, jsondata);
#endif
#if jsonReceiving
# ifdef ZgatewayLORA