98#ifndef WeatherSensor_h
99#define WeatherSensor_h
104#include <Preferences.h>
106#include "WeatherSensorCfg.h"
110namespace WeatherSensorReceiver {
111 extern RADIO_CHIP radio;
131#define SENSOR_TYPE_WEATHER0 0
132#define SENSOR_TYPE_WEATHER1 1
133#define SENSOR_TYPE_THERMO_HYGRO 2
134#define SENSOR_TYPE_POOL_THERMO 3
135#define SENSOR_TYPE_SOIL 4
136#define SENSOR_TYPE_LEAKAGE 5
137#define SENSOR_TYPE_AIR_PM 8
138#define SENSOR_TYPE_RAIN 9
139#define SENSOR_TYPE_LIGHTNING 9
140#define SENSOR_TYPE_CO2 10
141#define SENSOR_TYPE_HCHO_VOC 11
142#define SENSOR_TYPE_WEATHER3 12
143#define SENSOR_TYPE_WEATHER8 13
147#define WEATHER0_RAIN_OV 1000
148#define WEATHER1_RAIN_OV 100000
152#define DATA_COMPLETE 0x1
154#define DATA_ALL_SLOTS 0x8
157#define DECODER_5IN1 0x01
158#define DECODER_6IN1 0x02
159#define DECODER_7IN1 0x04
160#define DECODER_LIGHTNING 0x08
161#define DECODER_LEAKAGE 0x10
164#define MSG_BUF_SIZE 27
167typedef enum DecodeStatus {
168 DECODE_INVALID, DECODE_OK, DECODE_PAR_ERR, DECODE_CHK_ERR, DECODE_DIG_ERR, DECODE_SKIP, DECODE_FULL
191 Preferences cfgPrefs;
192 std::vector<uint32_t> sensor_ids_inc;
193 std::vector<uint32_t> sensor_ids_exc;
201 int16_t
begin(uint8_t max_sensors_default = MAX_SENSORS_DEFAULT,
bool init_filters =
true,
double frequency_offset = 0.0);
229 bool getData(uint32_t timeout, uint8_t flags = 0, uint8_t type = 0,
void (*func)() = NULL);
246 DecodeStatus
decodeMessage(
const uint8_t *msg, uint8_t msgSize);
262 #ifdef WIND_DATA_FLOATINGPOINT
267 #ifdef WIND_DATA_FIXEDPOINT
343 #pragma GCC diagnostic push
344 #pragma GCC diagnostic ignored "-Wclass-memaccess"
345 memset(
this, 0,
sizeof(*
this));
346 #pragma GCC diagnostic pop
361 bool genMessage(
int i, uint32_t
id = 0xff, uint8_t s_type = 1, uint8_t channel = 0, uint8_t startup = 0);
374 for (
size_t i=0; i<
sensor.size(); i++) {
375 if ((type == 0xFF) || (
sensor[i].s_type == type)) {
377 sensor[i].complete =
false;
379 if (
sensor[i].s_type == SENSOR_TYPE_WEATHER1) {
380 sensor[i].w.temp_ok =
false;
381 sensor[i].w.humidity_ok =
false;
382 sensor[i].w.light_ok =
false;
383 sensor[i].w.uv_ok =
false;
384 sensor[i].w.wind_ok =
false;
385 sensor[i].w.rain_ok =
false;
408 int findType(uint8_t type, uint8_t channel = 0xFF);
433 void setSensorsCfg(uint8_t max_sensors, uint8_t rx_flags, uint8_t en_decoders = 0xFF);
441 void setRxCfg(uint8_t rx_flags, uint8_t en_decoders = 0xFF);
470 uint8_t
convSensorsJson(std::vector<uint32_t> &ids, String json, uint8_t *buf);
516 void getSensorsCfg(uint8_t &max_sensors, uint8_t &rx_flags, uint8_t &en_decoders);
519 struct Sensor *pData;
530 void initList(std::vector<uint32_t> &list,
const std::vector<uint32_t> list_def,
const char *key);
549 int findSlot(uint32_t
id, DecodeStatus * status);
552 #ifdef BRESSER_5_IN_1
562 DecodeStatus decodeBresser5In1Payload(
const uint8_t *msg, uint8_t msgSize);
564 #ifdef BRESSER_6_IN_1
576 DecodeStatus decodeBresser6In1Payload(
const uint8_t *msg, uint8_t msgSize);
578 #ifdef BRESSER_7_IN_1
588 DecodeStatus decodeBresser7In1Payload(
const uint8_t *msg, uint8_t msgSize);
590 #ifdef BRESSER_LIGHTNING
600 DecodeStatus decodeBresserLightningPayload(
const uint8_t *msg, uint8_t msgSize);
602 #ifdef BRESSER_LEAKAGE
612 DecodeStatus decodeBresserLeakagePayload(
const uint8_t *msg, uint8_t msgSize);
619 uint16_t lfsr_digest16(uint8_t
const message[],
unsigned bytes, uint16_t gen, uint16_t key);
629 int add_bytes(uint8_t
const message[],
unsigned num_bytes);
641 uint16_t crc16(uint8_t
const message[],
unsigned nBytes, uint16_t polynomial, uint16_t init);
643 #if CORE_DEBUG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
655 void log_message(
const char *descr,
const uint8_t *msg, uint8_t msgSize) {
657 const char txt[] =
"Byte #: ";
659 int len1 = strlen(txt);
660 int len2 = strlen(descr) + 2;
661 int prefix_len = max(len1, len2);
663 memset(buf,
' ', prefix_len);
664 buf[prefix_len] =
'\0';
665 offs = (len1 < len2) ? (len2 - len1) : 0;
666 snprintf(&buf[offs],
sizeof(buf) - offs - 1,
"%s", txt);
669 for (
size_t i = 0 ; (i < msgSize) && (strlen(buf) <
sizeof(buf) - 4); i++) {
670 sprintf(&buf[strlen(buf)],
"%02d ", i);
674 memset(buf,
' ', prefix_len);
675 buf[prefix_len] =
'\0';
676 offs = (len1 > len2) ? (len1 - len2) : 0;
677 sprintf(&buf[offs],
"%s: ", descr);
679 for (
size_t i = 0 ; (i < msgSize) && (strlen(buf) <
sizeof(buf) - 4); i++) {
680 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:189
DecodeStatus getMessage(void)
Tries to receive radio message (non-blocking) and to decode it. Timeout occurs after a multitude of e...
Definition WeatherSensor.cpp:454
int findId(uint32_t id)
Definition WeatherSensor.cpp:561
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:364
uint8_t rxFlags
receive flags (see getData())
Definition WeatherSensor.h:353
float rssi
received signal strength indicator in dBm
Definition WeatherSensor.h:352
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:377
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:354
String getSensorsIncJson(void)
Definition WeatherSensorConfig.cpp:200
void sleep(void)
Set transceiver into sleep mode.
Definition WeatherSensor.cpp:369
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:574
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:504
String getSensorsExcJson(void)
Definition WeatherSensorConfig.cpp:206
std::vector< sensor_t > sensor
sensor data array
Definition WeatherSensor.h:351
int16_t begin(uint8_t max_sensors_default=MAX_SENSORS_DEFAULT, bool init_filters=true, double frequency_offset=0.0)
Presence check and initialization of radio module.
Definition WeatherSensor.cpp:214
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:372
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:177
String name
Name of sensor (e.g. for MQTT topic)
Definition WeatherSensor.h:179
uint32_t id
ID of sensor (as transmitted in radio message)
Definition WeatherSensor.h:178
Definition WeatherSensor.h:304
bool co2_init
measurement value invalid due to initialization
Definition WeatherSensor.h:306
uint16_t co2_ppm
CO2 concentration in ppm.
Definition WeatherSensor.h:305
Definition WeatherSensor.h:295
uint16_t pm_1_0
air quality PM1.0 in µg/m³
Definition WeatherSensor.h:296
bool pm_10_init
measurement value invalid due to initialization
Definition WeatherSensor.h:301
bool pm_2_5_init
measurement value invalid due to initialization
Definition WeatherSensor.h:300
uint16_t pm_2_5
air quality PM2.5 in µg/m³
Definition WeatherSensor.h:297
bool pm_1_0_init
measurement value invalid due to initialization
Definition WeatherSensor.h:299
uint16_t pm_10
air quality PM10 in µg/m³
Definition WeatherSensor.h:298
Definition WeatherSensor.h:309
bool hcho_init
measurement value invalid due to initialization
Definition WeatherSensor.h:312
uint8_t voc_level
volatile organic compounds; 1 - bad air quality .. 5 - very good air quality
Definition WeatherSensor.h:311
bool voc_init
measurement value invalid due to initialization
Definition WeatherSensor.h:313
uint16_t hcho_ppb
formaldehyde concentration in ppb
Definition WeatherSensor.h:310
Definition WeatherSensor.h:291
bool alarm
water leakage alarm (only water leakage)
Definition WeatherSensor.h:292
Definition WeatherSensor.h:283
uint16_t unknown1
unknown part 1
Definition WeatherSensor.h:286
uint8_t distance_km
lightning distance in km (only lightning)
Definition WeatherSensor.h:284
uint16_t unknown2
unknown part 2
Definition WeatherSensor.h:287
uint16_t strike_count
lightning strike counter (only lightning)
Definition WeatherSensor.h:285
sensor data and status flags
Definition WeatherSensor.h:321
bool battery_ok
battery o.k.
Definition WeatherSensor.h:328
float rssi
received signal strength indicator in dBm
Definition WeatherSensor.h:323
uint8_t decoder
decoder used
Definition WeatherSensor.h:326
bool complete
data is split into two separate messages is complete (only 6-in-1 WS)
Definition WeatherSensor.h:330
uint8_t s_type
sensor type
Definition WeatherSensor.h:324
bool startup
startup after reset / battery change
Definition WeatherSensor.h:327
uint32_t sensor_id
sensor ID (5-in-1: 1 byte / 6-in-1: 4 bytes / 7-in-1: 2 bytes)
Definition WeatherSensor.h:322
uint8_t chan
channel
Definition WeatherSensor.h:325
bool valid
data valid (but not necessarily complete)
Definition WeatherSensor.h:329
Definition WeatherSensor.h:278
float temp_c
temperature in degC
Definition WeatherSensor.h:279
uint8_t moisture
moisture in % (only 6-in-1)
Definition WeatherSensor.h:280
Definition WeatherSensor.h:248
float light_klx
Light KLux (only 7-in-1)
Definition WeatherSensor.h:258
bool light_ok
light o.k. (only 7-in-1)
Definition WeatherSensor.h:252
float light_lux
Light lux (only 7-in-1)
Definition WeatherSensor.h:259
float wind_direction_deg
wind direction in deg
Definition WeatherSensor.h:263
bool temp_ok
temperature o.k. (only 6-in-1)
Definition WeatherSensor.h:249
float temp_c
temperature in degC
Definition WeatherSensor.h:256
uint16_t wind_gust_meter_sec_fp1
wind speed (gusts) in m/s (fixed point int w. 1 decimal)
Definition WeatherSensor.h:272
uint16_t wind_avg_meter_sec_fp1
wind speed (avg) in m/s (fixed point int w. 1 decimal)
Definition WeatherSensor.h:273
uint8_t humidity
humidity in %
Definition WeatherSensor.h:275
float uv
uv radiation (only 6-in-1 & 7-in-1)
Definition WeatherSensor.h:260
bool humidity_ok
humidity o.k.
Definition WeatherSensor.h:251
bool wind_ok
wind speed/direction o.k. (only 6-in-1)
Definition WeatherSensor.h:254
uint16_t wind_direction_deg_fp1
wind direction in deg (fixed point int w. 1 decimal)
Definition WeatherSensor.h:271
bool uv_ok
uv radiation o.k. (only 6-in-1)
Definition WeatherSensor.h:253
float rain_mm
rain gauge level in mm
Definition WeatherSensor.h:261
float tglobe_c
globe temperature in degC (only 8-in-1)
Definition WeatherSensor.h:257
float wind_gust_meter_sec
wind speed (gusts) in m/s
Definition WeatherSensor.h:264
float wind_avg_meter_sec
wind speed (avg) in m/s
Definition WeatherSensor.h:265
bool rain_ok
rain gauge level o.k.
Definition WeatherSensor.h:255
bool tglobe_ok
globe temperature o.k. (only 8-in-1)
Definition WeatherSensor.h:250