I'm thinking about adding sunrise and sunset to NTP events, anyone interested? Attached is a patch that I haven't tried yet. Any feedback is greatly appreciated.
Rick
Czy wolisz polską wersję strony elektroda?
Nie, dziękuję Przekieruj mnie tam
waitFor NTPState 1
https://github.com/rickbronson/OpenBK7231T_App/
TL;DR: Field tests show the OpenBK sunrise/sunset scheduler stays within ±2 minutes of official tables ("good enough for us" [Elektroda, rickbronson, post #20823018]) and later self-tests cut the error to ±1 minute [Elektroda, p.kaczmarek2, post #20869623]
Why it matters: Accurate, timezone-aware switching lets IoT lights follow natural daylight without cloud services.
ntp_SetLatlong <lat> <long> merges latitude & longitude [Elektroda, p.kaczmarek2, post #20819240]#define OBK_ENABLE_SUN_EVENTS [Elektroda, p.kaczmarek2, post #20869378]#define OBK_ENABLE_SUN_EVENTS inside obk_config.h. Re-compile with that flag set, or flash a nightly image after 2023-12-20 where the flag is already enabled [Elektroda, p.kaczmarek2, post #20869378]#ifdef OBK_ENABLE_SUN_EVENTS around the code or strip unused math symbols to reclaim space during builds [Elektroda, p.kaczmarek2, post #20843876]autoexec.bat.ntp_timeZoneOfs with your own values.
PowerSave 1
startDriver ntp
ntp_timeZoneOfs -8
ntp_SetLatlong 44.002130 -123.091473
waitFor NTPState 1
removeClockEvent 12; removeClockEvent 13
addClockEvent sunrise 0x7f 12 POWER2 OFF
addClockEvent sunset 0x7f 13 POWER2 ON
The waitFor line guarantees correct timezone before scheduling [Elektroda, p.kaczmarek2, post #20823027]
addClockEvent sunset 0xff 21 backlog addRepeatingEvent 1800 1 POWER2 ON
1800 seconds = 30 minutes. Limitation: if the device reboots during the delay the queued event is lost [Elektroda, p.kaczmarek2, post #20879370]$hour with $sunrise_hour and $sunset_hour. If current time is between sunset and sunrise, issue POWER2 ON; else POWER2 OFF. Save manual overrides with LFS_WriteStr and read them during boot to skip auto-correction when the user toggled the light [Elektroda, ilengyel, post #20971275]openshwprojects/OpenBK7231T_App on GitHub.git push origin my_branch).#ifdef-ed the feature to avoid >20 kB growth on that MCU [Elektroda, w2q, post #21389444] If you enable it, use fixed-point math or link a lightweight trig library.ntp_SetLatlong to save command table entries and flash space [Elektroda, p.kaczmarek2, post #20819240]autoexec.bat, so downgrades are safe [Elektroda, p.kaczmarek2, post #20846866]