Skip to content

Conversation

MaxineMuster
Copy link
Contributor

@MaxineMuster MaxineMuster commented Sep 9, 2025

Driver enabled for W800 ATM.

enabling driver with

#define ENABLE_DRIVER_DS3231

starting driver with

startdriver DS3231 <CLK-Pin> <DATA-Pin> <optional: sync clock>

optional last argument "sync clock":
0: do nothing
1: on driver start set device clock to RTC
2: set device clock regularly to RTC - so RTC is "clock master"

MaxineMuster and others added 30 commits July 10, 2025 21:34
use original obk_config.h - only renaming functions - to see filesizes
consolidate time display on main page
fix double comments preventing several documentation details ($mday, $month ...) on docs/constants.md
enabling more time stuff for W800 for local testing.
…GetArgInteger(0) for epoch

Change user_main.c to use xticks as uptime for g_secondsElapsed
remove additional defines for W800 used for testing
Seems much better, 30 seconds difference in one day
(used to be over 10 minutes off in 12 hours)
@DeDaMrAzR
Copy link
Contributor

DeDaMrAzR commented Oct 2, 2025

@MaxineMuster share any comments so we can all test this better and maybe implement is project wide if possible. Any info is welcome and thanks.

@divadiow
Copy link
Contributor

divadiow commented Oct 2, 2025

image

@MaxineMuster
Copy link
Contributor Author

MaxineMuster commented Oct 3, 2025

This PR is mainly a demonstration on how PR#1729 can be used.
Its an implementation of a device clock based on the simple idea we have an uptime counter in OBK (g_secondsElapsed) so the actual time can always be calculated if we store the time on startup of the device.
Then we need to "share" all functions related to clock with this "clock" which are actually all implemented for NTP.
So the main part is separating the code to make it usable for different clock sources.
They are renamed internally to get rid of NTP prefix (e.g. if I want the hour, it's no longer "NTP_GetHour()" but "CLOCK_GetHour()" is called.) While this is only for internal calls, we need to change external calls, too:
While e.g "ntp_timeZoneOfs" is ok if we only have NTP, but strictly speaking we need to set it "for the clock", not for NTP. So we have a new command "clock_setTZ" (leaving the ntp based for compatibility). Same goes for almost all other commands starting with "ntp_", there are only few really related to NTP like e.g. "ntp_setServer" or "ntp_info".

A list of all commands introduced:

"clock_setLatLong"	(still for compatibility: "ntp_setLatLong")
	example 	"CLOCK_SetLatlong -34.911498 138.809488"
	
"clock_setDST" 		(still for compatibility: "clock_calcDST")

			                       |-- 1st rule: last_week March sunday 2_o_clock 60_minutes_DST_after_this_time  
			             |---------|  
	example:	"CLOCK_setDST 0 3 1 2 60 0 10 1 3 0"	
			                        |---------| 
			                                  |-- 2nd_rule: last_week October sunday 3_o_clock 0_minutes_DST_after_this_time 


"clock_setTZ"		(still for compatibility: "ntp_timeZoneOfs")
	examples:	"clock_setTZ 1"
				"clock_setTZ 1:30"
				"clock_setTZ -1:30"

Two additional areas for changes before getting to the actual RTC driver ;-)

Especially on BL602 the images increased quite a lot when using time.h functions.
So this PR (inherited from #1729) also introduces obktime.c for smaller calls to time related functions (resulting in much smaller BL602 images, but also some increased ones).

Since increasing g_secondsElapsed only in OnEverySecond, time will differ soon, depending on the chip for some seconds in a minute!
For (almost, not the new TXW81X and RDA) all platforms I changed this to a check for ticks, so time works quite precisely for me, only drifting up to some seconds a day.

And now, on top of the base to use a clock independent from NTP, there's the simple driver for the DS3231:

startdriver DS3231 <CLK-Pin> <DATA-Pin> <optional: sync clock>

e.g.
"DS3231_SetTime 19 50 01 13 8 2025"

"DS3231_GetTime"
"DS3231_SetTime <hours> <minutes> <seconds> <day> <month> <year>"
	examples:	"DS3231_SetTime 19 50 01 13 8 2025"	(19:50:01 13 Aug 2025)


"DS3231_GetEpoch"
"DS3231_SetEpoch <epoch>"
	examples:	"DS3231_SetEpoch 1755107401"		(19:50:01 13 Aug 2025)

So a simple call to set the RTC from another device:
wget "http://<ip.of.your.plug>/cmd_tool?cmd=DS3231_SetEpoch $(date +%s)"

The main thread for all around this is

https://www.elektroda.com/rtvforum/topic4046620.html

@DeDaMrAzR
Copy link
Contributor

Tomorrow I should be receiving my RTC module and will test more and report back with findings.

@MaxineMuster
Copy link
Contributor Author

A word of caution regarding the cheap modules: they often are delivered with a regular cell battery, but hardware setup is for a rechargeable battery. So if powered, the battery is "charging" against the rules.
If this is the case like with my modules: I desoldered the resistor connecting battery to VCC

51kZwSCBwQL _SY88

@divadiow
Copy link
Contributor

divadiow commented Oct 6, 2025

thanks. mine didn't come with cell, but I also dont have any rechargeables

@MaxineMuster
Copy link
Contributor Author

You can simply check if battery + is connected to VCC via the diode and resistor. If it is, you shouldn't use a non rechargeable battery without modification.

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.

3 participants