Skip to content

Commit

Permalink
[FSK] Add Lilygo Heltec environment with FSK modulation
Browse files Browse the repository at this point in the history
Enable RTL_433 frequency change with WebUI
Add FSK environment for Heltec and Lilygo
  • Loading branch information
1technophile committed Nov 28, 2023
1 parent 5421f0e commit fad5682
Show file tree
Hide file tree
Showing 15 changed files with 506 additions and 241 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ jobs:
- "esp32dev-rtl_433"
- "esp32doitv1-aithinker-r01-sx1278"
- "heltec-rtl_433"
- "heltec-rtl_433-fsk"
- "heltec-ble"
- "lilygo-rtl_433"
- "lilygo-rtl_433-fsk"
- "lilygo-ble"
- "esp32dev-multi_receiver"
- "esp32dev-multi_receiver-pilight"
Expand Down
10 changes: 5 additions & 5 deletions docs/use/rf.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,19 @@ 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
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 `frequency` 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}`
`home/OpenMQTTGateway/commands/MQTTtoRF {"frequency":315.026}`

### Change Signal RSSI Threshold Delta

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 {"rssiThreshold": 9}`

### Retrieve current status of receiver

`home/OpenMQTTGateway/commands/MQTTtoRTL_433 {"status":1}`
`home/OpenMQTTGateway/commands/MQTTtoRF {"status":1}`

```
{"model":"status",
Expand Down Expand Up @@ -184,7 +184,7 @@ Example:
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}'`
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoRF" -m '{"active":true}'`

### Status Messages

Expand Down
65 changes: 64 additions & 1 deletion environments.ini
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,38 @@ build_flags =
; '-DDISPLAY_BRIGHTNESS=80'
; '-DDISPLAY_METRIC=false'
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'
; *** 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
custom_hardware = ESP32 HELTEC LORA32 V2

[env:heltec-ble]
platform = ${com.esp32_platform}
Expand All @@ -810,6 +842,7 @@ build_flags =
; '-DDISPLAY_BRIGHTNESS=80'
; '-DDISPLAY_METRIC=false'
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]
platform = ${com.esp32_platform}
Expand Down Expand Up @@ -840,6 +873,37 @@ build_flags =
custom_description = For ESP32, Gateway using RTL_433_ESP and RadioLib
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=868.30'
; *** 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]
platform = ${com.esp32_platform}
board = ttgo-lora32-v21
Expand Down Expand Up @@ -920,7 +984,6 @@ build_flags =
; '-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


[env:tinypico-ble]
platform = ${com.esp32_platform}
board = tinypico
Expand Down
4 changes: 2 additions & 2 deletions main/ZactuatorSomfy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void setupSomfy() {
void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) {
if (cmpToMainTopic(topicOri, subjectMQTTtoSomfy)) {
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY_SOMFY);
ELECHOUSE_cc1101.SetTx(RF_FREQUENCY_SOMFY);
# endif
Log.trace(F("MQTTtoSomfy json data analysis" CR));

Expand All @@ -73,7 +73,7 @@ void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) {
SomfyRemote somfyRemote(RF_EMITTER_GPIO, somfyRemotes[remoteIndex], &rollingCodeStorage);
somfyRemote.sendCommand(command, repeat);
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
ELECHOUSE_cc1101.SetRx(RFConfig.frequency); // set Receive on
# endif
}
}
Expand Down
134 changes: 134 additions & 0 deletions main/ZcommonRF.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# include "User_config.h"

#if defined(ZgatewayRTL_433) || defined(ZgatewayPiLight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)

