[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
+733 -550

No files matched your search

+2
View File
@@ -39,8 +39,10 @@ jobs:
- "esp32dev-rtl_433" - "esp32dev-rtl_433"
- "esp32doitv1-aithinker-r01-sx1278" - "esp32doitv1-aithinker-r01-sx1278"
- "heltec-rtl_433" - "heltec-rtl_433"
- "heltec-rtl_433-fsk"
- "heltec-ble" - "heltec-ble"
- "lilygo-rtl_433" - "lilygo-rtl_433"
- "lilygo-rtl_433-fsk"
- "lilygo-ble" - "lilygo-ble"
- "esp32dev-multi_receiver" - "esp32dev-multi_receiver"
- "esp32dev-multi_receiver-pilight" - "esp32dev-multi_receiver-pilight"
+37 -48
View File
@@ -25,6 +25,34 @@ OpenMQTTGateway leverages several libraries for RF communication:
RTL_433 library can only receive data, RCSwitch, PiLight, RF2 can receive and transmit. RTL_433 library can only receive data, RCSwitch, PiLight, RF2 can receive and transmit.
::: :::
## Common parameters accross modules
### Change default frequency (SX127X and CC1101)
The frequency can be can changed by sending an MQTT message or through the WebUI. Parameter is `frequency` and valid values are 300-348 Mhz, 387-464Mhz and 779-928Mhz. Actual frequency support will depend on your board
`home/OpenMQTTGateway/commands/MQTTtoRF/config {"frequency":315.026}`
Note that with CC1101 this frequency will be used as the default sending frequency.
### Changing Active Receiver Modules
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 enable the RF gateway module send a json message to the RF gateway module command subject with the key being 'active', and any value. The value at this time is ignored.
1 - PiLight
2 - RF
3 - RTL_433
4 - RF2
Example to receive from the RF gateway:
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoRF/config" -m '{"active":2}'`
The active receiver can also be changed with the WebUI.
The OpenMQTTGateway RFtoMQTT status message contains a key `active` which is the current active receiver module.
## RTL_433 device decoders ## RTL_433 device decoders
This feature is only available on a ESP32 based device with a supported transceiver connected due to the resource requirements of the rtl_433 device decoders. At the present time only Pulse Position Modulation (OOK_PPM), Pulse Width Modulation (OOK_PWM) and Pulse Manchester Zero Bit (OOK_PULSE_MANCHESTER_ZEROBIT) based decoders are available. This feature is only available on a ESP32 based device with a supported transceiver connected due to the resource requirements of the rtl_433 device decoders. At the present time only Pulse Position Modulation (OOK_PPM), Pulse Width Modulation (OOK_PWM) and Pulse Manchester Zero Bit (OOK_PULSE_MANCHESTER_ZEROBIT) based decoders are available.
@@ -122,21 +150,15 @@ Registering protocol [101] "X10 RF"
Registering protocol [102] "X10 Security" Registering protocol [102] "X10 Security"
``` ```
### Change receive frequency
Default receive frequency of the module is 433.92 Mhz, and this can be can changed by sending a message with the frequency. Parameter is `mhz` and valid values are 300-348 Mhz, 387-464Mhz and 779-928Mhz. Actual frequency support will depend on your board
`home/OpenMQTTGateway/commands/MQTTtoRTL_433 {"mhz":315.026}`
### Change Signal RSSI Threshold Delta ### Change Signal RSSI Threshold Delta
Delta applied to RSSI floor noise level to determine start and end of signal, defaults to 9db. Delta applied to RSSI floor noise level to determine start and end of signal, defaults to 9db.
`home/OpenMQTTGateway/commands/MQTTtoRTL_433 {"rssi": 9}` `home/OpenMQTTGateway/commands/MQTTtoRF/config {"rssiThreshold": 9}`
### Retrieve current status of receiver ### Retrieve current status of receiver
`home/OpenMQTTGateway/commands/MQTTtoRTL_433 {"status":1}` `home/OpenMQTTGateway/commands/MQTTtoRF/config {"status":1}`
``` ```
{"model":"status", {"model":"status",
@@ -159,42 +181,6 @@ Delta applied to RSSI floor noise level to determine start and end of signal, de
"freeMem":112880} - ESP32 memory available "freeMem":112880} - ESP32 memory available
``` ```
## Changing Active Receiver Modules
### Switching Active Receiver Module
Switching of the active transceiver (RTL_433 receiver only) module is available between the RF, RF2, RTL_433 and Pilight gateway modules, allowing for changing of signal decoders without redeploying the openMQTTGateway package. Sending a JSON message to the command topic of the desired receiver will change the active transceiver module.
To enable the RF gateway module send a json message to the RF gateway module command subject with the key being 'active', and any value. The value at this time is ignored.
Example:
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTto433" -m '{"active":true}'`
To enable the PiLight gateway module send a json message to the PiLight gateway module command subject with the key being 'active', and any value. The value at this time is ignored.
Example:
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight" -m '{"active":true}'`
To enable the RF2 gateway module send a json message to the RF2 gateway module command subject with the key being 'active', and any value. The value at this time is ignored.
Example:
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoRF2" -m '{"active":true}'`
To enable the RTL_433 gateway module send a json message to the RTL_433 gateway module command subject with the key being 'active', and any value. The value at this time is ignored.
Example:
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoRTL_433" -m '{"active":true}'`
### Status Messages
The openMQTTGateway status message contains a key `actRec` which is the current active receiver module.
1 - PiLight
2 - RF
3 - RTL_433
4 - RF2
## RCSwitch based gateway ## RCSwitch based gateway
### Receiving data from RF signal ### Receiving data from RF signal
@@ -258,15 +244,15 @@ Example:
Default transmit frequency of the CC1101 module is 433.92 Mhz, and this can be can changed by including the frequency in the transmit message. Parameter is `mhz` and valid values are 300-348 Mhz, 387-464Mhz and 779-928Mhz. Actual frequency support will depend on your CC1101 board. Default transmit frequency of the CC1101 module is 433.92 Mhz, and this can be can changed by including the frequency in the transmit message. Parameter is `mhz` and valid values are 300-348 Mhz, 387-464Mhz and 779-928Mhz. Actual frequency support will depend on your CC1101 board.
`home/OpenMQTTGateway/commands/MQTTto433 {"value":1150,"protocol":6,"length":12,"delay":450,"repeat":8,"mhz":303.732}` `home/OpenMQTTGateway/commands/MQTTto433 {"value":1150,"protocol":6,"length":12,"delay":450,"repeat":8,"frequency":303.732}`
Default receive frequency of the CC1101 module is 433.92 Mhz, and this can be can changed by sending a message with the frequency. Parameter is `mhz` and valid values are 300-348 Mhz, 387-464Mhz and 779-928Mhz. Actual frequency support will depend on your CC1101 board Default receive frequency of the CC1101 module is 433.92 Mhz, and this can be can changed by sending a message with the frequency. Parameter is `frequency` and valid values are 300-348 Mhz, 387-464Mhz and 779-928Mhz. Actual frequency support will depend on your CC1101 board
`home/OpenMQTTGateway/commands/MQTTto433 {"mhz":315.026}` `home/OpenMQTTGateway/commands/MQTTtoRF/config {"frequency":433.92}`
Messages received will include the frequency, and when transmitting on a different frequency the module return to the receive frequency afterwards. ie transmit messages on 303.732 Mhz then receive messages on 433.92 Mhz Messages received will include the frequency, and when transmitting on a different frequency the module return to the receive frequency afterwards. ie transmit messages on 303.732 Mhz then receive messages on 433.92 Mhz
`{"value":4534142,"protocol":6,"length":26,"delay":356,"mhz":315.026}` `{"value":4534142,"protocol":6,"length":26,"delay":356,"frequency":315.026}`
You can adjust the tx-power in db for a transmission. Parameter is `cc1101_pa` and valid values in decibel are (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max! You can adjust the tx-power in db for a transmission. Parameter is `cc1101_pa` and valid values in decibel are (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
That can be done to reduce range and therefore disturbances with other nearby devices. That can be done to reduce range and therefore disturbances with other nearby devices.
@@ -339,6 +325,9 @@ To list the enabled protocols on the Serial -
These commands will transmit by RF the signals to actuate an elro_400 switch. These commands will transmit by RF the signals to actuate an elro_400 switch.
With a different frequency (CC1101 only):
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight" -m '{"message":"{\"systemcode\":12,\"unitcode\":22,\"off\":1}","protocol":"elro_400_switch","frequency":315.026}'`
#### Using a raw signal #### Using a raw signal
You can transmit raw signal data by using the "raw" protocol. This uses the Pilight pulse train string format. One such example string, representing a transmission for Nexus protocol weather stations, looks like this: `c:03020202010102020102010101010101010202020201020102020202020101010201010202;p:500,1000,2000,4000;r:12@`. This string represents pulses and gaps directly. You can transmit raw signal data by using the "raw" protocol. This uses the Pilight pulse train string format. One such example string, representing a transmission for Nexus protocol weather stations, looks like this: `c:03020202010102020102010101010101010202020201020102020202020101010201010202;p:500,1000,2000,4000;r:12@`. This string represents pulses and gaps directly.
+70 -6
View File
@@ -195,6 +195,7 @@ custom_description = RF gateway using ESPilight library
[env:esp32dev-pilight-cc1101] [env:esp32dev-pilight-cc1101]
platform = ${com.esp32_platform} platform = ${com.esp32_platform}
board = esp32dev board = esp32dev
board_build.partitions = min_spiffs.csv
lib_deps = lib_deps =
${com-esp32.lib_deps} ${com-esp32.lib_deps}
${libraries.esppilight} ${libraries.esppilight}
@@ -653,7 +654,6 @@ build_flags =
; *** OpenMQTTGateway Config *** ; *** OpenMQTTGateway Config ***
;'-UZmqttDiscovery' ; disables MQTT Discovery ;'-UZmqttDiscovery' ; disables MQTT Discovery
'-DvalueAsATopic=true' ; MQTT topic includes model and device '-DvalueAsATopic=true' ; MQTT topic includes model and device
'-DLOG_LEVEL=LOG_LEVEL_TRACE'
'-DGateway_Name="OMG_rtl_433_ESP"' '-DGateway_Name="OMG_rtl_433_ESP"'
; *** OpenMQTTGateway Modules *** ; *** OpenMQTTGateway Modules ***
'-DZgatewayRTL_433="rtl_433"' '-DZgatewayRTL_433="rtl_433"'
@@ -728,6 +728,7 @@ board_build.partitions = min_spiffs.csv
lib_deps = lib_deps =
${com-esp32.lib_deps} ${com-esp32.lib_deps}
${libraries.rtl_433_ESP} ${libraries.rtl_433_ESP}
${libraries.smartrc-cc1101-driver-lib}
build_flags = build_flags =
${com-esp32.build_flags} ${com-esp32.build_flags}
; *** OpenMQTTGateway Config *** ; *** OpenMQTTGateway Config ***
@@ -787,6 +788,40 @@ build_flags =
; '-DDISPLAY_BRIGHTNESS=80' ; '-DDISPLAY_BRIGHTNESS=80'
; '-DDISPLAY_METRIC=false' ; '-DDISPLAY_METRIC=false'
custom_description = Gateway using RTL_433_ESP and RadioLib custom_description = Gateway using RTL_433_ESP and RadioLib
custom_hardware = ESP32 HELTEC LORA32 V2
[env:heltec-rtl_433-fsk]
platform = ${com.esp32_platform}
board = heltec_wifi_lora_32_V2
; ~/.platformio/packages/framework-arduinoespressif32/variants/.../pins_arduino.h
board_build.partitions = min_spiffs.csv
lib_deps =
${com-esp32.lib_deps}
${libraries.ssd1306}
${libraries.rtl_433_ESP}
build_flags =
${com-esp32.build_flags}
; *** OpenMQTTGateway Config ***
;'-UZmqttDiscovery' ; disables MQTT Discovery
'-DvalueAsATopic=true' ; MQTT topic includes model and device
'-DGateway_Name="OMG_heltec_rtl_433_ESP"'
'-DOOK_MODULATION=false' ; FSK modulation activated
'-DRF_FREQUENCY=915'
;-DRF_FREQUENCY=868.300'
;-DRF_FREQUENCY=433.9'
; *** OpenMQTTGateway Modules ***
'-DZgatewayRTL_433="rtl_433"'
'-DZradioSX127x="SX127x"'
; *** ssd1306 Display Options ***
'-DZdisplaySSD1306="HELTEC_SSD1306"'
; '-DLOG_TO_OLED=false' ; Enable log to OLED
; '-DJSON_TO_OLED=true'
; '-DLOG_LEVEL_OLED=LOG_LEVEL_NOTICE'
; '-DDISPLAY_IDLE_LOGO=false'
; '-DDISPLAY_BRIGHTNESS=80'
; '-DDISPLAY_METRIC=false'
custom_description = Gateway using RTL_433_ESP and RadioLib with FSK modulation (beta)
custom_hardware = ESP32 HELTEC LORA32 V2
[env:heltec-ble] [env:heltec-ble]
platform = ${com.esp32_platform} platform = ${com.esp32_platform}
@@ -810,6 +845,7 @@ build_flags =
; '-DDISPLAY_BRIGHTNESS=80' ; '-DDISPLAY_BRIGHTNESS=80'
; '-DDISPLAY_METRIC=false' ; '-DDISPLAY_METRIC=false'
custom_description = Heltec BLE gateway with adaptive scanning activated, automatically adapts the scan parameters depending on your devices custom_description = Heltec BLE gateway with adaptive scanning activated, automatically adapts the scan parameters depending on your devices
custom_hardware = ESP32 HELTEC LORA32 V2
[env:lilygo-rtl_433] [env:lilygo-rtl_433]
platform = ${com.esp32_platform} platform = ${com.esp32_platform}
@@ -840,6 +876,39 @@ build_flags =
custom_description = For ESP32, Gateway using RTL_433_ESP and RadioLib custom_description = For ESP32, Gateway using RTL_433_ESP and RadioLib
custom_hardware = ESP32 LILYGO LoRa32 V2.1 custom_hardware = ESP32 LILYGO LoRa32 V2.1
[env:lilygo-rtl_433-fsk]
platform = ${com.esp32_platform}
board = ttgo-lora32-v21
; ~/.platformio/packages/framework-arduinoespressif32/variants/.../pins_arduino.h
board_build.partitions = min_spiffs.csv
lib_deps =
${com-esp32.lib_deps}
${libraries.ssd1306}
${libraries.rtl_433_ESP}
build_flags =
${com-esp32.build_flags}
; *** OpenMQTTGateway Config ***
;'-UZmqttDiscovery' ; disables MQTT Discovery
'-DvalueAsATopic=true' ; MQTT topic includes model and device
'-DGateway_Name="OMG_lilygo_rtl_433_ESP"'
'-DOOK_MODULATION=false' ; FSK modulation activated
'-DRF_FREQUENCY=915'
;-DRF_FREQUENCY=868.300'
;-DRF_FREQUENCY=433.9'
; *** OpenMQTTGateway Modules ***
'-DZgatewayRTL_433="rtl_433"'
'-DZradioSX127x="SX127x"'
; *** ssd1306 Display Options ***
'-DZdisplaySSD1306="LilyGo_SSD1306"'
; '-DLOG_TO_OLED=true' ; Enable log to OLED
; '-DJSON_TO_OLED=true'
; '-DLOG_LEVEL_OLED=LOG_LEVEL_NOTICE'
; '-DDISPLAY_IDLE_LOGO=false'
; '-DDISPLAY_BRIGHTNESS=80'
; '-DDISPLAY_METRIC=false'
custom_description = For ESP32, Gateway using RTL_433_ESP and RadioLib with FSK modulation (beta)
custom_hardware = ESP32 LILYGO LoRa32 V2.1
[env:lilygo-ble] [env:lilygo-ble]
platform = ${com.esp32_platform} platform = ${com.esp32_platform}
board = ttgo-lora32-v21 board = ttgo-lora32-v21
@@ -873,7 +942,6 @@ lib_deps =
${libraries.rc-switch} ${libraries.rc-switch}
${libraries.smartrc-cc1101-driver-lib} ${libraries.smartrc-cc1101-driver-lib}
${libraries.rtl_433_ESP} ${libraries.rtl_433_ESP}
${libraries.esppilight}
${libraries.newremoteswitch} ${libraries.newremoteswitch}
build_flags = build_flags =
${com-esp32.build_flags} ${com-esp32.build_flags}
@@ -883,7 +951,6 @@ build_flags =
'-DZradioCC1101="CC1101"' '-DZradioCC1101="CC1101"'
'-DGateway_Name="OMG_multi_receiver"' '-DGateway_Name="OMG_multi_receiver"'
'-DvalueAsATopic=true' ; MQTT topic includes model and device (rtl_433) or protocol and id (RF and PiLight) '-DvalueAsATopic=true' ; MQTT topic includes model and device (rtl_433) or protocol and id (RF and PiLight)
; '-DDEFAULT_RECEIVER=1' ; Default receiver to enable on startup
; *** RF Module Options *** ; *** RF Module Options ***
'-DRF_CC1101="CC1101"' ; CC1101 Transceiver Module '-DRF_CC1101="CC1101"' ; CC1101 Transceiver Module
'-DRF_MODULE_CS=5' ; pin to be used as chip select '-DRF_MODULE_CS=5' ; pin to be used as chip select
@@ -900,7 +967,6 @@ lib_deps =
${com-esp32.lib_deps} ${com-esp32.lib_deps}
${libraries.rc-switch} ${libraries.rc-switch}
${libraries.smartrc-cc1101-driver-lib} ${libraries.smartrc-cc1101-driver-lib}
${libraries.rtl_433_ESP}
${libraries.esppilight} ${libraries.esppilight}
${libraries.newremoteswitch} ${libraries.newremoteswitch}
build_flags = build_flags =
@@ -911,7 +977,6 @@ build_flags =
'-DZradioCC1101="CC1101"' '-DZradioCC1101="CC1101"'
'-DGateway_Name="OMG_multi_receiver"' '-DGateway_Name="OMG_multi_receiver"'
'-DvalueAsATopic=true' ; MQTT topic includes model and device (rtl_433) or protocol and id (RF and PiLight) '-DvalueAsATopic=true' ; MQTT topic includes model and device (rtl_433) or protocol and id (RF and PiLight)
; '-DDEFAULT_RECEIVER=1' ; Default receiver to enable on startup
; *** RF Module Options *** ; *** RF Module Options ***
'-DRF_CC1101="CC1101"' ; CC1101 Transceiver Module '-DRF_CC1101="CC1101"' ; CC1101 Transceiver Module
'-DRF_MODULE_CS=5' ; pin to be used as chip select '-DRF_MODULE_CS=5' ; pin to be used as chip select
@@ -920,7 +985,6 @@ build_flags =
; '-DRF_MODULE_INIT_STATUS=true' ; Display transceiver config during startup ; '-DRF_MODULE_INIT_STATUS=true' ; Display transceiver config during startup
custom_description = Multi RF library with the possibility to switch between ESPilight, NewRemoteSwitch and RCSwitch, need CC1101 custom_description = Multi RF library with the possibility to switch between ESPilight, NewRemoteSwitch and RCSwitch, need CC1101
[env:tinypico-ble] [env:tinypico-ble]
platform = ${com.esp32_platform} platform = ${com.esp32_platform}
board = tinypico board = tinypico
+8 -9
View File
@@ -34,9 +34,6 @@
# endif # endif
void setupSomfy() { void setupSomfy() {
# ifdef ZradioCC1101 //using with CC1101
ELECHOUSE_cc1101.Init();
# endif
pinMode(RF_EMITTER_GPIO, OUTPUT); pinMode(RF_EMITTER_GPIO, OUTPUT);
digitalWrite(RF_EMITTER_GPIO, LOW); digitalWrite(RF_EMITTER_GPIO, LOW);
@@ -54,10 +51,13 @@ void setupSomfy() {
# if jsonReceiving # if jsonReceiving
void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) { void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) {
if (cmpToMainTopic(topicOri, subjectMQTTtoSomfy)) { if (cmpToMainTopic(topicOri, subjectMQTTtoSomfy)) {
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY_SOMFY);
# endif
Log.trace(F("MQTTtoSomfy json data analysis" CR)); 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"]; const int remoteIndex = jsonData["remote"];
if (remoteIndex >= SOMFY_REMOTE_NUM) { if (remoteIndex >= SOMFY_REMOTE_NUM) {
@@ -72,9 +72,8 @@ void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) {
EEPROMRollingCodeStorage rollingCodeStorage(EEPROM_ADDRESS_START + remoteIndex * 2); EEPROMRollingCodeStorage rollingCodeStorage(EEPROM_ADDRESS_START + remoteIndex * 2);
SomfyRemote somfyRemote(RF_EMITTER_GPIO, somfyRemotes[remoteIndex], &rollingCodeStorage); SomfyRemote somfyRemote(RF_EMITTER_GPIO, somfyRemotes[remoteIndex], &rollingCodeStorage);
somfyRemote.sendCommand(command, repeat); somfyRemote.sendCommand(command, repeat);
# ifdef ZradioCC1101 initCC1101();
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on enableActiveReceiver();
# endif
} }
} }
# endif # 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 # 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() { void savePilightConfig() {
Log.trace(F("saving Pilight config" CR)); Log.trace(F("saving Pilight config" CR));
DynamicJsonDocument json(4096); DynamicJsonDocument json(4096);
@@ -211,10 +196,19 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
} }
} else if (cmpToMainTopic(topicOri, subjectMQTTtoPilight)) { } else if (cmpToMainTopic(topicOri, subjectMQTTtoPilight)) {
const char* message = Pilightdata["message"]; const char* message = Pilightdata["message"];
Log.notice(F("MQTTtoPilight message: %s" CR), message);
const char* protocol = Pilightdata["protocol"]; const char* protocol = Pilightdata["protocol"];
Log.notice(F("MQTTtoPilight protocol: %s" CR), protocol);
const char* raw = Pilightdata["raw"]; const char* raw = Pilightdata["raw"];
float tempMhz = Pilightdata["mhz"]; float txFrequency = Pilightdata["frequency"] | RFConfig.frequency;
bool success = false; 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) { if (raw) {
uint16_t codes[MAXPULSESTREAMLENGTH]; uint16_t codes[MAXPULSESTREAMLENGTH];
int repeats = rf.stringToRepeats(raw); int repeats = rf.stringToRepeats(raw);
@@ -231,13 +225,6 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
} }
int msgLength = rf.stringToPulseTrain(raw, codes, MAXPULSESTREAMLENGTH); int msgLength = rf.stringToPulseTrain(raw, codes, MAXPULSESTREAMLENGTH);
if (msgLength > 0) { 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); rf.sendPulseTrain(codes, msgLength, repeats);
Log.notice(F("MQTTtoPilight raw ok" CR)); Log.notice(F("MQTTtoPilight raw ok" CR));
success = true; success = true;
@@ -262,18 +249,11 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
} }
if (message && protocol) { if (message && protocol) {
Log.trace(F("MQTTtoPilight msg & protocol ok" CR)); 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); int msgLength = rf.send(protocol, message);
if (msgLength > 0) { if (msgLength > 0) {
Log.trace(F("Adv data MQTTtoPilight push state via PilighttoMQTT" CR)); Log.trace(F("Adv data MQTTtoPilight push state via PilighttoMQTT" CR));
Pilightdata["origin"] = subjectGTWPilighttoMQTT; // Acknowledgement
handleJsonEnqueue(Pilightdata); pub(subjectGTWPilighttoMQTT, message);
success = true; success = true;
} else { } else {
switch (msgLength) { switch (msgLength) {
@@ -294,26 +274,11 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
} }
} }
} }
if (Pilightdata.containsKey("active")) { if (!success) {
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 {
pub(subjectGTWPilighttoMQTT, "{\"Status\": \"Error\"}"); // Fail feedback pub(subjectGTWPilighttoMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
Log.error(F("MQTTtoPilight Fail json" CR)); Log.error(F("MQTTtoPilight Fail json" CR));
} }
enableActiveReceiver(false); enableActiveReceiver();
} }
} }
@@ -324,25 +289,13 @@ extern void disablePilightReceive() {
}; };
extern void enablePilightReceive() { extern void enablePilightReceive() {
# ifdef ZradioCC1101 Log.notice(F("Switching to Pilight Receiver: %F" CR), RFConfig.frequency);
Log.notice(F("Switching to Pilight Receiver: %F" CR), receiveMhz); Log.notice(F("RF_EMITTER_GPIO: %d " CR), RF_EMITTER_GPIO);
# else Log.notice(F("RF_RECEIVER_GPIO: %d " CR), RF_RECEIVER_GPIO);
Log.notice(F("Switching to Pilight Receiver" CR)); Log.trace(F("ZgatewayPilight command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoPilight);
# endif
# ifdef ZgatewayRF initCC1101();
disableRFReceive();
# endif
# ifdef ZgatewayRF2
disableRF2Receive();
# endif
# ifdef ZgatewayRTL_433
disableRTLreceive();
# endif
# ifdef ZradioCC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
rf.setCallback(pilightCallback); rf.setCallback(pilightCallback);
# ifdef Pilight_rawEnabled # ifdef Pilight_rawEnabled
if (pilightRawEnabled) { 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(); 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(); rf.enableReceiver();
loadPilightConfig(); loadPilightConfig();
Log.trace(F("ZgatewayPilight setup done " CR));
}; };
#endif #endif
+25 -89
View File
@@ -106,31 +106,6 @@ void RFtoMQTTdiscovery(SIGNAL_SIZE_UL_ULL MQTTvalue) {
} }
# endif # 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() { void RFtoMQTT() {
if (mySwitch.available()) { if (mySwitch.available()) {
StaticJsonDocument<JSON_MSG_BUFFER> RFdataBuffer; StaticJsonDocument<JSON_MSG_BUFFER> RFdataBuffer;
@@ -161,7 +136,7 @@ void RFtoMQTT() {
RFdata["raw"] = rawDump; RFdata["raw"] = rawDump;
# endif # endif
# ifdef ZradioCC1101 // set Receive off and Transmitt on # ifdef ZradioCC1101 // set Receive off and Transmitt on
RFdata["mhz"] = receiveMhz; RFdata["frequency"] = RFConfig.frequency;
# endif # endif
mySwitch.resetAvailable(); mySwitch.resetAvailable();
@@ -187,9 +162,9 @@ void RFtoMQTT() {
# if simpleReceiving # if simpleReceiving
void MQTTtoRF(char* topicOri, char* datacallback) { void MQTTtoRF(char* topicOri, char* datacallback) {
# ifdef ZradioCC1101 // set Receive off and Transmitt on # ifdef ZradioCC1101 // set Receive off and Transmitt on
disableActiveReceiver(); disableCurrentReceiver();
ELECHOUSE_cc1101.SetTx(receiveMhz); ELECHOUSE_cc1101.SetTx(RFConfig.frequency);
Log.notice(F("Transmit mhz: %F" CR), receiveMhz); Log.notice(F("Transmit frequency: %F" CR), RFConfig.frequency);
# endif # endif
mySwitch.disableReceive(); mySwitch.disableReceive();
mySwitch.enableTransmit(RF_EMITTER_GPIO); 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 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 # ifdef ZradioCC1101 // set Receive on and Transmitt off
ELECHOUSE_cc1101.SetRx(receiveMhz); ELECHOUSE_cc1101.SetRx(RFConfig.frequency);
mySwitch.disableTransmit(); mySwitch.disableTransmit();
mySwitch.enableReceive(RF_RECEIVER_GPIO); mySwitch.enableReceive(RF_RECEIVER_GPIO);
# endif # 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 Protocol:%d" CR), valuePRT);
Log.notice(F("RF Pulse Lgth: %d" CR), valuePLSL); Log.notice(F("RF Pulse Lgth: %d" CR), valuePLSL);
Log.notice(F("Bits nb: %d" CR), valueBITS); Log.notice(F("Bits nb: %d" CR), valueBITS);
# ifdef ZradioCC1101 // set Receive off and Transmitt on # ifdef ZradioCC1101
disableActiveReceiver(); disableCurrentReceiver();
initCC1101();
int txPower = RFdata["txpower"] | RF_CC1101_TXPOWER; int txPower = RFdata["txpower"] | RF_CC1101_TXPOWER;
ELECHOUSE_cc1101.setPA((int)txPower); ELECHOUSE_cc1101.setPA((int)txPower);
Log.notice(F("CC1101 TX Power: %d" CR), txPower); Log.notice(F("CC1101 TX Power: %d" CR), txPower);
float txFrequency = RFdata["frequency"] | RFConfig.frequency;
float trMhz = RFdata["mhz"] | CC1101_FREQUENCY; ELECHOUSE_cc1101.SetTx(txFrequency);
if (validFrequency((int)trMhz)) { Log.notice(F("Transmit frequency: %F" CR), txFrequency);
ELECHOUSE_cc1101.SetTx(trMhz);
Log.notice(F("Transmit mhz: %F" CR), trMhz);
}
# endif # endif
mySwitch.disableReceive();
mySwitch.enableTransmit(RF_EMITTER_GPIO); mySwitch.enableTransmit(RF_EMITTER_GPIO);
mySwitch.setRepeatTransmit(valueRPT); mySwitch.setRepeatTransmit(valueRPT);
mySwitch.setProtocol(valuePRT, valuePLSL); 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 // 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); pub(subjectGTWRFtoMQTT, RFdata);
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT); // Restore the default value 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"]; enableActiveReceiver();
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);
} }
} }
# endif # endif
@@ -317,36 +265,24 @@ int receiveInterupt = -1;
void disableRFReceive() { void disableRFReceive() {
Log.trace(F("disableRFReceive %d" CR), receiveInterupt); Log.trace(F("disableRFReceive %d" CR), receiveInterupt);
if (receiveInterupt != -1) {
receiveInterupt = -1;
mySwitch.disableReceive(); mySwitch.disableReceive();
}
} }
void enableRFReceive() { void enableRFReceive() {
# ifdef ZradioCC1101 Log.notice(F("Enable RF Receiver: %FMhz" CR), RFConfig.frequency);
Log.notice(F("Switching to RF Receiver: %F" CR), receiveMhz); //RF init parameters
# else Log.notice(F("RF_EMITTER_GPIO: %d " CR), RF_EMITTER_GPIO);
Log.notice(F("Switching to RF Receiver" CR)); Log.notice(F("RF_RECEIVER_GPIO: %d " CR), RF_RECEIVER_GPIO);
# 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 # ifdef RF_DISABLE_TRANSMIT
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz);
# endif
mySwitch.disableTransmit(); mySwitch.disableTransmit();
# else
mySwitch.enableTransmit(RF_EMITTER_GPIO);
# endif
receiveInterupt = RF_RECEIVER_GPIO; 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 #endif
+13 -62
View File
@@ -55,21 +55,6 @@ struct RF2rxd {
RF2rxd rf2rd; 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 # ifdef ZmqttDiscovery
//Register for autodiscover in Home Assistant //Register for autodiscover in Home Assistant
void RF2toMQTTdiscovery(JsonObject& data) { void RF2toMQTTdiscovery(JsonObject& data) {
@@ -148,13 +133,9 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
# if simpleReceiving # if simpleReceiving
void MQTTtoRF2(char* topicOri, char* datacallback) { void MQTTtoRF2(char* topicOri, char* datacallback) {
# ifdef ZradioCC1101
NewRemoteReceiver::disable(); NewRemoteReceiver::disable();
disableActiveReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT); pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on initCC1101();
# endif
// RF DATA ANALYSIS // RF DATA ANALYSIS
//We look into the subject to see if a special RF protocol is defined //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 # ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on ELECHOUSE_cc1101.SetRx(RFConfig.frequency); // set Receive on
NewRemoteReceiver::enable(); NewRemoteReceiver::enable();
# endif # endif
} }
@@ -267,13 +248,9 @@ void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding
int boolSWITCHTYPE = RF2data["switchType"] | 99; int boolSWITCHTYPE = RF2data["switchType"] | 99;
bool success = false; bool success = false;
if (boolSWITCHTYPE != 99) { if (boolSWITCHTYPE != 99) {
# ifdef ZradioCC1101
NewRemoteReceiver::disable(); NewRemoteReceiver::disable();
disableActiveReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT); pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on initCC1101();
# endif
Log.trace(F("MQTTtoRF2 switch type ok" CR)); Log.trace(F("MQTTtoRF2 switch type ok" CR));
bool isDimCommand = boolSWITCHTYPE == 2; bool isDimCommand = boolSWITCHTYPE == 2;
unsigned long valueCODE = RF2data["address"]; unsigned long valueCODE = RF2data["address"];
@@ -311,19 +288,6 @@ void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding
success = true; 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) { 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 // 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); pub(subjectRF2toMQTT, RF2data);
@@ -333,39 +297,26 @@ void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding
# endif # endif
Log.error(F("MQTTtoRF2 failed json read" CR)); Log.error(F("MQTTtoRF2 failed json read" CR));
} }
enableActiveReceiver(false); enableActiveReceiver();
} }
} }
# endif # endif
void disableRF2Receive() { void disableRF2Receive() {
Log.trace(F("disableRF2Receive" CR)); Log.trace(F("disableRF2Receive" CR));
NewRemoteReceiver::deinit(); NewRemoteReceiver::disable();
NewRemoteReceiver::init(-1, 2, rf2Callback); // mark _interupt with -1
NewRemoteReceiver::deinit();
} }
void enableRF2Receive() { void enableRF2Receive() {
# ifdef ZradioCC1101 Log.trace(F("enableRF2Receive" CR));
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
NewRemoteReceiver::init(RF_RECEIVER_GPIO, 2, rf2Callback); 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 #endif
+3 -65
View File
@@ -40,8 +40,6 @@
char messageBuffer[JSON_MSG_BUFFER]; char messageBuffer[JSON_MSG_BUFFER];
rtl_433_ESP rtl_433;
# ifdef ZmqttDiscovery # ifdef ZmqttDiscovery
SemaphoreHandle_t semaphorecreateOrUpdateDeviceRTL_433; SemaphoreHandle_t semaphorecreateOrUpdateDeviceRTL_433;
std::vector<RTL_433device*> RTL_433devices; std::vector<RTL_433device*> RTL_433devices;
@@ -273,7 +271,7 @@ void setupRTL_433() {
semaphorecreateOrUpdateDeviceRTL_433 = xSemaphoreCreateBinary(); semaphorecreateOrUpdateDeviceRTL_433 = xSemaphoreCreateBinary();
xSemaphoreGive(semaphorecreateOrUpdateDeviceRTL_433); xSemaphoreGive(semaphorecreateOrUpdateDeviceRTL_433);
# endif # 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)); Log.notice(F("ZgatewayRTL_433 setup done " CR));
} }
@@ -281,69 +279,9 @@ void RTL_433Loop() {
rtl_433.loop(); 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() { extern void enableRTLreceive() {
Log.notice(F("Switching to RTL_433 Receiver: %FMhz" CR), receiveMhz); Log.notice(F("Enable RTL_433 Receiver: %FMhz" CR), RFConfig.frequency);
# ifdef ZgatewayRF rtl_433.initReceiver(RF_MODULE_RECEIVER_GPIO, RFConfig.frequency);
disableRFReceive();
# endif
# ifdef ZgatewayRF2
disableRF2Receive();
# endif
# ifdef ZgatewayPilight
disablePilightReceive();
# endif
rtl_433.initReceiver(RF_MODULE_RECEIVER_GPIO, receiveMhz);
rtl_433.enableReceiver(); rtl_433.enableReceiver();
} }
+141 -6
View File
@@ -947,54 +947,72 @@ void handleLA() {
if (server.hasArg("save")) { if (server.hasArg("save")) {
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer; StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject WEBtoLORA = jsonBuffer.to<JsonObject>(); JsonObject WEBtoLORA = jsonBuffer.to<JsonObject>();
bool update = false;
if (server.hasArg("lf")) { if (server.hasArg("lf")) {
WEBtoLORA["frequency"] = server.arg("lf"); WEBtoLORA["frequency"] = server.arg("lf");
update = true;
} }
if (server.hasArg("lt")) { if (server.hasArg("lt")) {
WEBtoLORA["txpower"] = server.arg("lt"); WEBtoLORA["txpower"] = server.arg("lt");
update = true;
} }
if (server.hasArg("ls")) { if (server.hasArg("ls")) {
WEBtoLORA["spreadingfactor"] = server.arg("ls"); WEBtoLORA["spreadingfactor"] = server.arg("ls");
update = true;
} }
if (server.hasArg("lb")) { if (server.hasArg("lb")) {
WEBtoLORA["signalbandwidth"] = server.arg("lb"); WEBtoLORA["signalbandwidth"] = server.arg("lb");
update = true;
} }
if (server.hasArg("lc")) { if (server.hasArg("lc")) {
WEBtoLORA["codingrate"] = server.arg("lc"); WEBtoLORA["codingrate"] = server.arg("lc");
update = true;
} }
if (server.hasArg("ll")) { if (server.hasArg("ll")) {
WEBtoLORA["preamblelength"] = server.arg("ll"); WEBtoLORA["preamblelength"] = server.arg("ll");
update = true;
} }
if (server.hasArg("lw")) { if (server.hasArg("lw")) {
WEBtoLORA["syncword"] = server.arg("lw"); WEBtoLORA["syncword"] = server.arg("lw");
update = true;
} }
if (server.hasArg("lr")) { if (server.hasArg("lr")) {
WEBtoLORA["enablecrc"] = server.arg("lr"); WEBtoLORA["enablecrc"] = server.arg("lr");
update = true;
} else { } else {
WEBtoLORA["enablecrc"] = false; WEBtoLORA["enablecrc"] = false;
update = true;
} }
if (server.hasArg("li")) { if (server.hasArg("li")) {
WEBtoLORA["invertiq"] = server.arg("li"); WEBtoLORA["invertiq"] = server.arg("li");
update = true;
} else { } else {
WEBtoLORA["invertiq"] = false; WEBtoLORA["invertiq"] = false;
update = true;
} }
if (server.hasArg("ok")) { if (server.hasArg("ok")) {
WEBtoLORA["onlyknown"] = server.arg("ok"); WEBtoLORA["onlyknown"] = server.arg("ok");
update = true;
} else { } else {
WEBtoLORA["onlyknown"] = false; WEBtoLORA["onlyknown"] = false;
update = true;
} }
if (update) {
Log.notice(F("[WebUI] Save data" CR));
WEBtoLORA["save"] = true;
LORAConfig_fromJson(WEBtoLORA); LORAConfig_fromJson(WEBtoLORA);
stateLORAMeasures();
Log.trace(F("[WebUI] LORAConfig end" CR));
}
} }
} }
char jsonChar[100]; char jsonChar[100];
@@ -1056,8 +1074,121 @@ void handleLA() {
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION); snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
response += String(buffer); response += String(buffer);
server.send(200, "text/html", response); 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 # endif
@@ -1228,6 +1359,10 @@ void handleIN() {
# if defined(ZgatewayLORA) # if defined(ZgatewayLORA)
informationDisplay += "1<BR>LORA}2}1"; informationDisplay += "1<BR>LORA}2}1";
informationDisplay += stateLORAMeasures(); informationDisplay += stateLORAMeasures();
# endif
# if defined(ZgatewayRF)
informationDisplay += "1<BR>RF}2}1";
informationDisplay += stateRFMeasures();
# endif # endif
informationDisplay += "1<BR>WebUI}2}1"; informationDisplay += "1<BR>WebUI}2}1";
informationDisplay += stateWebUIStatus(); informationDisplay += stateWebUIStatus();
@@ -1494,6 +1629,8 @@ void WebUISetup() {
server.on("/wu", handleWU); // Configure WebUI server.on("/wu", handleWU); // Configure WebUI
# ifdef ZgatewayLORA # ifdef ZgatewayLORA
server.on("/la", handleLA); // Configure LORA 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 # endif
# if defined(ZgatewayCloud) # if defined(ZgatewayCloud)
server.on("/cl", handleCL); // Configure Cloud 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); // WEBUI_TRACE_LOG(F("[ webUIPubPrint ] switch %s " CR), message->title);
switch (webUIHash(message->title)) { switch (webUIHash(message->title)) {
case webUIHash("SYStoMQTT"): { 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 // Line 1
if (data["version"]) { if (data["version"]) {
+34 -162
View File
@@ -29,10 +29,6 @@
#include <Arduino.h> #include <Arduino.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#if defined(ESP8266) || defined(ESP32)
# include <EEPROM.h>
#endif
#ifdef ZgatewayRF #ifdef ZgatewayRF
extern void setupRF(); extern void setupRF();
extern void RFtoMQTT(); extern void RFtoMQTT();
@@ -42,7 +38,6 @@ extern void disableRFReceive();
extern void enableRFReceive(); extern void enableRFReceive();
#endif #endif
#ifdef ZgatewayRF2 #ifdef ZgatewayRF2
extern void setupRF2();
extern void RF2toMQTT(); extern void RF2toMQTT();
extern void MQTTtoRF2(char* topicOri, char* datacallback); extern void MQTTtoRF2(char* topicOri, char* datacallback);
extern void MQTTtoRF2(char* topicOri, JsonObject& RFdata); extern void MQTTtoRF2(char* topicOri, JsonObject& RFdata);
@@ -58,9 +53,11 @@ extern void disablePilightReceive();
extern void enablePilightReceive(); extern void enablePilightReceive();
#endif #endif
#ifdef ZgatewayRTL_433 #ifdef ZgatewayRTL_433
# include <rtl_433_ESP.h>
rtl_433_ESP rtl_433;
extern void RTL_433Loop(); extern void RTL_433Loop();
extern void setupRTL_433(); extern void setupRTL_433();
extern void MQTTtoRTL_433(char* topicOri, JsonObject& RTLdata);
extern void enableRTLreceive(); extern void enableRTLreceive();
extern void disableRTLreceive(); extern void disableRTLreceive();
extern int getRTLrssiThreshold(); extern int getRTLrssiThreshold();
@@ -136,6 +133,7 @@ const char parameters[40][4][24] = {
//433Mhz MQTT Subjects and keys //433Mhz MQTT Subjects and keys
#define subjectMQTTtoRF "/commands/MQTTto433" #define subjectMQTTtoRF "/commands/MQTTto433"
#define subjectRFtoMQTT "/433toMQTT" #define subjectRFtoMQTT "/433toMQTT"
#define subjectcommonRFtoMQTT "/RFtoMQTT"
#define subjectGTWRFtoMQTT "/433toMQTT" #define subjectGTWRFtoMQTT "/433toMQTT"
#define RFprotocolKey "433_" // protocol will be defined if a subject contains RFprotocolKey followed by a value of 1 digit #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 RFbitsKey "RFBITS_" // bits will be defined if a subject contains RFbitsKey followed by a value of 2 digits
@@ -171,18 +169,39 @@ const char parameters[40][4][24] = {
/*-------------------RTL_433 topics & parameters----------------------*/ /*-------------------RTL_433 topics & parameters----------------------*/
//433Mhz RTL_433 MQTT Subjects and keys //433Mhz RTL_433 MQTT Subjects and keys
#define subjectMQTTtoRTL_433 "/commands/MQTTtoRTL_433" #define subjectMQTTtoRFset "/commands/MQTTtoRF/config"
#define subjectRTL_433toMQTT "/RTL_433toMQTT" #define subjectRTL_433toMQTT "/RTL_433toMQTT"
/*-------------------CC1101 frequency----------------------*/ /*-------------------RF frequency----------------------*/
//Match frequency to the hardware version of the radio if ZradioCC1101 is used. //Match frequency to the hardware version of the radio used.
#ifndef CC1101_FREQUENCY #ifndef RF_FREQUENCY
# define CC1101_FREQUENCY 433.92 # define RF_FREQUENCY 433.92
#endif
// Allow ZGatewayRF Module to change receive frequency of CC1101 Transceiver module
#if defined(ZradioCC1101) || defined(ZradioSX127x)
float receiveMhz = CC1101_FREQUENCY;
#endif #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----------------------*/ /*-------------------CC1101 DefaultTXPower----------------------*/
//Adjust the default TX-Power for sending radio if ZradioCC1101 is used. //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! //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
#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 #endif
+1 -1
View File
@@ -40,6 +40,6 @@ const uint32_t somfyRemotes[SOMFY_REMOTE_NUM] = {0x5184c8};
#define subjectMQTTtoSomfy "/commands/MQTTtoSomfy" #define subjectMQTTtoSomfy "/commands/MQTTtoSomfy"
/*-------------------INTERNAL DEFINITIONS----------------------*/ /*-------------------INTERNAL DEFINITIONS----------------------*/
#define CC1101_FREQUENCY_SOMFY 433.42 #define RF_FREQUENCY_SOMFY 433.42
#endif #endif
+25
View File
@@ -57,6 +57,8 @@
#define configure_5 "<p><form action='lo' method='get'><button>Configure Logging</button></form></p>" #define configure_5 "<p><form action='lo' method='get'><button>Configure Logging</button></form></p>"
#ifdef ZgatewayLORA #ifdef ZgatewayLORA
# define configure_6 "<p><form action='la' method='get'><button>Configure LORA</button></form></p>" # 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 #else
# define configure_6 # define configure_6
#endif #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_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 const char config_lora_body[] = body_header
"<fieldset class=\"set1\">" "<fieldset class=\"set1\">"
"<legend><span><b>Configure LORA</b></span></legend>" "<legend><span><b>Configure LORA</b></span></legend>"
+16 -34
View File
@@ -1189,7 +1189,11 @@ void setup() {
client.setCallback(callback); client.setCallback(callback);
delay(1500); delay(1500);
#if defined(ZgatewayRF) || defined(ZgatewayPilight) || defined(ZgatewayRTL_433) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
# ifndef ARDUINO_AVR_UNO
setupCommonRF();
# endif
#endif
#ifdef ZsensorBME280 #ifdef ZsensorBME280
setupZsensorBME280(); setupZsensorBME280();
modules.add(ZsensorBME280); modules.add(ZsensorBME280);
@@ -1235,12 +1239,10 @@ void setup() {
modules.add(ZgatewayLORA); modules.add(ZgatewayLORA);
#endif #endif
#ifdef ZgatewayRF #ifdef ZgatewayRF
setupRF();
modules.add(ZgatewayRF); modules.add(ZgatewayRF);
# define ACTIVE_RECEIVER ACTIVE_RF # define ACTIVE_RECEIVER ACTIVE_RF
#endif #endif
#ifdef ZgatewayRF2 #ifdef ZgatewayRF2
setupRF2();
modules.add(ZgatewayRF2); modules.add(ZgatewayRF2);
# ifdef ACTIVE_RECEIVER # ifdef ACTIVE_RECEIVER
# undef ACTIVE_RECEIVER # undef ACTIVE_RECEIVER
@@ -1248,9 +1250,7 @@ void setup() {
# define ACTIVE_RECEIVER ACTIVE_RF2 # define ACTIVE_RECEIVER ACTIVE_RF2
#endif #endif
#ifdef ZgatewayPilight #ifdef ZgatewayPilight
setupPilight();
modules.add(ZgatewayPilight); modules.add(ZgatewayPilight);
disablePilightReceive();
# ifdef ACTIVE_RECEIVER # ifdef ACTIVE_RECEIVER
# undef ACTIVE_RECEIVER # undef ACTIVE_RECEIVER
# endif # endif
@@ -1305,6 +1305,10 @@ void setup() {
modules.add(ZactuatorPWM); modules.add(ZactuatorPWM);
#endif #endif
#ifdef ZactuatorSomfy #ifdef ZactuatorSomfy
# ifdef ACTIVE_RECEIVER
# undef ACTIVE_RECEIVER
# endif
# define ACTIVE_RECEIVER ACTIVE_NONE
setupSomfy(); setupSomfy();
modules.add(ZactuatorSomfy); modules.add(ZactuatorSomfy);
#endif #endif
@@ -1336,20 +1340,12 @@ void setup() {
setupSHTC3(); setupSHTC3();
#endif #endif
#ifdef ZgatewayRTL_433 #ifdef ZgatewayRTL_433
setupRTL_433();
modules.add(ZgatewayRTL_433);
# ifdef ACTIVE_RECEIVER # ifdef ACTIVE_RECEIVER
# undef ACTIVE_RECEIVER # undef ACTIVE_RECEIVER
# endif # endif
# define ACTIVE_RECEIVER ACTIVE_RTL # define ACTIVE_RECEIVER ACTIVE_RTL
#endif setupRTL_433();
#if defined(ZgatewayRTL_433) || defined(ZgatewayRF) || defined(ZgatewayPilight) || defined(ZgatewayRF2) modules.add(ZgatewayRTL_433);
# ifdef DEFAULT_RECEIVER // Allow defining of default receiver as a compiler directive
activeReceiver = DEFAULT_RECEIVER;
# else
activeReceiver = ACTIVE_RECEIVER;
# endif
enableActiveReceiver(true);
#endif #endif
Log.trace(F("mqtt_max_packet_size: %d" CR), mqtt_max_packet_size); Log.trace(F("mqtt_max_packet_size: %d" CR), mqtt_max_packet_size);
@@ -2084,6 +2080,9 @@ void loop() {
# ifdef ZgatewayLORA # ifdef ZgatewayLORA
stateLORAMeasures(); stateLORAMeasures();
# endif # endif
# if defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
stateRFMeasures();
# endif
# if defined(ZwebUI) && defined(ESP32) # if defined(ZwebUI) && defined(ESP32)
stateWebUIStatus(); stateWebUIStatus();
# endif # endif
@@ -2441,23 +2440,6 @@ String stateMeasures() {
SYSdata["m5batpower"] = (float)M5.Axp.GetBatPower(); SYSdata["m5batpower"] = (float)M5.Axp.GetBatPower();
SYSdata["m5batchargecurrent"] = (float)M5.Axp.GetBatChargeCurrent(); SYSdata["m5batchargecurrent"] = (float)M5.Axp.GetBatChargeCurrent();
SYSdata["m5apsvoltage"] = (float)M5.Axp.GetAPSVoltage(); 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 # endif
SYSdata["modules"] = modules; 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 #ifdef ZgatewayPilight // ZgatewayPilight is only defined with json publishing due to its numerous parameters
MQTTtoPilight(topicOri, jsondata); MQTTtoPilight(topicOri, jsondata);
#endif #endif
#ifdef ZgatewayRTL_433 // ZgatewayRTL_433 is only defined with json publishing due to its numerous parameters #if defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
MQTTtoRTL_433(topicOri, jsondata); MQTTtoRFset(topicOri, jsondata);
#endif #endif
#if jsonReceiving #if jsonReceiving
# ifdef ZgatewayLORA # ifdef ZgatewayLORA
+3 -1
View File
@@ -61,8 +61,10 @@ extra_configs =
;default_envs = esp32doitv1-aithinker-r01-sx1278 ;default_envs = esp32doitv1-aithinker-r01-sx1278
;default_envs = esp32dev-rtl_433 ;default_envs = esp32dev-rtl_433
;default_envs = heltec-rtl_433 ;default_envs = heltec-rtl_433
;default_envs = heltec-rtl_433-fsk
;default_envs = heltec-ble ;default_envs = heltec-ble
;default_envs = lilygo-rtl_433 ;default_envs = lilygo-rtl_433
;default_envs = lilygo-rtl_433-fsk
;default_envs = lilygo-ble ;default_envs = lilygo-ble
;default_envs = esp32dev-multi_receiver ;default_envs = esp32dev-multi_receiver
;default_envs = esp32dev-multi_receiver-pilight ;default_envs = esp32dev-multi_receiver-pilight
@@ -149,7 +151,7 @@ smartrc-cc1101-driver-lib = SmartRC-CC1101-Driver-Lib@2.5.7
stl = https://github.com/mike-matera/ArduinoSTL.git#7411816 stl = https://github.com/mike-matera/ArduinoSTL.git#7411816
shtc3 = https://github.com/sparkfun/SparkFun_SHTC3_Arduino_Library shtc3 = https://github.com/sparkfun/SparkFun_SHTC3_Arduino_Library
somfy_remote=Somfy_Remote_Lib@0.3.0 somfy_remote=Somfy_Remote_Lib@0.3.0
rtl_433_ESP = https://github.com/NorthernMan54/rtl_433_ESP.git#v0.3.0 rtl_433_ESP = https://github.com/NorthernMan54/rtl_433_ESP.git#v0.3.1
emodbus = miq19/eModbus@1.0.0 emodbus = miq19/eModbus@1.0.0
gfSunInverter = https://github.com/BlackSmith/GFSunInverter.git#v1.0.1 gfSunInverter = https://github.com/BlackSmith/GFSunInverter.git#v1.0.1
decoder = https://github.com/theengs/decoder.git#v1.6.3 decoder = https://github.com/theengs/decoder.git#v1.6.3