logo elektroda
logo elektroda
X
logo elektroda

[BK7231N] I'm thinking about adding sunrise and sunset to NTP events, anyone interested?

rickbronson 5784 60

Best answers

Yes—sunrise/sunset support was implemented, tested, and later merged, with Rick reporting it fully functional and the maintainer confirming the merge [#20906485][#20869378] Use it in `autoexec.bat` after NTP is ready, e.g. `waitFor NTPState 1`, then `ntp_SetLatLong `, and finally `addClockEvent sunrise ...` / `addClockEvent sunset ...` [#20828244] The feature was reported as accurate to about ±1 to ±2 minutes, which was considered acceptable for this use case [#20869623][#20870355] To avoid startup/timezone issues, the thread recommends keeping the sunrise/sunset code behind a `#define` in `obk_config.h` and using globals/statics instead of adding new config-structure fields [#20843876] If you want a delayed “civil sunset” style action, the simplest workaround suggested was `addRepeatingEvent` with a 30-minute delay after the sunrise/sunset trigger, though that would not survive a reboot during the delay [#20879370]
ADVERTISEMENT
  • #61 21753729
    divadiow
    Level 38  
    I don't know if this is correct, but the chatgpt-codex-connector bot just sent me this suggestion after I updated my branch

    In src/driver/drv_ntp_events.c:
    Code: C / C++
    Log in, to see the code


    DST fix drives sunrise events out of range
    When fix_DSTforEvents shifts all future sun events by hours, it simply does e->hour += hours (line 179). If the DST change subtracts an hour (e.g. summer→winter) any sunrise close to midnight immediately becomes negative (−1) and NTP_RunEventsForSecond will never match it against ltm->tm_hour, so that event is lost until the schedule is recreated. The inverse happens for hours ≥24. Wrap the result back into 0 23 (and adjust the day when crossing midnight) so that sunrise/sunset handlers still run after a DST switch.
  • ADVERTISEMENT

Topic summary

A feature to add sunrise and sunset events to NTP-based scheduling on BK7231N devices was proposed and developed, with code inspired by Tasmota and integrated into the OpenBK7231T_App firmware. The implementation includes commands to set latitude and longitude in a single command to save flash memory, and sunrise/sunset events can be added as clock events triggering device actions such as powering relays on or off. Testing showed the sunrise/sunset calculations are accurate within ±2 minutes globally. Challenges addressed include handling NTP synchronization timing, timezone offsets, and ensuring correct event triggering after device reboot or power outages. The code footprint increased by about 11 KB, mainly due to trigonometric calculations. The feature was merged into the main repository with ongoing improvements such as self-tests and documentation updates. Users shared example autoexec.bat scripts demonstrating how to configure the feature, including setting timezone, coordinates, and clock events for controlling lights. Discussions also covered handling manual overrides and state persistence across reboots using LFS commands. The feature is fully functional and available in the latest OpenBK7231T_App firmware, with additional pull requests extending functionality to expose next sunrise/sunset times as constants.
Summary generated by the language model.
ADVERTISEMENT