-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FSK] Add Lilygo Heltec environment with FSK modulation
Enable RTL_433 frequency change with WebUI Add FSK environment for Heltec and Lilygo
- Loading branch information
1 parent
5421f0e
commit fad5682
Showing
15 changed files
with
506 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.