BresserWeatherSensorLW
Bresser 868 MHz Weather Sensor Radio Receiver based on ESP32/RP2040 and SX1262/SX1276/LR1121 - sends data to a LoRaWAN Network
Loading...
Searching...
No Matches
PayloadBresser.h
Go to the documentation of this file.
1
2// PayloadBresser.h
3//
4// Read Bresser sensor data and encode as LoRaWAN payload
5//
6// created: 05/2024
7//
8//
9// MIT License
10//
11// Copyright (c) 2025 Matthias Prinke
12//
13// Permission is hereby granted, free of charge, to any person obtaining a copy
14// of this software and associated documentation files (the "Software"), to deal
15// in the Software without restriction, including without limitation the rights
16// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17// copies of the Software, and to permit persons to whom the Software is
18// furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included in all
21// copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29// SOFTWARE.
30//
31//
32// History:
33//
34// 20240521 Created
35// 20240523 Added encodeWeatherSensor(),
36// added defines for signalling invalid data
37// 20240524 Moved rainGauge, appPrefs and time members from AppLayer
38// into the class
39// Added isSpaceLeft(), payloadSize[] & sensorTypes[]
40// 20240528 Moved encoding of invalid values to BresserWeatherSensorLWCmd.h
41// 20240530 Added missing entries in sensorTypes[]
42// 20240603 encodeBresser(): added appStatus parameter
43// 20240716 Added ws_scantime and scanBresser()
44// 20250209 Added Weather Station 8-in-1
45// 20250318 Renamed PAYLOAD_SIZE to MAX_UPLINK_SIZE
46// 20250828 Changed time functions to POSIX, added SystemContext
47// Added ws_postproc_int
48//
49// ToDo:
50// -
51//
53
57
58#if !defined(_PAYLOAD_BRESSER)
59#define _PAYLOAD_BRESSER
60
61#include "../BresserWeatherSensorLWCfg.h"
62#include "WeatherSensorCfg.h"
63#include <WeatherSensor.h>
64#include <time.h>
65#include <Preferences.h>
66
67#ifdef RAINDATA_EN
68#include "RainGauge.h"
69#endif
70#ifdef LIGHTNINGSENSOR_EN
71#include "Lightning.h"
72#endif
73
74#include <LoraMessage.h>
75#include "SystemContext.h"
76#include "logging.h"
77
78
85{
86public:
88 WeatherSensor weatherSensor;
89
91 uint8_t ws_scantime = 0;
92
95
97 const uint8_t payloadSize[16] = {
98 0,
99 25, // SENSOR_TYPE_WEATHER<0|1|2> (max.)
100 3, // SENSOR_TYPE_THERMO_HYGRO
101 2, // SENSOR_TYPE_POOL_THERMO
102 3, // SENSOR_TYPE_SOIL
103 1, // SENSOR_TYPE_LEAKAGE
104 0, // reserved
105 0, // reserved
106 6, // SENSOR_TYPE_AIR_PM
107 3, // SENSOR_TYPE_LIGHTNING (min.)
108 2, // SENSOR_TYPE_CO2
109 3, // SENSOR_TYPE_HCHO_VOC
110 0, // reserved
111 0, // (Weather Station 8-in-1, included in [1])
112 0, // reserved
113 0 // reserved
114 };
115
116#if CORE_DEBUG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
118 const char * sensorTypes[16] = {
119 "Weather",
120 "Weather",
121 "Thermo/Hygro",
122 "Pool Temperature",
123 "Soil",
124 "Leakage",
125 "reserved",
126 "reserved",
127 "Air Quality (PM)",
128 "Lightning",
129 "CO2",
130 "Air Quality (HCHO/VOC)",
131 "reserved",
132 "Weather", // Weather Station 8-in-1
133 "reserved",
134 "reserved"
135 };
136#endif
137
138private:
140 SystemContext *_sysCtx;
141
143 Preferences appPrefs;
144
145
146#ifdef RAINDATA_EN
147public:
149 RainGauge rainGauge;
150#endif
151
152#ifdef LIGHTNINGSENSOR_EN
153public:
155 Lightning lightningProc;
156
157private:
158 time_t lightn_ts;
159 int lightn_events;
160 uint8_t lightn_distance;
161#endif
162
163public:
168 {
169 _sysCtx = sysCtx;
170 };
171
175 void begin(void);
176
183 void scanBresser(uint8_t ws_scantime, LoraEncoder &encoder);
184
192 void encodeBresser(uint8_t *appPayloadCfg, uint8_t *appStatus, LoraEncoder &encoder);
193
194private:
195 void encodeWeatherSensor(int idx, uint16_t flags, LoraEncoder &encoder);
196 void encodeThermoHygroSensor(int idx, LoraEncoder &encoder);
197 void encodePoolThermometer(int idx, LoraEncoder &encoder);
198 void encodeSoilSensor(int idx, LoraEncoder &encoder);
199 void encodeLeakageSensor(int idx, LoraEncoder &encoder);
200 void encodeAirPmSensor(int idx, LoraEncoder &encoder);
201#ifdef LIGHTNINGSENSOR_EN
202 void encodeLightningSensor(int idx, uint8_t flags, LoraEncoder &encoder);
203#endif
204 void encodeCo2Sensor(int idx, LoraEncoder &encoder);
205 void encodeHchoVocSensor(int idx, LoraEncoder &encoder);
206
207 bool isSpaceLeft(LoraEncoder &encoder, uint8_t type)
208 {
209 return (encoder.getLength() + payloadSize[type] <= MAX_UPLINK_SIZE);
210 };
211};
212#endif //_PAYLOAD_BRESSER
System context for BresserWeatherSensorLW.
void encodeBresser(uint8_t *appPayloadCfg, uint8_t *appStatus, LoraEncoder &encoder)
Encode Bresser sensor data for LoRaWAN transmission.
Definition PayloadBresser.cpp:166
uint8_t ws_postproc_interval
Weather Sensor Post-Processing Update Rate (0: auto, 1..255: minutes).
Definition PayloadBresser.h:94
void scanBresser(uint8_t ws_scantime, LoraEncoder &encoder)
Scan for Bresser sensors.
Definition PayloadBresser.cpp:100
const char * sensorTypes[16]
Map sensor type ID to name.
Definition PayloadBresser.h:118
PayloadBresser(SystemContext *sysCtx)
Constructor.
Definition PayloadBresser.h:167
uint8_t ws_scantime
Weather Sensor Scan Request.
Definition PayloadBresser.h:91
WeatherSensor weatherSensor
Bresser Weather Sensor Receiver.
Definition PayloadBresser.h:88
RainGauge rainGauge
Rain data statistics.
Definition PayloadBresser.h:149
Lightning lightningProc
Lightning sensor post-processing.
Definition PayloadBresser.h:155
void begin(void)
Bresser sensors startup code.
Definition PayloadBresser.cpp:64
const uint8_t payloadSize[16]
Payload size in bytes per sensor type.
Definition PayloadBresser.h:97
System context for BresserWeatherSensorLW.
Definition SystemContext.h:95
Replacement for esp32-hal-log.h on RP20240.