From ff450b68f669fe312af9a3e00ae9736804df12b6 Mon Sep 17 00:00:00 2001 From: Matthias Prinke <83612361+matthias-bs@users.noreply.github.com> Date: Wed, 17 Jul 2024 22:16:58 +0200 Subject: [PATCH] Feat scan sensors (#187) * Added struct Sensor.decoder * Added option to skip initialization of include/exclude list in begin() --- .../src/WeatherSensor.cpp | 19 +++++++++++-------- .../src/WeatherSensor.h | 5 ++++- .../src/WeatherSensorDecoders.cpp | 6 ++++++ library.properties | 2 +- package.json | 2 +- src/WeatherSensor.cpp | 18 +++++++++++------- src/WeatherSensor.h | 5 ++++- src/WeatherSensorDecoders.cpp | 6 ++++++ 8 files changed, 44 insertions(+), 19 deletions(-) diff --git a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.cpp b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.cpp index 0a30dc9..141e247 100644 --- a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.cpp +++ b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.cpp @@ -101,6 +101,7 @@ // 20240528 Fixed channel comparison in findType() // 20240608 Modified implementation of maximum number of sensors // 20240609 Fixed implementation of maximum number of sensors +// 20240714 Added option to skip initialization of include/exclude lists // // ToDo: // - @@ -135,23 +136,25 @@ void receivedFlag = true; } -int16_t WeatherSensor::begin(uint8_t max_sensors_default) +int16_t WeatherSensor::begin(uint8_t max_sensors_default, bool init_filters) { uint8_t maxSensors = max_sensors_default; - getSensorsCfg(maxSensors, rxFlags, enDecoders); log_d("max_sensors: %u", maxSensors); log_d("rx_flags: %u", rxFlags); log_d("en_decoders: %u", enDecoders); sensor.resize(maxSensors); - // List of sensor IDs to be excluded - can be empty - std::vector sensor_ids_exc_def = SENSOR_IDS_EXC; - initList(sensor_ids_exc, sensor_ids_exc_def, "exc"); + if (init_filters) + { + // List of sensor IDs to be excluded - can be empty + std::vector sensor_ids_exc_def = SENSOR_IDS_EXC; + initList(sensor_ids_exc, sensor_ids_exc_def, "exc"); - // List of sensor IDs to be included - if zero, handle all available sensors - std::vector sensor_ids_inc_def = SENSOR_IDS_INC; - initList(sensor_ids_inc, sensor_ids_inc_def, "inc"); + // List of sensor IDs to be included - if zero, handle all available sensors + std::vector sensor_ids_inc_def = SENSOR_IDS_INC; + initList(sensor_ids_inc, sensor_ids_inc_def, "inc"); + } // https://github.com/RFD-FHEM/RFFHEM/issues/607#issuecomment-830818445 // Freq: 868.300 MHz, Bandwidth: 203 KHz, rAmpl: 33 dB, sens: 8 dB, DataRate: 8207.32 Baud diff --git a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h index 7bb0610..07a7b9e 100644 --- a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h +++ b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h @@ -81,6 +81,8 @@ // 20240507 Added configuration of enabled decoders at run time // 20240608 Modified implementation of maximum number of sensors // 20240609 Fixed implementation of maximum number of sensors +// 20240714 Added decoder to struct Sensor +// 20240716 Added option to skip initialization of filters in begin() // // ToDo: // - @@ -180,7 +182,7 @@ class WeatherSensor { \returns RADIOLIB_ERR_NONE on success (otherwise does never return). */ - int16_t begin(uint8_t max_sensors_default = MAX_SENSORS_DEFAULT); + int16_t begin(uint8_t max_sensors_default = MAX_SENSORS_DEFAULT, bool init_filters = true); /*! \brief Reset radio transceiver @@ -303,6 +305,7 @@ class WeatherSensor { float rssi; //!< received signal strength indicator in dBm uint8_t s_type; //!< sensor type uint8_t chan; //!< channel + uint8_t decoder; //!< decoder used bool startup = false; //!< startup after reset / battery change bool battery_ok; //!< battery o.k. bool valid; //!< data valid (but not necessarily complete) diff --git a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorDecoders.cpp b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorDecoders.cpp index fc008d4..06cab03 100644 --- a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorDecoders.cpp +++ b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorDecoders.cpp @@ -49,6 +49,7 @@ // https://github.com/merbanan/rtl_433/commit/271bed886c5b1ff7c1a47e6cf1366e397aeb8364 // and // https://github.com/merbanan/rtl_433/commit/9928efe5c8d55e9ca01f1ebab9e8b20b0e7ba01e +// 20240716 Added assignment of sensor[slot].decoder // // ToDo: // - @@ -331,6 +332,7 @@ DecodeStatus WeatherSensor::decodeBresser5In1Payload(const uint8_t *msg, uint8_t } sensor[slot].s_type = type_tmp; + sensor[slot].decoder = DECODER_5IN1; sensor[slot].w.temp_ok = (msg[20] & 0x0f) <= 9; // BCD, 0x0f on error sensor[slot].w.light_ok = false; sensor[slot].w.uv_ok = false; @@ -479,6 +481,7 @@ DecodeStatus WeatherSensor::decodeBresser6In1Payload(const uint8_t *msg, uint8_t sensor[slot].sensor_id = id_tmp; sensor[slot].s_type = type_tmp; sensor[slot].chan = chan_tmp; + sensor[slot].decoder = DECODER_6IN1; sensor[slot].startup = ((msg[6] & 0x8) == 0) ? true : false; // s.a. #1214 sensor[slot].battery_ok = (msg[13] >> 1) & 1; // b[13] & 0x02 is battery_good, s.a. #1993 @@ -743,6 +746,7 @@ DecodeStatus WeatherSensor::decodeBresser7In1Payload(const uint8_t *msg, uint8_t sensor[slot].s_type = s_type; sensor[slot].startup = (msg[6] & 0x08) == 0x00; // raw data, no de-whitening sensor[slot].chan = msg[6] & 0x07; // raw data, no de-whitening + sensor[slot].decoder = DECODER_7IN1; sensor[slot].battery_ok = !battery_low; sensor[slot].valid = true; sensor[slot].complete = true; @@ -907,6 +911,7 @@ DecodeStatus WeatherSensor::decodeBresserLightningPayload(const uint8_t *msg, ui sensor[slot].s_type = s_type; sensor[slot].startup = startup; sensor[slot].chan = 0; + sensor[slot].decoder = DECODER_LIGHTNING; sensor[slot].battery_ok = !battery_low; sensor[slot].rssi = rssi; sensor[slot].valid = true; @@ -1008,6 +1013,7 @@ DecodeStatus WeatherSensor::decodeBresserLeakagePayload(const uint8_t *msg, uint sensor[slot].sensor_id = id_tmp; sensor[slot].s_type = type_tmp; sensor[slot].chan = chan_tmp; + sensor[slot].decoder = DECODER_LEAKAGE; sensor[slot].startup = (msg[6] & 0x8) == 0x00; sensor[slot].battery_ok = (msg[7] & 0x30) != 0x00; sensor[slot].rssi = rssi; diff --git a/library.properties b/library.properties index 8088c95..671f42f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=BresserWeatherSensorReceiver -version=0.28.8 +version=0.28.9 author=Matthias Prinke maintainer=Matthias Prinke sentence=Bresser 5-in-1/6-in-1/7-in-1 868 MHz Weather Sensor Radio Receiver for Arduino based on CC1101, SX1276/RFM95W or SX1262. diff --git a/package.json b/package.json index 95bb282..82efb03 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "BresserWeatherSensorReceiver", - "version": "0.28.8", + "version": "0.28.9", "description": "Bresser 5-in-1/6-in-1/7-in-1 868 MHz Weather Sensor Radio Receiver for Arduino based on CC1101, SX1276/RFM95W or SX1262", "main": "WeatherSensor.cpp", "frameworks": "arduino", diff --git a/src/WeatherSensor.cpp b/src/WeatherSensor.cpp index e2ac686..141e247 100644 --- a/src/WeatherSensor.cpp +++ b/src/WeatherSensor.cpp @@ -101,6 +101,7 @@ // 20240528 Fixed channel comparison in findType() // 20240608 Modified implementation of maximum number of sensors // 20240609 Fixed implementation of maximum number of sensors +// 20240714 Added option to skip initialization of include/exclude lists // // ToDo: // - @@ -135,7 +136,7 @@ void receivedFlag = true; } -int16_t WeatherSensor::begin(uint8_t max_sensors_default) +int16_t WeatherSensor::begin(uint8_t max_sensors_default, bool init_filters) { uint8_t maxSensors = max_sensors_default; getSensorsCfg(maxSensors, rxFlags, enDecoders); @@ -144,13 +145,16 @@ int16_t WeatherSensor::begin(uint8_t max_sensors_default) log_d("en_decoders: %u", enDecoders); sensor.resize(maxSensors); - // List of sensor IDs to be excluded - can be empty - std::vector sensor_ids_exc_def = SENSOR_IDS_EXC; - initList(sensor_ids_exc, sensor_ids_exc_def, "exc"); + if (init_filters) + { + // List of sensor IDs to be excluded - can be empty + std::vector sensor_ids_exc_def = SENSOR_IDS_EXC; + initList(sensor_ids_exc, sensor_ids_exc_def, "exc"); - // List of sensor IDs to be included - if zero, handle all available sensors - std::vector sensor_ids_inc_def = SENSOR_IDS_INC; - initList(sensor_ids_inc, sensor_ids_inc_def, "inc"); + // List of sensor IDs to be included - if zero, handle all available sensors + std::vector sensor_ids_inc_def = SENSOR_IDS_INC; + initList(sensor_ids_inc, sensor_ids_inc_def, "inc"); + } // https://github.com/RFD-FHEM/RFFHEM/issues/607#issuecomment-830818445 // Freq: 868.300 MHz, Bandwidth: 203 KHz, rAmpl: 33 dB, sens: 8 dB, DataRate: 8207.32 Baud diff --git a/src/WeatherSensor.h b/src/WeatherSensor.h index 7bb0610..07a7b9e 100644 --- a/src/WeatherSensor.h +++ b/src/WeatherSensor.h @@ -81,6 +81,8 @@ // 20240507 Added configuration of enabled decoders at run time // 20240608 Modified implementation of maximum number of sensors // 20240609 Fixed implementation of maximum number of sensors +// 20240714 Added decoder to struct Sensor +// 20240716 Added option to skip initialization of filters in begin() // // ToDo: // - @@ -180,7 +182,7 @@ class WeatherSensor { \returns RADIOLIB_ERR_NONE on success (otherwise does never return). */ - int16_t begin(uint8_t max_sensors_default = MAX_SENSORS_DEFAULT); + int16_t begin(uint8_t max_sensors_default = MAX_SENSORS_DEFAULT, bool init_filters = true); /*! \brief Reset radio transceiver @@ -303,6 +305,7 @@ class WeatherSensor { float rssi; //!< received signal strength indicator in dBm uint8_t s_type; //!< sensor type uint8_t chan; //!< channel + uint8_t decoder; //!< decoder used bool startup = false; //!< startup after reset / battery change bool battery_ok; //!< battery o.k. bool valid; //!< data valid (but not necessarily complete) diff --git a/src/WeatherSensorDecoders.cpp b/src/WeatherSensorDecoders.cpp index fc008d4..06cab03 100644 --- a/src/WeatherSensorDecoders.cpp +++ b/src/WeatherSensorDecoders.cpp @@ -49,6 +49,7 @@ // https://github.com/merbanan/rtl_433/commit/271bed886c5b1ff7c1a47e6cf1366e397aeb8364 // and // https://github.com/merbanan/rtl_433/commit/9928efe5c8d55e9ca01f1ebab9e8b20b0e7ba01e +// 20240716 Added assignment of sensor[slot].decoder // // ToDo: // - @@ -331,6 +332,7 @@ DecodeStatus WeatherSensor::decodeBresser5In1Payload(const uint8_t *msg, uint8_t } sensor[slot].s_type = type_tmp; + sensor[slot].decoder = DECODER_5IN1; sensor[slot].w.temp_ok = (msg[20] & 0x0f) <= 9; // BCD, 0x0f on error sensor[slot].w.light_ok = false; sensor[slot].w.uv_ok = false; @@ -479,6 +481,7 @@ DecodeStatus WeatherSensor::decodeBresser6In1Payload(const uint8_t *msg, uint8_t sensor[slot].sensor_id = id_tmp; sensor[slot].s_type = type_tmp; sensor[slot].chan = chan_tmp; + sensor[slot].decoder = DECODER_6IN1; sensor[slot].startup = ((msg[6] & 0x8) == 0) ? true : false; // s.a. #1214 sensor[slot].battery_ok = (msg[13] >> 1) & 1; // b[13] & 0x02 is battery_good, s.a. #1993 @@ -743,6 +746,7 @@ DecodeStatus WeatherSensor::decodeBresser7In1Payload(const uint8_t *msg, uint8_t sensor[slot].s_type = s_type; sensor[slot].startup = (msg[6] & 0x08) == 0x00; // raw data, no de-whitening sensor[slot].chan = msg[6] & 0x07; // raw data, no de-whitening + sensor[slot].decoder = DECODER_7IN1; sensor[slot].battery_ok = !battery_low; sensor[slot].valid = true; sensor[slot].complete = true; @@ -907,6 +911,7 @@ DecodeStatus WeatherSensor::decodeBresserLightningPayload(const uint8_t *msg, ui sensor[slot].s_type = s_type; sensor[slot].startup = startup; sensor[slot].chan = 0; + sensor[slot].decoder = DECODER_LIGHTNING; sensor[slot].battery_ok = !battery_low; sensor[slot].rssi = rssi; sensor[slot].valid = true; @@ -1008,6 +1013,7 @@ DecodeStatus WeatherSensor::decodeBresserLeakagePayload(const uint8_t *msg, uint sensor[slot].sensor_id = id_tmp; sensor[slot].s_type = type_tmp; sensor[slot].chan = chan_tmp; + sensor[slot].decoder = DECODER_LEAKAGE; sensor[slot].startup = (msg[6] & 0x8) == 0x00; sensor[slot].battery_ok = (msg[7] & 0x30) != 0x00; sensor[slot].rssi = rssi;