String stateRFMeasures() {
//Publish RTL_433 state
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject RFdata = jsonBuffer.to<JsonObject>();

#if defined(ZradioCC1101) || defined(ZradioSX127x)
RFdata["frequency"] = RFConfig.frequency;
# endif
RFdata["active"] = RFConfig.activeReceiver;

if (RFConfig.activeReceiver == ACTIVE_RTL) {
RFdata["rssithreshold"] = (int)getRTLrssiThreshold();
RFdata["rssi"] = (int)getRTLCurrentRSSI();
RFdata["avgrssi"] = (int)getRTLAverageRSSI();
RFdata["count"] = (int)getRTLMessageCount();
# ifdef ZradioSX127x
RFdata["ookthreshold"] = (int)getOOKThresh();
# 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.trace(F("RF active:" CR));
Config_update(RFdata, "active", RFConfig.activeReceiver);
success = true;
}
# ifdef ZgatewayRTL_433
if (RFdata.containsKey("rssithreshold")) {
Config_update(RFdata, "rssithreshold", RFConfig.rssiThreshold);
Log.notice(F("RTL_433 RSSI Threshold : %d " CR), 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
# endif
if (RFdata.containsKey("status")) {
Log.notice(F("RF get status:" CR));
rtl_433.getStatus();
success = true;
}
if (!success) {
Log.error(F("[rtl_433] MQTTtoRF Fail json" CR));
}

enableActiveReceiver();

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);
}
}

void RFConfig_init() {
RFConfig.frequency = RF_FREQUENCY;
RFConfig.activeReceiver = ACTIVE_RTL;
RFConfig.rssiThreshold = 0;
RFConfig.newOokThreshold = 0;
}

void RFConfig_load() {
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();
}
}
#endif
29 changes: 12 additions & 17 deletions main/ZgatewayPilight.ino
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ void pilightRawCallback(const uint16_t* pulses, size_t length) {
# endif

void setupPilight() {
RFConfig_init();
RFConfig_load();
# ifdef ZradioCC1101 //receiving with CC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
ELECHOUSE_cc1101.setMHZ(RF_FREQUENCY);
ELECHOUSE_cc1101.SetRx(RF_FREQUENCY);
# endif
rf.setCallback(pilightCallback);
rf.initReceiver(RF_RECEIVER_GPIO);
Expand Down Expand Up @@ -232,10 +234,10 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
int msgLength = rf.stringToPulseTrain(raw, codes, MAXPULSESTREAMLENGTH);
if (msgLength > 0) {
# ifdef ZradioCC1101
disableActiveReceiver();
disableCurrentReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(receiveMhz); // set Transmit on
ELECHOUSE_cc1101.SetTx(RFConfig.frequency); // set Transmit on
rf.disableReceiver();
# endif
rf.sendPulseTrain(codes, msgLength, repeats);
Expand Down Expand Up @@ -263,10 +265,10 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
if (message && protocol) {
Log.trace(F("MQTTtoPilight msg & protocol ok" CR));
# ifdef ZradioCC1101
disableActiveReceiver();
disableCurrentReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(receiveMhz); // set Transmit on
ELECHOUSE_cc1101.SetTx(RFConfig.frequency); // set Transmit on
rf.disableReceiver();
# endif
int msgLength = rf.send(protocol, message);
Expand Down Expand Up @@ -296,24 +298,17 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
}
if (Pilightdata.containsKey("active")) {
Log.trace(F("PiLight active:" CR));
activeReceiver = ACTIVE_PILIGHT; // Enable PILIGHT gateway
RFConfig.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
Log.error(F("MQTTtoPilight Fail json" CR));
}
enableActiveReceiver(false);
enableActiveReceiver();
}
}

Expand All @@ -325,7 +320,7 @@ extern void disablePilightReceive() {

extern void enablePilightReceive() {
# ifdef ZradioCC1101
Log.notice(F("Switching to Pilight Receiver: %F" CR), receiveMhz);
Log.notice(F("Switching to Pilight Receiver: %F" CR), RFConfig.frequency);
# else
Log.notice(F("Switching to Pilight Receiver" CR));
# endif
Expand All @@ -341,7 +336,7 @@ extern void enablePilightReceive() {

# ifdef ZradioCC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
ELECHOUSE_cc1101.SetRx(RFConfig.frequency); // set Receive on
# endif
rf.setCallback(pilightCallback);
# ifdef Pilight_rawEnabled
Expand Down
Loading

0 comments on commit fad5682

Please sign in to comment.