[SITE] Renew the web board presentation and the ESP32 web upload + [SYS] Security checks (#2277)
* Refactor GitHub Actions workflows for build, documentation, and linting - Consolidated build logic into reusable workflows (`task-build.yml` and `task-docs.yml`) to reduce duplication across multiple workflows. - Introduced `environments.json` to centralize the list of PlatformIO build environments, improving maintainability and clarity. - Updated `build.yml` and `build_and_docs_to_dev.yml` to utilize the new reusable workflows and environment definitions. - Enhanced `release.yml` to streamline the release process and integrate documentation generation. - Created reusable linting workflow (`task-lint.yml`) to standardize code formatting checks across the repository. - Simplified manual documentation workflow by leveraging the new reusable documentation workflow. - Improved artifact management and retention policies across workflows. - Updated dependencies and versions in workflows to ensure compatibility and performance. CI/CD pipeline agnostic of Workflow Engine and integrated on github actions - Implemented ci.sh for orchestrating the complete build pipeline. - Created ci_00_config.sh for centralized configuration of build scripts. - Created ci_build_firmware.sh for building firmware for specified PlatformIO environments. - Created ci_prepare_artifacts.sh for preparing firmware artifacts for upload or deployment. - Created ci_set_version.sh for updating version tags in firmware configuration files. - Created ci_build.sh to orchestrate the complete build pipeline. - Created ci_qa.sh for code linting and formatting checks using clang-format. - Created ci_site.sh for building and deploying VuePress documentation with version management. - Implemented checks for required tools and dependencies in the new scripts. - Improved internal scripts for better error handling and logging. UPDATE the web installer manifest generation and update documentation structure - Enhanced ci_list-env.sh to list environments from a JSON file. - Replaced common_wu.py and gen_wu.py scripts with new npm scripts for site generation and previewing on docsgen/gen_wu.js - Replaced generate_board_docs.py with docsgen/generated_board_docs.js - Added new npm scripts for integration of site generation on build phase. - Created preview_site.js to serve locally generated site over HTTPS with improved error handling. - Added new CI environments for CI builds in environments.json. - Deleted lint.yml as part of workflow cleanup. - Enhanced task-build.yml to include linting as a job and added support for specifying PlatformIO version. - Improved task-docs.yml to handle versioning more effectively and added clean option. Enhance documentation - ADD CLEAR Mark of development version of site - Updated README.md to include detailed workflow dependencies and relationships using mermaid diagrams. - Improved development.md with a quick checklist for contributors and clarified the code style guide. - Enhanced quick_start.md with tips for contributors and streamlined the workflow explanation. LINT FIX - Refined User_config.h for better formatting consistency. - Adjusted blufi.cpp and gatewayBT.cpp for improved code readability and consistency in formatting. - Updated gatewaySERIAL.cpp and mqttDiscovery.cpp to enhance logging error messages. - Improved sensorDS1820.cpp for better logging of device information. Add security scan workflows for vulnerability detection Add SBOM generation and upload to release workflow; update security scan summary handling Add shellcheck suppor + FIX shellcheck warning Enhance documentation for CI/CD scripts and workflows, adding details for security scanning and SBOM generation processes Fix formatting and alignment in BLE connection handling Reviewed the full web board presentation and the ESP32 web upload. The project uses a modern pattern where data is divided from the presentation layer. - Removed the `generate_board_docs` script. - Updated the `gen_wu` script in order to generate `boards-info.json`: the fail that containe all information about the configuration - Created and isolate the file `boards-info.js` to streamline the parsing of PlatformIO dependencies, modules, environments and improve the handling of library information. - Introduced vuepress component `BoardEnvironmentTable.vue` that render `boards-info.json` as UI card component - Introduced vuepress component `FlashEnvironmentSelector.vue` that render a selectred environment from `boards-info.json` and provide esp-web-upload feature on it - Introduced a new board page `board-selector.md` for improved firmware selection. - Updated `web-install.md` to enhance the firmware upload process, including a new board environment table. - Enhanced custom descriptions in `environments.ini` to include HTML links for better user guidance and board image link Add CC1101 initialization improvements and logging enhancements Add installation step for PlatformIO dependencies in documentation workflow Remove ci_set_version.sh script and associated versioning functionality * Fix comment provisined Fix PlatformIO version input reference in documentation workflow Remove outdated Squeezelite-ESP32 installer documentation
This commit is contained in:
1 parent
5f0966c2c1
commit
98481c5145
73 files changed
+5985
-2447
No files matched your search
@@ -92,6 +92,19 @@ extern bool cmpToMainTopic(const char*, const char*);
|
||||
extern bool pub(const char*, const char*, bool);
|
||||
extern bool pub(const char*, const char*);
|
||||
|
||||
// Float-specific overload to log with the correct format specifier.
|
||||
inline void Config_update(JsonObject& data, const char* key, float& var) {
|
||||
if (data.containsKey(key)) {
|
||||
float newVal = data[key].as<float>();
|
||||
if (var != newVal) {
|
||||
var = newVal;
|
||||
THEENGS_LOG_NOTICE(F("Config %s changed to: %F" CR), key, newVal);
|
||||
} else {
|
||||
THEENGS_LOG_NOTICE(F("Config %s unchanged, currently: %F" CR), key, newVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Config_update(JsonObject& data, const char* key, T& var) {
|
||||
if (data.containsKey(key)) {
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
#define user_config_h
|
||||
/*-------------------VERSION----------------------*/
|
||||
#ifndef OMG_VERSION
|
||||
# define OMG_VERSION "version_tag"
|
||||
# define OMG_VERSION "edge"
|
||||
#endif
|
||||
|
||||
/*-------------CONFIGURE WIFIMANAGER-------------(only ESP8266 & SONOFF RFBridge)*/
|
||||
|
||||
+4
-4
@@ -49,9 +49,9 @@ static NimBLEOta* pNimBLEOta;
|
||||
static NimBLECharacteristic* pCommandCharacteristic;
|
||||
static NimBLECharacteristic* pRecvFwCharacteristic;
|
||||
|
||||
#ifndef BLUFI_MFG_ID
|
||||
# define BLUFI_MFG_ID 0xFFFF // Default Manufacturer ID if not defined
|
||||
#endif
|
||||
# ifndef BLUFI_MFG_ID
|
||||
# define BLUFI_MFG_ID 0xFFFF // Default Manufacturer ID if not defined
|
||||
# endif
|
||||
|
||||
struct pkt_info {
|
||||
uint8_t* pkt;
|
||||
@@ -201,7 +201,7 @@ void restart_connection_timer() {}
|
||||
void stop_connection_timer() {}
|
||||
# endif
|
||||
|
||||
void set_blufi_mfg_data () {
|
||||
void set_blufi_mfg_data() {
|
||||
if (!NimBLEDevice::isInitialized() || !NimBLEDevice::getAdvertising()->isAdvertising()) {
|
||||
THEENGS_LOG_NOTICE(F("Unable to set advertising data" CR));
|
||||
return;
|
||||
|
||||
+52
-14
@@ -40,6 +40,7 @@ extern rtl_433_ESP rtl_433;
|
||||
# endif
|
||||
|
||||
int currentReceiver = ACTIVE_NONE;
|
||||
boolean isDriverEnabled = false;
|
||||
extern void enableActiveReceiver();
|
||||
extern void disableCurrentReceiver();
|
||||
|
||||
@@ -53,43 +54,63 @@ public:
|
||||
ZCommonRFWrapper() : RFReceiver() {}
|
||||
void enable() override { enableActiveReceiver(); }
|
||||
void disable() override { disableCurrentReceiver(); }
|
||||
|
||||
int getReceiverID() const override { return currentReceiver; }
|
||||
};
|
||||
|
||||
ZCommonRFWrapper iRFReceiver;
|
||||
RFConfiguration iRFConfig(iRFReceiver);
|
||||
|
||||
//TODO review
|
||||
// Initialize the CC1101 and tune the RX frequency.
|
||||
// - Uses truncated exponential backoff to avoid tight retry loops
|
||||
// - Validates the configured frequency before touching the radio
|
||||
// - Emits explicit logs for success/failure so watchdog resets are traceable
|
||||
void initCC1101() {
|
||||
# ifdef ZradioCC1101 //receiving with CC1101
|
||||
// Loop on getCC1101() until it returns true and break after 10 attempts
|
||||
# ifdef ZradioCC1101 // receiving with CC1101
|
||||
const float freqMhz = iRFConfig.getFrequency();
|
||||
if (!iRFConfig.validFrequency(freqMhz)) {
|
||||
THEENGS_LOG_ERROR(F("C1101 invalid frequency: %F MHz" CR), freqMhz);
|
||||
return;
|
||||
}
|
||||
|
||||
int delayMS = 16;
|
||||
int delayMaxMS = 500;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
# if defined(RF_MODULE_SCK) && defined(RF_MODULE_MISO) && \
|
||||
defined(RF_MODULE_MOSI) && defined(RF_MODULE_CS)
|
||||
ELECHOUSE_cc1101.setSpiPin(RF_MODULE_SCK, RF_MODULE_MISO, RF_MODULE_MOSI, RF_MODULE_CS);
|
||||
bool connected = false;
|
||||
|
||||
for (int attempt = 1; attempt <= 10; attempt++) {
|
||||
# if defined(RF_CC1101_SCK) && defined(RF_CC1101_MISO) && \
|
||||
defined(RF_CC1101_MOSI) && defined(RF_CC1101_CS)
|
||||
THEENGS_LOG_TRACE(F("initCC1101 with custom SPI pins, SCK=%d, MISO=%d, MOSI=%d, CS=%d" CR), RF_CC1101_SCK, RF_CC1101_MISO, RF_CC1101_MOSI, RF_CC1101_CS);
|
||||
ELECHOUSE_cc1101.setSpiPin(RF_CC1101_SCK, RF_CC1101_MISO, RF_CC1101_MOSI, RF_CC1101_CS);
|
||||
# endif
|
||||
|
||||
if (ELECHOUSE_cc1101.getCC1101()) {
|
||||
THEENGS_LOG_NOTICE(F("C1101 spi Connection OK" CR));
|
||||
connected = true;
|
||||
THEENGS_LOG_NOTICE(F("C1101 SPI connection OK on attempt %d" CR), attempt);
|
||||
ELECHOUSE_cc1101.Init();
|
||||
ELECHOUSE_cc1101.SetRx(iRFConfig.getFrequency());
|
||||
ELECHOUSE_cc1101.SetRx(freqMhz);
|
||||
THEENGS_LOG_NOTICE(F("C1101 tuned RX to %F MHz" CR), freqMhz);
|
||||
break;
|
||||
} else {
|
||||
THEENGS_LOG_ERROR(F("C1101 spi Connection Error" CR));
|
||||
delay(delayMS);
|
||||
}
|
||||
|
||||
THEENGS_LOG_ERROR(F("C1101 SPI connection error (attempt %d), retrying" CR), attempt);
|
||||
delay(delayMS);
|
||||
|
||||
// truncated exponential backoff
|
||||
delayMS = delayMS * 2;
|
||||
if (delayMS > delayMaxMS) delayMS = delayMaxMS;
|
||||
}
|
||||
|
||||
if (!connected) {
|
||||
THEENGS_LOG_ERROR(F("C1101 init failed after retries, radio left disabled" CR));
|
||||
}
|
||||
# else
|
||||
THEENGS_LOG_TRACE(F("initCC1101 skipped: ZradioCC1101 not enabled" CR));
|
||||
# endif
|
||||
}
|
||||
|
||||
void setupCommonRF() {
|
||||
iRFConfig.reInit();
|
||||
iRFConfig.loadFromStorage();
|
||||
iRFConfig.loadFromStorage(true);
|
||||
}
|
||||
|
||||
# if !defined(ZgatewayRFM69) && !defined(ZactuatorSomfy)
|
||||
@@ -120,28 +141,37 @@ bool validReceiver(int receiver) {
|
||||
# endif
|
||||
|
||||
void disableCurrentReceiver() {
|
||||
if (!isDriverEnabled) {
|
||||
THEENGS_LOG_TRACE(F("Receiver %d is already disabled" CR), currentReceiver);
|
||||
return;
|
||||
}
|
||||
THEENGS_LOG_TRACE(F("disableCurrentReceiver: %d" CR), currentReceiver);
|
||||
switch (currentReceiver) {
|
||||
case ACTIVE_NONE:
|
||||
isDriverEnabled = false;
|
||||
break;
|
||||
# ifdef ZgatewayPilight
|
||||
case ACTIVE_PILIGHT:
|
||||
disablePilightReceive();
|
||||
isDriverEnabled = false;
|
||||
break;
|
||||
# endif
|
||||
# ifdef ZgatewayRF
|
||||
case ACTIVE_RF:
|
||||
disableRFReceive();
|
||||
isDriverEnabled = false;
|
||||
break;
|
||||
# endif
|
||||
# ifdef ZgatewayRTL_433
|
||||
case ACTIVE_RTL:
|
||||
disableRTLreceive();
|
||||
isDriverEnabled = false;
|
||||
break;
|
||||
# endif
|
||||
# ifdef ZgatewayRF2
|
||||
case ACTIVE_RF2:
|
||||
disableRF2Receive();
|
||||
isDriverEnabled = false;
|
||||
break;
|
||||
# endif
|
||||
default:
|
||||
@@ -150,6 +180,10 @@ void disableCurrentReceiver() {
|
||||
}
|
||||
|
||||
void enableActiveReceiver() {
|
||||
if (isDriverEnabled) {
|
||||
THEENGS_LOG_TRACE(F("Receiver %d is already enabled" CR), currentReceiver);
|
||||
return;
|
||||
}
|
||||
THEENGS_LOG_TRACE(F("enableActiveReceiver: %d" CR), iRFConfig.getActiveReceiver());
|
||||
switch (iRFConfig.getActiveReceiver()) {
|
||||
# ifdef ZgatewayPilight
|
||||
@@ -157,6 +191,7 @@ void enableActiveReceiver() {
|
||||
initCC1101();
|
||||
enablePilightReceive();
|
||||
currentReceiver = ACTIVE_PILIGHT;
|
||||
isDriverEnabled = true;
|
||||
break;
|
||||
# endif
|
||||
# ifdef ZgatewayRF
|
||||
@@ -164,6 +199,7 @@ void enableActiveReceiver() {
|
||||
initCC1101();
|
||||
enableRFReceive(iRFConfig.getFrequency(), RF_RECEIVER_GPIO, RF_EMITTER_GPIO);
|
||||
currentReceiver = ACTIVE_RF;
|
||||
isDriverEnabled = true;
|
||||
break;
|
||||
# endif
|
||||
# ifdef ZgatewayRTL_433
|
||||
@@ -171,6 +207,7 @@ void enableActiveReceiver() {
|
||||
initCC1101();
|
||||
enableRTLreceive();
|
||||
currentReceiver = ACTIVE_RTL;
|
||||
isDriverEnabled = true;
|
||||
break;
|
||||
# endif
|
||||
# ifdef ZgatewayRF2
|
||||
@@ -178,6 +215,7 @@ void enableActiveReceiver() {
|
||||
initCC1101();
|
||||
enableRF2Receive();
|
||||
currentReceiver = ACTIVE_RF2;
|
||||
isDriverEnabled = true;
|
||||
break;
|
||||
# endif
|
||||
case ACTIVE_RECERROR:
|
||||
|
||||
+1
-1
@@ -190,7 +190,7 @@ extern RFConfiguration iRFConfig;
|
||||
/*-------------------RF frequency----------------------*/
|
||||
//Match frequency to the hardware version of the radio used.
|
||||
#ifndef RF_FREQUENCY
|
||||
# define RF_FREQUENCY 433.92
|
||||
# define RF_FREQUENCY 433.92f
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
@@ -337,20 +337,20 @@ void BM2_connect::publishData() {
|
||||
static const unsigned char BM6_AES_KEY[16] = {
|
||||
108, // l
|
||||
101, // e
|
||||
97, // a
|
||||
97, // a
|
||||
103, // g
|
||||
101, // e
|
||||
110, // n
|
||||
100, // d
|
||||
255, // 0xff
|
||||
254, // 0xfe
|
||||
48, // 0
|
||||
49, // 1
|
||||
48, // 0
|
||||
48, // 0
|
||||
48, // 0
|
||||
48, // 0
|
||||
57, // 9
|
||||
48, // 0
|
||||
49, // 1
|
||||
48, // 0
|
||||
48, // 0
|
||||
48, // 0
|
||||
48, // 0
|
||||
57, // 9
|
||||
};
|
||||
|
||||
void BM6_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, size_t length, bool isNotify) {
|
||||
|
||||
+3
-3
@@ -992,7 +992,7 @@ void launchBTDiscovery(bool overrideDiscovery) {
|
||||
if (!BTConfig.extDecoderEnable && // Do not decode if an external decoder is configured
|
||||
p->sensorModel_id > UNKWNON_MODEL &&
|
||||
p->sensorModel_id < TheengsDecoder::BLE_ID_NUM::BLE_ID_MAX &&
|
||||
p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::HHCCJCY01HHCC &&
|
||||
p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::HHCCJCY01HHCC &&
|
||||
p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::BM2 &&
|
||||
p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::BM6) { // Exception on HHCCJCY01HHCC and BM2/BM6 as these ones are discoverable and connectable
|
||||
if (isTracker) {
|
||||
@@ -1025,10 +1025,10 @@ void launchBTDiscovery(bool overrideDiscovery) {
|
||||
// This should not happen if JSON_MSG_BUFFER is large enough for
|
||||
// the Theengs json properties
|
||||
THEENGS_LOG_ERROR(F("JSON deserialization of Theengs properties overflowed (error %s), buffer capacity: %u. Program might crash. Properties json: %s" CR),
|
||||
error.c_str(), jsonBuffer.capacity(), properties.c_str());
|
||||
error.c_str(), jsonBuffer.capacity(), properties.c_str());
|
||||
} else {
|
||||
THEENGS_LOG_ERROR(F("JSON deserialization of Theengs properties errored: %" CR),
|
||||
error.c_str());
|
||||
error.c_str());
|
||||
}
|
||||
}
|
||||
for (JsonPair prop : jsonBuffer["properties"].as<JsonObject>()) {
|
||||
|
||||
+2
-2
@@ -402,7 +402,7 @@ void enableRFReceive(
|
||||
float rfFrequency = iRFConfig.getFrequency(),
|
||||
int rfReceiverGPIO = RF_RECEIVER_GPIO,
|
||||
int rfEmitterGPIO = RF_EMITTER_GPIO) {
|
||||
THEENGS_LOG_NOTICE(F("[RF] Enable RF Receiver: %fMhz, RF_EMITTER_GPIO: %d, RF_RECEIVER_GPIO: %d" CR), rfFrequency, rfEmitterGPIO, rfReceiverGPIO);
|
||||
THEENGS_LOG_NOTICE(F("[RF] Enable RF Receiver: %F Mhz, RF_EMITTER_GPIO: %d, RF_RECEIVER_GPIO: %d" CR), rfFrequency, rfEmitterGPIO, rfReceiverGPIO);
|
||||
|
||||
# ifdef RF_DISABLE_TRANSMIT
|
||||
mySwitch.disableTransmit();
|
||||
@@ -410,7 +410,7 @@ void enableRFReceive(
|
||||
mySwitch.enableTransmit(rfEmitterGPIO);
|
||||
# endif
|
||||
|
||||
mySwitch.setRepeatTransmit(rfEmitterGPIO);
|
||||
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT);
|
||||
mySwitch.enableReceive(rfReceiverGPIO);
|
||||
|
||||
THEENGS_LOG_TRACE(F("[RF] Setup command topic: %s%s%s\n Setup done" CR), (const char*)mqtt_topic, (const char*)gateway_name, (const char*)subjectMQTTtoRF);
|
||||
|
||||
@@ -316,7 +316,7 @@ void sendMQTTfromNestedJson(JsonVariant obj, char* topic, int level, int maxLeve
|
||||
topic[topicLength] = '\0';
|
||||
} else {
|
||||
THEENGS_LOG_ERROR(F("Nested key '%s' at level %d does not fit within max topic length of %d, skipping"),
|
||||
key, level, mqtt_topic_max_size);
|
||||
key, level, mqtt_topic_max_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -96,8 +96,8 @@ char gateway_name[parameters_size + 1] = Gateway_Name;
|
||||
unsigned long lastDiscovery = 0;
|
||||
|
||||
#if BLEDecryptor
|
||||
char ble_aes[parameters_size] = BLE_AES;
|
||||
StaticJsonDocument<JSON_BLE_AES_CUSTOM_KEYS> ble_aes_keys;
|
||||
char ble_aes[parameters_size] = BLE_AES;
|
||||
StaticJsonDocument<JSON_BLE_AES_CUSTOM_KEYS> ble_aes_keys;
|
||||
#endif
|
||||
|
||||
#if !MQTT_BROKER_MODE
|
||||
@@ -2185,11 +2185,11 @@ bool loadConfigFromFlash() {
|
||||
if (json.containsKey("ble_aes")) {
|
||||
strcpy(ble_aes, json["ble_aes"]);
|
||||
THEENGS_LOG_TRACE(F("loaded default BLE AES key %s" CR), ble_aes);
|
||||
}
|
||||
}
|
||||
if (json.containsKey("ble_aes_keys")) {
|
||||
ble_aes_keys = json["ble_aes_keys"];
|
||||
THEENGS_LOG_TRACE(F("loaded %d custom BLE AES keys" CR), ble_aes_keys.size());
|
||||
}
|
||||
}
|
||||
# endif
|
||||
result = true;
|
||||
} else {
|
||||
|
||||
@@ -600,7 +600,7 @@ void createDiscovery(const char* sensor_type,
|
||||
}
|
||||
}
|
||||
|
||||
if (diagnostic_entity) { // entity_category
|
||||
if (diagnostic_entity) { // entity_category
|
||||
sensor["ent_cat"] = "diagnostic";
|
||||
}
|
||||
|
||||
|
||||
+19
-22
@@ -65,6 +65,7 @@ void RFConfiguration::reInit() {
|
||||
activeReceiver = ACTIVE_RECEIVER;
|
||||
rssiThreshold = 0;
|
||||
newOokThreshold = 0;
|
||||
THEENGS_LOG_TRACE(F("RFConfiguration reInit: frequency=%F, activeReceiver=%d" CR), frequency, activeReceiver);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,13 +83,13 @@ void RFConfiguration::eraseStorage() {
|
||||
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);
|
||||
THEENGS_LOG_NOTICE(F("RF config erase result: %d" CR), result);
|
||||
} else {
|
||||
Log.notice(F("RF config not found" CR));
|
||||
THEENGS_LOG_NOTICE(F("RF config not found" CR));
|
||||
}
|
||||
preferences.end();
|
||||
#else
|
||||
Log.warning(F("RF Config Erase not support with this board" CR));
|
||||
THEENGS_LOG_WARNING(F("RF Config Erase not support with this board" CR));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -120,9 +121,9 @@ void RFConfiguration::saveOnStorage() {
|
||||
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);
|
||||
THEENGS_LOG_NOTICE(F("RF Config_save: %s, result: %d" CR), conf.c_str(), result);
|
||||
#else
|
||||
Log.warning(F("RF Config_save not support with this board" CR));
|
||||
THEENGS_LOG_WARNING(F("RF Config_save not support with this board" CR));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -149,24 +150,25 @@ void RFConfiguration::loadFromStorage(bool reinitReceiver) {
|
||||
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());
|
||||
THEENGS_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));
|
||||
THEENGS_LOG_WARNING(F("RF Config is null" CR));
|
||||
return;
|
||||
}
|
||||
JsonObject jo = jsonBuffer.as<JsonObject>();
|
||||
fromJson(jo);
|
||||
Log.notice(F("RF Config loaded" CR));
|
||||
THEENGS_LOG_NOTICE(F("RF Config loaded" CR));
|
||||
} else {
|
||||
preferences.end();
|
||||
Log.notice(F("RF Config not found using default" CR));
|
||||
THEENGS_LOG_NOTICE(F("RF Config not found using default" CR));
|
||||
}
|
||||
#endif
|
||||
// Disable and re-enable the receiver to ensure proper initialization
|
||||
if (reinitReceiver) {
|
||||
iRFReceiver.disable();
|
||||
delay(100);
|
||||
iRFReceiver.enable();
|
||||
}
|
||||
}
|
||||
@@ -209,10 +211,10 @@ void RFConfiguration::loadFromMessage(JsonObject& RFdata) {
|
||||
|
||||
if (RFdata.containsKey("erase") && RFdata["erase"].as<bool>()) {
|
||||
eraseStorage();
|
||||
Log.notice(F("RF Config erased" CR));
|
||||
THEENGS_LOG_NOTICE(F("RF Config erased" CR));
|
||||
} else if (RFdata.containsKey("save") && RFdata["save"].as<bool>()) {
|
||||
saveOnStorage();
|
||||
Log.notice(F("RF Config saved" CR));
|
||||
THEENGS_LOG_NOTICE(F("RF Config saved" CR));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,17 +247,17 @@ void RFConfiguration::fromJson(JsonObject& RFdata) {
|
||||
|
||||
if (RFdata.containsKey("frequency") && validFrequency(RFdata["frequency"])) {
|
||||
Config_update(RFdata, "frequency", frequency);
|
||||
Log.notice(F("RF Receive mhz: %F" CR), frequency);
|
||||
THEENGS_LOG_NOTICE(F("RF Receive mhz: %F" CR), frequency);
|
||||
success = true;
|
||||
}
|
||||
if (RFdata.containsKey("active")) {
|
||||
Config_update(RFdata, "active", activeReceiver);
|
||||
Log.notice(F("RF receiver active: %d" CR), activeReceiver);
|
||||
THEENGS_LOG_NOTICE(F("RF receiver active: %d" CR), activeReceiver);
|
||||
success = true;
|
||||
}
|
||||
#ifdef ZgatewayRTL_433
|
||||
if (RFdata.containsKey("rssithreshold")) {
|
||||
Log.notice(F("RTL_433 RSSI Threshold : %d " CR), rssiThreshold);
|
||||
THEENGS_LOG_NOTICE(F("RTL_433 RSSI Threshold : %d " CR), rssiThreshold);
|
||||
Config_update(RFdata, "rssithreshold", rssiThreshold);
|
||||
rtl_433.setRSSIThreshold(rssiThreshold);
|
||||
success = true;
|
||||
@@ -263,18 +265,18 @@ void RFConfiguration::fromJson(JsonObject& RFdata) {
|
||||
# if defined(RF_SX1276) || defined(RF_SX1278)
|
||||
if (RFdata.containsKey("ookthreshold")) {
|
||||
Config_update(RFdata, "ookthreshold", newOokThreshold);
|
||||
Log.notice(F("RTL_433 ookThreshold %d" CR), newOokThreshold);
|
||||
THEENGS_LOG_NOTICE(F("RTL_433 ookThreshold %d" CR), newOokThreshold);
|
||||
rtl_433.setOOKThreshold(newOokThreshold);
|
||||
success = true;
|
||||
}
|
||||
# endif
|
||||
if (RFdata.containsKey("status")) {
|
||||
Log.notice(F("RF get status:" CR));
|
||||
THEENGS_LOG_NOTICE(F("RF get status:" CR));
|
||||
rtl_433.getStatus();
|
||||
success = true;
|
||||
}
|
||||
if (!success) {
|
||||
Log.error(F("MQTTtoRF Fail json" CR));
|
||||
THEENGS_LOG_ERROR(F("MQTTtoRF Fail json" CR));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -307,11 +309,6 @@ void RFConfiguration::toJson(JsonObject& RFdata) {
|
||||
RFdata["rssithreshold"] = rssiThreshold;
|
||||
RFdata["ookthreshold"] = newOokThreshold;
|
||||
RFdata["active"] = activeReceiver;
|
||||
|
||||
// Add white-list vector to the JSON object
|
||||
JsonArray whiteListArray = RFdata.createNestedArray("white-list");
|
||||
// Add black-list vector to the JSON object
|
||||
JsonArray blackListArray = RFdata.createNestedArray("black-list");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,10 +92,10 @@ void setupZsensorDS1820() {
|
||||
}
|
||||
ds1820_resolution[ds1820_count] = ds1820.getResolution(ds1820_address);
|
||||
THEENGS_LOG_TRACE(F("DS1820: Device %d, Type: %s, Address: %s, Resolution: %d" CR),
|
||||
ds1820_count,
|
||||
(char*)ds1820_type[ds1820_count].c_str(),
|
||||
(char*)ds1820_addr[ds1820_count].c_str(),
|
||||
ds1820_resolution[ds1820_count]);
|
||||
ds1820_count,
|
||||
(char*)ds1820_type[ds1820_count].c_str(),
|
||||
(char*)ds1820_addr[ds1820_count].c_str(),
|
||||
ds1820_resolution[ds1820_count]);
|
||||
ds1820_count++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user