99#ifndef WeatherSensor_h
100#define WeatherSensor_h
105#include <Preferences.h>
107#include "WeatherSensorCfg.h"
111namespace WeatherSensorReceiver {
112 extern RADIO_CHIP radio;
132#define SENSOR_TYPE_WEATHER0 0
133#define SENSOR_TYPE_WEATHER1 1
134#define SENSOR_TYPE_THERMO_HYGRO 2
135#define SENSOR_TYPE_POOL_THERMO 3
136#define SENSOR_TYPE_SOIL 4
137#define SENSOR_TYPE_LEAKAGE 5
138#define SENSOR_TYPE_AIR_PM 8
139#define SENSOR_TYPE_RAIN 9
140#define SENSOR_TYPE_LIGHTNING 9
141#define SENSOR_TYPE_CO2 10
142#define SENSOR_TYPE_HCHO_VOC 11
143#define SENSOR_TYPE_WEATHER3 12
144#define SENSOR_TYPE_WEATHER8 13
148#define WEATHER0_RAIN_OV 1000
149#define WEATHER1_RAIN_OV 100000
153#define DATA_COMPLETE 0x1
155#define DATA_ALL_SLOTS 0x8
158#define DECODER_5IN1 0x01
159#define DECODER_6IN1 0x02
160#define DECODER_7IN1 0x04
161#define DECODER_LIGHTNING 0x08
162#define DECODER_LEAKAGE 0x10
165#define MSG_BUF_SIZE 27
168typedef enum DecodeStatus {
169 DECODE_INVALID, DECODE_OK, DECODE_PAR_ERR, DECODE_CHK_ERR, DECODE_DIG_ERR, DECODE_SKIP, DECODE_FULL
192 Preferences cfgPrefs;
193 std::vector<uint32_t> sensor_ids_inc;
194 std::vector<uint32_t> sensor_ids_exc;
202 int16_t
begin(uint8_t max_sensors_default = MAX_SENSORS_DEFAULT,
bool init_filters =
true, int32_t frequency_offset = 0);
230 bool getData(uint32_t timeout, uint8_t flags = 0, uint8_t type = 0,
void (*func)() = NULL);
247 DecodeStatus
decodeMessage(
const uint8_t *msg, uint8_t msgSize);
263 #ifdef WIND_DATA_FLOATINGPOINT
268 #ifdef WIND_DATA_FIXEDPOINT
344 #pragma GCC diagnostic push
345 #pragma GCC diagnostic ignored "-Wclass-memaccess"
346 memset(
this, 0,
sizeof(*
this));
347 #pragma GCC diagnostic pop
362 bool genMessage(
int i, uint32_t
id = 0xff, uint8_t s_type = 1, uint8_t channel = 0, uint8_t startup = 0);
375 for (
size_t i=0; i<
sensor.size(); i++) {
376 if ((type == 0xFF) || (
sensor[i].s_type == type)) {
378 sensor[i].complete =
false;
380 if (
sensor[i].s_type == SENSOR_TYPE_WEATHER1) {
381 sensor[i].w.temp_ok =
false;
382 sensor[i].w.humidity_ok =
false;
383 sensor[i].w.light_ok =
false;
384 sensor[i].w.uv_ok =
false;
385 sensor[i].w.wind_ok =
false;
386 sensor[i].w.rain_ok =
false;
409 int findType(uint8_t type, uint8_t channel = 0xFF);
434 void setSensorsCfg(uint8_t max_sensors, uint8_t rx_flags, uint8_t en_decoders = 0xFF);
442 void setRxCfg(uint8_t rx_flags, uint8_t en_decoders = 0xFF);
471 uint8_t
convSensorsJson(std::vector<uint32_t> &ids, String json, uint8_t *buf);
517 void getSensorsCfg(uint8_t &max_sensors, uint8_t &rx_flags, uint8_t &en_decoders);
520 struct Sensor *pData;
531 void initList(std::vector<uint32_t> &list,
const std::vector<uint32_t> list_def,
const char *key);
550 int findSlot(uint32_t
id, DecodeStatus * status);
553 #ifdef BRESSER_5_IN_1
563 DecodeStatus decodeBresser5In1Payload(
const uint8_t *msg, uint8_t msgSize);
565 #ifdef BRESSER_6_IN_1
577 DecodeStatus decodeBresser6In1Payload(
const uint8_t *msg, uint8_t msgSize);
579 #ifdef BRESSER_7_IN_1
589 DecodeStatus decodeBresser7In1Payload(
const uint8_t *msg, uint8_t msgSize);
591 #ifdef BRESSER_LIGHTNING
601 DecodeStatus decodeBresserLightningPayload(
const uint8_t *msg, uint8_t msgSize);
603 #ifdef BRESSER_LEAKAGE
613 DecodeStatus decodeBresserLeakagePayload(
const uint8_t *msg, uint8_t msgSize);
620 uint16_t lfsr_digest16(uint8_t
const message[],
unsigned bytes, uint16_t gen, uint16_t key);
630 int add_bytes(uint8_t
const message[],
unsigned num_bytes);
642 uint16_t crc16(uint8_t
const message[],
unsigned nBytes, uint16_t polynomial, uint16_t init);
644 #if CORE_DEBUG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
656 void log_message(
const char *descr,
const uint8_t *msg, uint8_t msgSize) {
658 const char txt[] =
"Byte #: ";
660 int len1 = strlen(txt);
661 int len2 = strlen(descr) + 2;
662 int prefix_len = max(len1, len2);
664 memset(buf,
' ', prefix_len);
665 buf[prefix_len] =
'\0';
666 offs = (len1 < len2) ? (len2 - len1) : 0;
667 snprintf(&buf[offs],
sizeof(buf) - offs - 1,
"%s", txt);
670 for (
size_t i = 0 ; (i < msgSize) && (strlen(buf) <
sizeof(buf) - 4); i++) {
671 sprintf(&buf[strlen(buf)],
"%02d ", i);
675 memset(buf,
' ', prefix_len);
676 buf[prefix_len] =
'\0';
677 offs = (len1 > len2) ? (len1 - len2) : 0;
678 sprintf(&buf[offs],
"%s: ", descr);
680 for (
size_t i = 0 ; (i < msgSize) && (strlen(buf) <
sizeof(buf) - 4); i++) {
681 sprintf(&buf[strlen(buf)],
"%02X ", msg[i]);
Receive, decode and store Bresser Weather Sensor Data Uses CC1101 or SX1276 radio module for receivin...
Definition WeatherSensor.h:190
DecodeStatus getMessage(void)
Tries to receive radio message (non-blocking) and to decode it. Timeout occurs after a multitude of e...
Definition WeatherSensor.cpp:458
int findId(uint32_t id)
Definition WeatherSensor.cpp:565
uint8_t convSensorsJson(std::vector< uint32_t > &ids, String json, uint8_t *buf)
Definition WeatherSensorConfig.cpp:212
void radioReset(void)
Reset radio transceiver.
Definition WeatherSensor.cpp:368
uint8_t rxFlags
receive flags (see getData())
Definition WeatherSensor.h:354
float rssi
received signal strength indicator in dBm
Definition WeatherSensor.h:353
void getSensorsCfg(uint8_t &max_sensors, uint8_t &rx_flags, uint8_t &en_decoders)
Definition WeatherSensorConfig.cpp:277
bool getData(uint32_t timeout, uint8_t flags=0, uint8_t type=0, void(*func)()=NULL)
Wait for reception of data or occurrence of timeout. With BRESSER_6_IN_1, data is distributed across ...
Definition WeatherSensor.cpp:381
void setSensorsCfg(uint8_t max_sensors, uint8_t rx_flags, uint8_t en_decoders=0xFF)
Definition WeatherSensorConfig.cpp:248
uint8_t enDecoders
enabled Decoders
Definition WeatherSensor.h:355
String getSensorsIncJson(void)
Definition WeatherSensorConfig.cpp:200
void sleep(void)
Set transceiver into sleep mode.
Definition WeatherSensor.cpp:373
String getSensorsJson(std::vector< uint32_t > &ids)
Definition WeatherSensorConfig.cpp:173
void setRxCfg(uint8_t rx_flags, uint8_t en_decoders=0xFF)
Definition WeatherSensorConfig.cpp:264
void setSensorsIncJson(String json)
Definition WeatherSensorConfig.cpp:232
void setSensorsExcJson(String json)
Definition WeatherSensorConfig.cpp:240
int findType(uint8_t type, uint8_t channel=0xFF)
Definition WeatherSensor.cpp:578
uint8_t getSensorsInc(uint8_t *payload)
Definition WeatherSensorConfig.cpp:122
bool genMessage(int i, uint32_t id=0xff, uint8_t s_type=1, uint8_t channel=0, uint8_t startup=0)
Generates data otherwise received and decoded from a radio message.
Definition WeatherSensor.cpp:508
struct Sensor sensor_t
Shortcut for struct Sensor.
Definition WeatherSensor.h:351
String getSensorsExcJson(void)
Definition WeatherSensorConfig.cpp:206
std::vector< sensor_t > sensor
sensor data array
Definition WeatherSensor.h:352
void setSensorsInc(uint8_t *bytes, uint8_t size)
Definition WeatherSensorConfig.cpp:99
uint8_t getSensorsExc(uint8_t *payload)
Definition WeatherSensorConfig.cpp:159
void clearSlots(uint8_t type=0xFF)
Clear sensor data.
Definition WeatherSensor.h:373
int16_t begin(uint8_t max_sensors_default=MAX_SENSORS_DEFAULT, bool init_filters=true, int32_t frequency_offset=0)
Presence check and initialization of radio module.
Definition WeatherSensor.cpp:215
DecodeStatus decodeMessage(const uint8_t *msg, uint8_t msgSize)
Decode message Tries the available decoders until a decoding was successful.
Definition WeatherSensorDecoders.cpp:149
void setSensorsExc(uint8_t *bytes, uint8_t size)
Definition WeatherSensorConfig.cpp:136
Mapping of sensor IDs to names.
Definition WeatherSensor.h:178
String name
Name of sensor (e.g. for MQTT topic).
Definition WeatherSensor.h:180
uint32_t id
ID of sensor (as transmitted in radio message).
Definition WeatherSensor.h:179
Definition WeatherSensor.h:305
bool co2_init
measurement value invalid due to initialization
Definition WeatherSensor.h:307
uint16_t co2_ppm
CO2 concentration in ppm.
Definition WeatherSensor.h:306
Definition WeatherSensor.h:296
uint16_t pm_1_0
air quality PM1.0 in µg/m³
Definition WeatherSensor.h:297
bool pm_10_init
measurement value invalid due to initialization
Definition WeatherSensor.h:302
bool pm_2_5_init
measurement value invalid due to initialization
Definition WeatherSensor.h:301
uint16_t pm_2_5
air quality PM2.5 in µg/m³
Definition WeatherSensor.h:298
bool pm_1_0_init
measurement value invalid due to initialization
Definition WeatherSensor.h:300
uint16_t pm_10
air quality PM10 in µg/m³
Definition WeatherSensor.h:299
Definition WeatherSensor.h:310
bool hcho_init
measurement value invalid due to initialization
Definition WeatherSensor.h:313
uint8_t voc_level
volatile organic compounds; 1 - bad air quality .. 5 - very good air quality
Definition WeatherSensor.h:312
bool voc_init
measurement value invalid due to initialization
Definition WeatherSensor.h:314
uint16_t hcho_ppb
formaldehyde concentration in ppb
Definition WeatherSensor.h:311
Definition WeatherSensor.h:292
bool alarm
water leakage alarm (only water leakage)
Definition WeatherSensor.h:293
Definition WeatherSensor.h:284
uint16_t unknown1
unknown part 1
Definition WeatherSensor.h:287
uint8_t distance_km
lightning distance in km (only lightning)
Definition WeatherSensor.h:285
uint16_t unknown2
unknown part 2
Definition WeatherSensor.h:288
uint16_t strike_count
lightning strike counter (only lightning)
Definition WeatherSensor.h:286
sensor data and status flags
Definition WeatherSensor.h:322
bool battery_ok
battery o.k.
Definition WeatherSensor.h:329
float rssi
received signal strength indicator in dBm
Definition WeatherSensor.h:324
uint8_t decoder
decoder used
Definition WeatherSensor.h:327
bool complete
data is split into two separate messages is complete (only 6-in-1 WS)
Definition WeatherSensor.h:331
uint8_t s_type
sensor type
Definition WeatherSensor.h:325
bool startup
startup after reset / battery change
Definition WeatherSensor.h:328
uint32_t sensor_id
sensor ID (5-in-1: 1 byte / 6-in-1: 4 bytes / 7-in-1: 2 bytes)
Definition WeatherSensor.h:323
uint8_t chan
channel
Definition WeatherSensor.h:326
bool valid
data valid (but not necessarily complete)
Definition WeatherSensor.h:330
Definition WeatherSensor.h:279
float temp_c
temperature in degC
Definition WeatherSensor.h:280
uint8_t moisture
moisture in % (only 6-in-1)
Definition WeatherSensor.h:281
Definition WeatherSensor.h:249
float light_klx
Light KLux (only 7-in-1).
Definition WeatherSensor.h:259
bool light_ok
light o.k. (only 7-in-1)
Definition WeatherSensor.h:253
float light_lux
Light lux (only 7-in-1).
Definition WeatherSensor.h:260
float wind_direction_deg
wind direction in deg
Definition WeatherSensor.h:264
bool temp_ok
temperature o.k. (only 6-in-1)
Definition WeatherSensor.h:250
float temp_c
temperature in degC
Definition WeatherSensor.h:257
uint16_t wind_gust_meter_sec_fp1
wind speed (gusts) in m/s (fixed point int w. 1 decimal)
Definition WeatherSensor.h:273
uint16_t wind_avg_meter_sec_fp1
wind speed (avg) in m/s (fixed point int w. 1 decimal)
Definition WeatherSensor.h:274
uint8_t humidity
humidity in %
Definition WeatherSensor.h:276
float uv
uv radiation (only 6-in-1 & 7-in-1)
Definition WeatherSensor.h:261
bool humidity_ok
humidity o.k.
Definition WeatherSensor.h:252
bool wind_ok
wind speed/direction o.k. (only 6-in-1)
Definition WeatherSensor.h:255
uint16_t wind_direction_deg_fp1
wind direction in deg (fixed point int w. 1 decimal)
Definition WeatherSensor.h:272
bool uv_ok
uv radiation o.k. (only 6-in-1)
Definition WeatherSensor.h:254
float rain_mm
rain gauge level in mm
Definition WeatherSensor.h:262
float tglobe_c
globe temperature in degC (only 8-in-1)
Definition WeatherSensor.h:258
float wind_gust_meter_sec
wind speed (gusts) in m/s
Definition WeatherSensor.h:265
float wind_avg_meter_sec
wind speed (avg) in m/s
Definition WeatherSensor.h:266
bool rain_ok
rain gauge level o.k.
Definition WeatherSensor.h:256
bool tglobe_ok
globe temperature o.k. (only 8-in-1)
Definition WeatherSensor.h:251