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
Loading...
Searching...
No Matches
RainGauge Class Reference

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 int quality_threshold=DEFAULT_QUALITY_THRESHOLD)
 
void set_max (float raingauge_max)
 
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 *quality=nullptr)
 
float currentDay (void)
 
float currentWeek (void)
 
float currentMonth (void)
 

Detailed Description

Calculation of hourly (past 60 minutes), daily, weekly and monthly rainfall.

Additionally overflow of the rain gauge is handled when reaching RAINGAUGE_MAX_VALUE.

Constructor & Destructor Documentation

◆ RainGauge()

RainGauge::RainGauge ( const float  raingauge_max = RAINGAUGE_MAX_VALUE,
const int  quality_threshold = DEFAULT_QUALITY_THRESHOLD 
)
inline

Constructor

Parameters
raingauge_maxraingauge value which causes a counter overflow
quality_thresholdnumber of valid rain_hist entries required for valid pastHour() result

Member Function Documentation

◆ currentDay()

float RainGauge::currentDay ( void  )

Rainfall of current calendar day

Returns
amount of rain

◆ currentMonth()

float RainGauge::currentMonth ( void  )

Rainfall of current calendar month

Returns
amount of rain

◆ currentWeek()

float RainGauge::currentWeek ( void  )

Rainfall of current calendar week

Returns
amount of rain

◆ hist_init()

void RainGauge::hist_init ( int16_t  rain = -1)

Initialize history buffer for hourly (past 60 minutes) rainfall

◆ pastHour()

float RainGauge::pastHour ( bool *  valid = nullptr,
int *  quality = nullptr 
)

Rainfall during past 60 minutes

Parameters
validnumber of valid entries in rain_hist >= qualityThreshold
qualitynumber of valid entries in rain_hist
Returns
amount of rain during past 60 minutes

◆ reset()

void RainGauge::reset ( uint8_t  flags = 0xF)

Reset non-volatile data and current rain counter value

Parameters
flagsFlags defining what to reset:

◆ set_max()

void RainGauge::set_max ( float  raingauge_max)
inline

Set maximum rain counter value

Parameters
raingauge_maxraingauge value which causes a counter overflow

◆ update()

RainGauge::update ( time_t  ts,
float  rain,
bool  startup = false 
)

Update rain gauge statistics.

Parameters
tstimestamp
rainrain gauge raw value (in mm/m²)
startupsensor 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 / RAINGAUGE_UPD_RATE
* - 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 / RAINGAUGE_UPD_RATE
*
* - 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.
* 

The documentation for this class was generated from the following files: