Skip to content

Commit

Permalink
Feat scan sensors (#187)
Browse files Browse the repository at this point in the history
* Added struct Sensor.decoder
* Added option to skip initialization of include/exclude list in begin()
  • Loading branch information
matthias-bs authored Jul 17, 2024
1 parent 6694ff1 commit ff450b6
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 19 deletions.
19 changes: 11 additions & 8 deletions examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// -
Expand Down Expand Up @@ -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<uint32_t> 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<uint32_t> 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<uint32_t> 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<uint32_t> 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
Expand Down
5 changes: 4 additions & 1 deletion examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// -
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// -
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=BresserWeatherSensorReceiver
version=0.28.8
version=0.28.9
author=Matthias Prinke <matthias-bs@web.de>
maintainer=Matthias Prinke <matthias-bs@web.de>
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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
18 changes: 11 additions & 7 deletions src/WeatherSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// -
Expand Down Expand Up @@ -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);
Expand All @@ -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<uint32_t> 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<uint32_t> 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<uint32_t> 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<uint32_t> 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
Expand Down
5 changes: 4 additions & 1 deletion src/WeatherSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// -
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/WeatherSensorDecoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// -
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ff450b6

Please sign in to comment.