BresserWeatherSensorReceiver
Bresser 5-in-1/6-in-1/7-in-1 868 MHz Weather Sensor Radio Receiver for Arduino based on CC1101 or SX1276/RFM95W
|
Calculation of hourly (past 60 minutes), daily, weekly and monthly rainfall. More...
#include <RainGauge.h>
Public Member Functions | |
RainGauge (const float raingauge_max=RAINGAUGE_MAX_VALUE, const float quality_threshold=DEFAULT_QUALITY_THRESHOLD) | |
void | set_max (float raingauge_max) |
void | setUpdateRate (uint8_t rate=RAINGAUGE_UPD_RATE) |
Set expected update rate for pastHour() calculation. | |
void | reset (uint8_t flags=0xF) |
void | hist_init (int16_t rain=-1) |
void | update (time_t ts, float rain, bool startup=false) |
Update rain gauge statistics. | |
float | pastHour (bool *valid=nullptr, int *nbins=nullptr, float *quality=nullptr) |
float | currentDay (void) |
float | currentWeek (void) |
float | currentMonth (void) |
Calculation of hourly (past 60 minutes), daily, weekly and monthly rainfall.
Additionally overflow of the rain gauge is handled when reaching RAINGAUGE_MAX_VALUE.
|
inline |
Constructor
raingauge_max | raingauge value which causes a counter overflow |
quality_threshold | fraction of valid rain_hist entries required for valid pastHour() result |
float RainGauge::currentDay | ( | void | ) |
Rainfall of current calendar day
float RainGauge::currentMonth | ( | void | ) |
Rainfall of current calendar month
float RainGauge::currentWeek | ( | void | ) |
Rainfall of current calendar week
void RainGauge::hist_init | ( | int16_t | rain = -1 | ) |
Initialize history buffer for hourly (past 60 minutes) rainfall
float RainGauge::pastHour | ( | bool * | valid = nullptr , |
int * | nbins = nullptr , |
||
float * | quality = nullptr |
||
) |
Rainfall during past 60 minutes
valid | number of valid entries in rain_hist >= qualityThreshold * 60 / updateRate |
nbins | number of valid entries in rain_hist |
quality | fraction of valid entries in rain_hist (0..1); quality = nbins / (60 / updateRate) |
void RainGauge::reset | ( | uint8_t | flags = 0xF | ) |
Reset non-volatile data and current rain counter value
flags | Flags defining what to reset: |
|
inline |
Set maximum rain counter value
raingauge_max | raingauge value which causes a counter overflow |
|
inline |
Set expected update rate for pastHour() calculation.
RAIN_HIST_SIZE: number of entries in rain_hist[] updateRate: update rate in minutes
60 minutes / updateRate = no_of_hist_bins The resulting number of history bins must be an integer value which does not exceed RAIN_HIST_SIZE.
Examples:
Changing the update rate will reset the history buffer, therefore the caller should avoid frequent changes.
Actual update intervals shorter than updateRate will lead to a reduced resolution of the pastHour() result and a higher risk of an invalid result if a bin in the history buffer was missed.
Actual update intervals longer than updateRate will lead to an invalid result, because bins in the history buffer will be missed.
rate | update rate in minutes (default: 6) |
RainGauge::update | ( | time_t | ts, |
float | rain, | ||
bool | startup = false |
||
) |
Update rain gauge statistics.
ts | timestamp |
rain | rain gauge raw value (in mm/m²) |
startup | sensor startup flag |
* Total rainfall during past 60 minutes * -------------------------------------- * * In each update(): * - timestamp (time_t) -> t (localtime, struct tm) * - calculate index into hist[]: idx = t.tm_min / updateRate * - expired time since last update: t_delta = timestamp - nvData.lastUpdate * - amount of rain since last update: rainDelta = rainCurr - nvData.rainPrev * - t_delta * < 0: something is wrong, e.g. RTC was not set correctly -> ignore, return * t_delta < expected update rate: * idx same as in previous cycle: hist[idx] += rainDelta * idx changed by 1: hist[idx] = rainDelta * t_delta >= history size: mark all history entries as invalid * else (index changed > 1): mark all history entries in interval [expected_index, current_index) as invalid * hist[idx] = rainDelta * * --------------- ----------- * | | | | |...| | | | hist[RAIN_HIST_SIZE] * --------------- ----------- * ^ * | * idx = t.tm_min / updateRate * * - Calculate hourly rate: * pastHour = sum of all valid hist[] entries * * Notes: * - rainDelta values (floating point with resolution of 0.1) are stored as integers to reduce memory consumption. * To avoid rounding errors, the rainDelta values are multiplied by 100 for conversion to integer. *