Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First try for time keeping without NTP #1152

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

MaxineMuster
Copy link
Contributor

Since often you might not need very exact time, or even can't connect to an NTP server, I tried an different approach for some "easy" time keeping:

If you store the epoch at startup of the device, you can get the actual time by adding "g_secondsElapsed".
Since this is quite unreliable (drifting off 1 to 2 minutes per day) I introduced a function to set it to a more reliable value derived from xTaskGetTickCount() - I hope it is present on all platforms.
ATM its only tested on the one platform I have: LN882H.

Up to now its more like an "extended proof of concept" - probably some bugs inside and even during upload I saw quite some typos ..
"Extended" because it will also respect daylight saving time - for the EU, but this can be extended.
I would be happy to get some feedback, there are quite some aspects to discuss:
E.g. how to implement DST: I have two possible solutions tested:

  1. A formula to calculate it - not really hard to implement - but how to work with different DST rules?
  2. A table with pre-calculated times where switches in DST will take place

The second solution is implemented at the moment: Takes some memory and is restricted to the calculated dates.
But it should be quite easy to change/extend it for other zones, if you only have to add dates, but no formula.
And regarding the restricted list - maybe its possible to realize an "update" process

Now I'm at the point to find out, if this is something worth to invest more time:
It won't make sense to put too much afford in this, if it will never make it into the project.

@openshwprojects
Copy link
Owner

That's a very interesting concept, I want it merged, but yould you be able to add a #define to enable and disable that?
I am asking becaues BL602 is very limited on space and we need to be able to disable that for this platform.

@MaxineMuster
Copy link
Contributor Author

Thanks for your feedback.

Sure, this would need some effords to make it flexible and configurable.
E.g. just "emulate" a clock, no additional features, this would take only few bytes to store the time and might be included even in the "core".
Handling of timezones, DST and so an could be optional.
And maybe we should devide the actual NTP driver into parts related to NTP and more general functions:

  • sunset and sunrise
  • time related events
  • ...
    this is not necessarily bound to NTP but just to having a running clock

MaxineMuster and others added 8 commits March 27, 2024 10:19
Fix some typos
Delete some test code
Add time on index page
	added "drv_deviceclock" for general functions
	moved "drv_ntp_events" to "drv_clock_events"

to compile, "driver/drv_deviceclock.c" must be added sdk Makefiles:

--- sdk/OpenW800/app/Makefile	2024-03-26 16:04:03.812580727 +0100
+++ sdk/OpenW800/app/Makefile	2024-04-02 21:24:35.486435795 +0200
@@ -30,6 +30,7 @@
 CSRCS += $(_SHARED_APP)/hal/w800/hal_pins_w800.c
 CSRCS += $(_SHARED_APP)/hal/w800/hal_wifi_w800.c
 CSRCS += $(_SHARED_APP)/httpserver/hass.c
+CSRCS += $(_SHARED_APP)/driver/drv_deviceclock.c
 CSRCS += $(_SHARED_APP)/httpserver/http_fns.c
 CSRCS += $(_SHARED_APP)/httpserver/http_tcp_server.c
 CSRCS += $(_SHARED_APP)/httpserver/http_basic_auth.c

--- sdk/OpenW600/app/Makefile	2024-03-26 16:04:02.376605773 +0100
+++ sdk/OpenW600/app/Makefile	2024-04-02 21:01:54.011157424 +0200
@@ -47,6 +47,7 @@
 CSRCS += $(_SHARED_APP)/driver/drv_httpButtons.c
 CSRCS += $(_SHARED_APP)/driver/drv_main.c
 CSRCS += $(_SHARED_APP)/driver/drv_ntp.c
+CSRCS += $(_SHARED_APP)/driver/drv_deviceclock.c
 CSRCS += $(_SHARED_APP)/driver/drv_tasmotaDeviceGroups.c
 CSRCS += $(_SHARED_APP)/driver/drv_test_drivers.c
 CSRCS += $(_SHARED_APP)/driver/drv_bridge_driver.c

--- sdk/OpenXR809/project/oxr_sharedApp/gcc/Makefile	2024-03-26 16:04:04.420570122 +0100
+++ sdk/OpenXR809/project/oxr_sharedApp/gcc/Makefile	2024-04-02 20:52:18.203372715 +0200
@@ -67,6 +67,7 @@
 SRCS += ../shared/src/driver/drv_ntp
 SRCS += ../shared/src/driver/drv_tuyaMCU
 SRCS += ../shared/src/driver/drv_uart
+SRCS += ../shared/src/driver/drv_deviceclock

 SRCS += ../shared/src/i2c/drv_i2c_main
 SRCS += ../shared/src/i2c/drv_i2c_mcp23017
@MaxineMuster
Copy link
Contributor Author

Can I somehow include changes to the Makefiles in sdk?
In order to compile, the added file must be included, which I can do on my local clone, but theese changes are not included.
So I would need a changed version of the sdk-files, too...

some "streamlining" to Javascript code to save some bytes.

Displaying time on GUI is done via "status updates" from device
So uptime is not so fancy anymore (no start with "just ..." changing with the time)
But this saves some bytes in the Javascript Part
@openshwprojects
Copy link
Owner

I can see you made a lot of updates. Can you change the function names to fit our standard, if not NTP_GetHour then maybe Clock_GetHour, etc? Windows (uised on simulator) has names like GetMiliseconds so we need to use prefixes.

The SDK changes are problematic because they need to be done separately, but on the other hand, I can't do the in main tree because the new file created would be missing in main... maybe I can do them manually once you get the basic version working?
Is this version working? Could it have been merged soon?

Is there a correct #define to enable/disable manual timekeeping in obk_config.h ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants