|
BresserWeatherSensorLW
Bresser 868 MHz Weather Sensor Radio Receiver based on ESP32/RP2040 and SX1262/SX1276/LR1121 - sends data to a LoRaWAN Network
|
System context for BresserWeatherSensorLW. More...
#include <SystemContext.h>
Public Member Functions | |
| void | begin (void) |
| Initialize the system context. | |
| bool | isFirstBoot (void) |
| Check if this is the first boot of the system after power-on/HW reset. | |
| void | resetFailedJoinCount (void) |
| Reset the failed join count. | |
| void | sleepAfterFailedJoin (void) |
| Sleep after a failed join attempt. | |
| void | setTime (time_t epoch, E_TIME_SOURCE source) |
| Set RTC to epoch. | |
| void | printDateTime (void) |
| void | savePreferences (void) |
| Save preferences to flash memory. | |
| void | getVoltages (void) |
| Get the voltages from ADC / Power Management Chip. | |
| void | sleepIfSupplyLow (void) |
| Sleep if battery voltage is low to prevent deep-discharging. | |
| uint8_t | getBattlevel (void) |
| Get the battery fill level. | |
| uint8_t | getBattlevelDefault (void) |
| Get the battery fill level (default implementation). | |
| uint32_t | sleepInterval (void) |
| Switch between normal and long sleep interval. | |
| bool | longSleepActive (void) |
| Check if long sleep is active. | |
| bool | isRtcSynched (void) |
| Check if the RTC is synchronized to a time source. | |
| E_TIME_SOURCE | getRtcTimeSource (void) |
| Get the RTC time source. | |
| bool | rtcNeedsSync (void) |
| Check if the RTC needs to be synchronized to a time source. | |
| uint32_t | sleepDuration (void) |
| Compute sleep duration in seconds. | |
| void | uplinkDelay (uint32_t timeUntilUplink, uint32_t uplinkInterval) |
| LoRaWAN uplink delay. | |
| void | gotoSleep (uint32_t seconds) |
| Enter sleep mode. | |
System context for BresserWeatherSensorLW.
Handles system initialization and management for the LoRaWAN node. This includes hardware-specific setup, RTC management, and power-saving features.
| void SystemContext::begin | ( | void | ) |
Initialize the system context.
Initialize the system context

|
inline |
Get the battery fill level.
Wrapper for board specific implementations.
Get the battery fill level for LoRaWAN device status uplink. The LoRaWAN network server may periodically request this information.
0 = external power source 1 = lowest (empty battery) 254 = highest (full battery) 255 = unable to measure

|
inline |
Get the battery fill level (default implementation).
Get the battery fill level for LoRaWAN device status uplink. The LoRaWAN network server may periodically request this information.
0 = external power source 1 = lowest (empty battery) 254 = highest (full battery) 255 = unable to measure
| E_TIME_SOURCE SystemContext::getRtcTimeSource | ( | void | ) |
Get the RTC time source.
|
inline |
Get the voltages from ADC / Power Management Chip.
Bus voltage: Supply voltage (e.g. USB or external power) if available, otherwise battery voltage. If no voltage converter is used, the permitted voltage range is limited by the 3.3V LDO input range and by the connected 3.3V loads. Typically 5V nominal.
The bus voltage is evaluated to determine the state of the power supply.

|
inline |
Enter sleep mode.
On wake-up, the MCU will soft-reset and start from the beginning.
| seconds | Sleep duration in seconds |
| bool SystemContext::isFirstBoot | ( | void | ) |
Check if this is the first boot of the system after power-on/HW reset.
| bool SystemContext::isRtcSynched | ( | void | ) |
Check if the RTC is synchronized to a time source.
|
inline |
Check if long sleep is active.
Check if the sleep interval is set to the long sleep interval. This flag is sent in a LoRaWAN uplink message.

|
inline |
Print date and time (i.e. local time)
| void SystemContext::resetFailedJoinCount | ( | void | ) |
Reset the failed join count.
The failed join count is reset to 0 after a successful join.
| bool SystemContext::rtcNeedsSync | ( | void | ) |
Check if the RTC needs to be synchronized to a time source.
Checks if the RTC is synchronized to a time source
If the RTC is not synchronized or if the last clock sync is older than CLOCK_SYNC_INTERVAL, it returns true.
| void SystemContext::setTime | ( | time_t | epoch, |
| E_TIME_SOURCE | source ) |
Set RTC to epoch.
Set RTC to epoch and store source and RTC sync timestamp
| epoch | time in seconds since epoch |
| source | time source |
| void SystemContext::sleepAfterFailedJoin | ( | void | ) |
Sleep after a failed join attempt.
The sleep duration after a failed join is determined by the failed join count.

|
inline |
Compute sleep duration in seconds.
Minimum duration: SLEEP_INTERVAL_MIN If battery voltage is available and <= BATTERY_WEAK: sleep_interval_long else sleep_interval
Additionally, the sleep interval is reduced from the default value to achieve a wake-up time aligned to an integer multiple of the interval after a full hour.

|
inline |
Sleep if battery voltage is low to prevent deep-discharging.
Checks if the bus voltage has reached the shut-off threshold and enters sleep mode for battery deep-discharge protection.

| uint32_t SystemContext::sleepInterval | ( | void | ) |
Switch between normal and long sleep interval.
Switch between normal and long sleep interval depending on the system voltage (default) or battery state of charge (PowerFeather). The long sleep interval is used to save energy (eco mode). A hysteresis is implemented by using two voltage/SOC thresholds - <voltage|soc>_eco_exit and <voltage|soc>_eco_enter .
The normal sleep interval is used as default, e.g. if the system voltage/battery SOC is not available.
|
inline |
LoRaWAN uplink delay.
Uses MCU sleep mode if possible, otherwise delays for the given time.
| timeUntilUplink | time until next uplink in milliseconds |
| uplinkInterval | planned uplink interval in seconds |