Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions farmerbot/manager/power.v
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ fn (mut p PowerManager) poweron_all_nodes() {
}

fn (mut p PowerManager) periodic_wakeup() {
now := time.now()
// convert time to utc to avoid daylight saving issues
now := time.now().local_to_utc()
today := time.new_time(year: now.year, month: now.month, day: now.day)
periodic_wakeup_start := today.add(p.db.periodic_wakeup_start)
mut amount_wakeup_calls := 0
Expand All @@ -88,7 +89,7 @@ fn (mut p PowerManager) periodic_wakeup() {
if now.day == 1 && now.hour == 1 && now.minute >= 0 && now.minute < 5 {
node.times_random_wakeups = 0
}
if periodic_wakeup_start <= now && node.last_time_awake < periodic_wakeup_start {
if periodic_wakeup_start <= now && node.last_time_awake.local_to_utc() < periodic_wakeup_start {
// Fixed periodic wakeup (once a day)
// we wakeup the node if the periodic wakeup start time has started and only if the last time the node was awake
// was before the periodic wakeup start of that day
Expand Down Expand Up @@ -306,8 +307,16 @@ fn (mut p PowerManager) configure(mut action actions.Action) ! {
periodic_wakeup_limit = system.default_periodic_wakeup_limit
p.logger.warn('${manager.power_manager_prefix} The setting periodic_wakeup_limit should be greater then 0!')
}

periodic_wakeup_start_utc = convert_to_utc(periodic_wakeup_start)
p.db.wake_up_threshold = wake_up_threshold
p.db.periodic_wakeup_start = periodic_wakeup_start
p.db.periodic_wakeup_start = periodic_wakeup_start_utc
p.db.periodic_wakeup_limit = periodic_wakeup_limit
}


fn convert_to_utc(d Duration) Duration{
now := time.now()
today := time.new_time(year: now.year, month: now.month, day: now.day)
daily_wakeup := today.add(d).local_to_utc()
return Duration(daily_wakeup.hour * time.hour + daily_wakeup.minute * time.minute)
}