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
SystemContext Class Reference

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.

Public Attributes

uint16_t sleep_interval
 preferences: sleep interval
uint16_t sleep_interval_long
 preferences: sleep interval long
uint8_t lw_stat_interval
 preferences: LoRaWAN node status uplink interval

Detailed Description

System context for BresserWeatherSensorLW.

Handles system initialization and management for the LoRaWAN node. This includes hardware-specific setup, RTC management, and power-saving features.

Member Function Documentation

◆ begin()

void SystemContext::begin ( void )

Initialize the system context.

Initialize the system context

  • MCU / board specific initialization
  • Load node configuration from JSON file
  • Load preferences from flash memory
  • Initialize RTC and time zone
Here is the call graph for this function:

◆ getBattlevel()

uint8_t SystemContext::getBattlevel ( void )
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

Here is the call graph for this function:

◆ getBattlevelDefault()

uint8_t SystemContext::getBattlevelDefault ( void )
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

◆ getRtcTimeSource()

E_TIME_SOURCE SystemContext::getRtcTimeSource ( void )

Get the RTC time source.

Returns
E_TIME_SOURCE current RTC time source

◆ getVoltages()

void SystemContext::getVoltages ( void )
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.

Here is the call graph for this function:

◆ gotoSleep()

void SystemContext::gotoSleep ( uint32_t seconds)
inline

Enter sleep mode.

On wake-up, the MCU will soft-reset and start from the beginning.

Parameters
secondsSleep duration in seconds

◆ isFirstBoot()

bool SystemContext::isFirstBoot ( void )

Check if this is the first boot of the system after power-on/HW reset.

Returns
true First boot after power-on/HW reset
false Not the first boot

◆ isRtcSynched()

bool SystemContext::isRtcSynched ( void )

Check if the RTC is synchronized to a time source.

Returns
true if the RTC is synchronized to a time source
false if the RTC is not synchronized

◆ longSleepActive()

bool SystemContext::longSleepActive ( void )
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.

Returns
true if long sleep is active
false if long sleep is not active
Here is the call graph for this function:

◆ printDateTime()

void SystemContext::printDateTime ( void )
inline

Print date and time (i.e. local time)

◆ resetFailedJoinCount()

void SystemContext::resetFailedJoinCount ( void )

Reset the failed join count.

The failed join count is reset to 0 after a successful join.

◆ rtcNeedsSync()

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.

Returns
true if the RTC needs to be synchronized
false if the RTC is synchronized and the last clock sync is within CLOCK_SYNC_INTERVAL

◆ setTime()

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

Parameters
epochtime in seconds since epoch
sourcetime source

◆ sleepAfterFailedJoin()

void SystemContext::sleepAfterFailedJoin ( void )

Sleep after a failed join attempt.

The sleep duration after a failed join is determined by the failed join count.

Here is the call graph for this function:

◆ sleepDuration()

uint32_t SystemContext::sleepDuration ( void )
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.

Returns
sleep duration in seconds
Here is the call graph for this function:

◆ sleepIfSupplyLow()

void SystemContext::sleepIfSupplyLow ( void )
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.

Here is the call graph for this function:

◆ sleepInterval()

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.

◆ uplinkDelay()

void SystemContext::uplinkDelay ( uint32_t timeUntilUplink,
uint32_t uplinkInterval )
inline

LoRaWAN uplink delay.

Uses MCU sleep mode if possible, otherwise delays for the given time.

Parameters
timeUntilUplinktime until next uplink in milliseconds
uplinkIntervalplanned uplink interval in seconds

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