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)
@divadiow
Copy link
Contributor

divadiow commented Nov 15, 2025

to discuss here or in thread?
1792_merge_ce894dca457c on BK7231N

DS3231_SetTime 19 50 01 13 8 2025 sets OK, but the date in GUI is

image
DS3231_GetTimeCmd: 13/08/73 19:58:17
Info:CMD:[WebApp Cmd 'DS3231_GetTime' Result] OK

@divadiow
Copy link
Contributor

same on ALT_N. Let me try BK7238, which you've already listed as working

@divadiow
Copy link
Contributor

BK7238 detecting ok

Info:I2C:Address 0x57 (dec 87)
Info:I2C:Address 0x68 (dec 104)

the example should be DS3231_SetTime 19 50 01 13 8 25 ?

image

@MaxineMuster
Copy link
Contributor Author

MaxineMuster commented Nov 15, 2025

the example should be DS3231_SetTime 19 50 01 13 8 25 ?

You are absolutely right, shame on me - will fix the "usage" (year is only "uint8_t, so any value > 255 will result in strange behaviour, as you already found out ...)

I must admit, I didn't test all commands again, so reading the already set RTC made me mark it "working".
Good you did test again ...

@divadiow
Copy link
Contributor

No shame. All good. :)

Switch to internal time functions to reduce flash usage (avoid gmtime and mktime)
@MaxineMuster
Copy link
Contributor Author

MaxineMuster commented Nov 15, 2025

Updated source - now (to test) driver is again enabled for all platforms.
Added a simple %100 to allow setting "full years" but it will be truncated to "years in century" since DS3231 only uses two digits for year.

Also changed DS3231 code to use internal time implementation (obktime) so size should be lower now (not needing time.h).
Maximum size increase is now < 5k. And W800 is still over 12k smaller?!? But DS3231 is working and I can't see I disabled anything else ...:

Size +/-    Filename                                                       1.18.211   1792_merge_3963aa99cae5
-12652      OpenW800_XX.fls                                                  698056                     685404
-7980       OpenW800_XX_ota.img                                              417768                     409788
-2840       OpenLN882H_XX.bin                                                809408                     806568
-1799       OpenLN882H_XX_OTA.bin                                            459493                     457694
0           OpenBK7231M_ALT_QIO_XX.bin                                      1253376                    1253376
0           OpenBK7231M_QIO_XX.bin                                          1220464                    1220464
0           OpenBK7231N_ALT_QIO_XX.bin                                      1253376                    1253376
0           OpenBK7231N_ALT_UA_XX.bin                                       1183744                    1183744
0           OpenBK7231N_QIO_XX_berry.bin                                    1220464                    1220464
0           OpenBK7231N_QIO_XX.bin                                          1220464                    1220464
0           OpenBK7231N_QIO_XX_hlw8112.bin                                  1220464                    1220464
0           OpenBK7231N_QIO_XX_irRemoteESP.bin                              1220464                    1220464
0           OpenBK7231N_QIO_XX_powerMetering.bin                            1220464                    1220464
0           OpenBK7231N_QIO_XX_sensors.bin                                  1220464                    1220464
0           OpenBK7231N_QIO_XX_tuyaMCU.bin                                  1220464                    1220464
0           OpenBK7231N_UA_XX_berry.bin                                     1150832                    1150832
0           OpenBK7231N_UA_XX.bin                                           1150832                    1150832
0           OpenBK7231N_UA_XX_hlw8112.bin                                   1150832                    1150832
0           OpenBK7231N_UA_XX_irRemoteESP.bin                               1150832                    1150832
0           OpenBK7231N_UA_XX_powerMetering.bin                             1150832                    1150832
0           OpenBK7231N_UA_XX_sensors.bin                                   1150832                    1150832
0           OpenBK7231N_UA_XX_tuyaMCU.bin                                   1150832                    1150832
0           OpenBK7231T_ALT_QIO_XX.bin                                      1253376                    1253376
0           OpenBK7231T_ALT_UA_XX.bin                                       1183744                    1183744
0           OpenBK7231T_QIO_XX_berry.bin                                    1048576                    1048576
0           OpenBK7231T_QIO_XX.bin                                          1048576                    1048576
0           OpenBK7231T_QIO_XX_irRemoteESP.bin                              1048576                    1048576
0           OpenBK7231T_QIO_XX_powerMetering.bin                            1048576                    1048576
0           OpenBK7231T_QIO_XX_sensors.bin                                  1048576                    1048576
0           OpenBK7231T_QIO_XX_tuyaMCU.bin                                  1048576                    1048576
0           OpenBK7231T_UA_XX_berry.bin                                      978944                     978944
0           OpenBK7231T_UA_XX.bin                                            978944                     978944
0           OpenBK7231T_UA_XX_irRemoteESP.bin                                978944                     978944
0           OpenBK7231T_UA_XX_powerMetering.bin                              978944                     978944
0           OpenBK7231T_UA_XX_sensors.bin                                    978944                     978944
0           OpenBK7231T_UA_XX_tuyaMCU.bin                                    978944                     978944
0           OpenBK7231U_QIO_XX.bin                                          1253376                    1253376
0           OpenBK7231U_UA_XX.bin                                           1183744                    1183744
0           OpenBK7238_QIO_XX_berry.bin                                     1253376                    1253376
0           OpenBK7238_QIO_XX.bin                                           1253376                    1253376
0           OpenBK7238_QIO_XX_irRemoteESP.bin                               1253376                    1253376
0           OpenBK7238_UA_XX_berry.bin                                      1183744                    1183744
0           OpenBK7238_UA_XX.bin                                            1183744                    1183744
0           OpenBK7238_UA_XX_irRemoteESP.bin                                1183744                    1183744
0           OpenBK7252N_QIO_XX.bin                                          1253376                    1253376
0           OpenBK7252N_UA_XX.bin                                           1183744                    1183744
0           OpenBK7252_QIO_XX.bin                                           1253376                    1253376
0           OpenBK7252_UA_XX.bin                                            1183744                    1183744
64          OpenBL602_XX_OTA.bin.xz                                          425868                     425932
64          OpenBL602_XX_OTA.bin.xz.ota                                      426380                     426444
264         OpenBL602_XX_berry_OTA.bin.xz                                    493552                     493816
264         OpenBL602_XX_berry_OTA.bin.xz.ota                                494064                     494328
384         OpenRTL87X0C_XX.bin                                              969988                     970372
384         OpenRTL87X0C_XX_ota.img                                          904452                     904836
608         OpenBL602_XX_berry_OTA.bin                                       898512                     899120
616         OpenBL602_XX_berry.bin                                           894404                     895020
632         OpenBL602_XX.bin                                                 769372                     770004
640         OpenBL602_XX_OTA.bin                                             773472                     774112
1008        OpenBK7252N_XX.rbl                                               487264                     488272
1088        OpenBK7252_XX.rbl                                                487360                     488448
1312        OpenBK7231T_UG_XX_irRemoteESP.bin                                548704                     550016
1312        OpenBK7231T_XX_irRemoteESP.rbl                                   548672                     549984
1384        OpenW600_XX_gz.img                                               336528                     337912
1408        OpenBK7231N_UG_XX_powerMetering.bin                              505952                     507360
1408        OpenBK7231N_XX_powerMetering.rbl                                 505920                     507328
1488        OpenBK7231T_UG_XX_powerMetering.bin                              483776                     485264
1488        OpenBK7231T_XX_powerMetering.rbl                                 483744                     485232
1488        OpenBK7238_XX_irRemoteESP.rbl                                    558176                     559664
1520        OpenBK7231T_UG_XX_sensors.bin                                    476208                     477728
1520        OpenBK7231T_XX_sensors.rbl                                       476176                     477696
1600        OpenBK7231N_UG_XX_sensors.bin                                    499712                     501312
1600        OpenBK7231N_XX_sensors.rbl                                       499680                     501280
1616        OpenBK7231N_UG_XX_irRemoteESP.bin                                566912                     568528
1616        OpenBK7231N_XX_irRemoteESP.rbl                                   566880                     568496
1625        OpenECR6600_XX_ota.img                                           528401                     530026
1628        OpenXR806_XX_ota.img                                             495880                     497508
1632        OpenBK7231T_UG_XX_berry.bin                                      546288                     547920
1632        OpenBK7231T_XX_berry.rbl                                         546256                     547888
1719        OpenRDA5981_XX_ota.img                                           293296                     295015
1728        OpenBK7231T_UG_XX.bin                                            481616                     483344
1728        OpenBK7231T_XX.rbl                                               481584                     483312
1776        OpenBK7231N_UG_XX.bin                                            506000                     507776
1776        OpenBK7231N_XX.rbl                                               505968                     507744
1808        OpenBK7231T_ALT_XX.rbl                                           498720                     500528
1872        OpenBK7238_XX.rbl                                                500848                     502720
1888        OpenBK7231N_ALT_XX.rbl                                           500896                     502784
1888        OpenBK7231N_UG_XX_tuyaMCU.bin                                    503856                     505744
1888        OpenBK7231N_XX_tuyaMCU.rbl                                       503824                     505712
1888        OpenBK7238_XX_berry.rbl                                          564992                     566880
1936        OpenXR872_XX_ota.img                                             445980                     447916
1952        OpenBK7231N_UG_XX_berry.bin                                      570480                     572432
1952        OpenBK7231N_XX_berry.rbl                                         570448                     572400
1952        OpenBK7231U_XX.rbl                                               499264                     501216
2048        OpenXR806_XX.img                                                 871264                     873312
2048        OpenXR809_XX.img                                                 912168                     914216
2108        OpenTXW81X_XX_ota.img                                            423908                     426016
2148        OpenBK7252N_XX.bin                                               732341                     734489
2160        OpenBK7231T_XX_powerMetering.bin                                 755493                     757653
2184        OpenBK7231N_XX_powerMetering.bin                                 786205                     788389
2192        OpenBK7252_XX.bin                                                738337                     740529
2228        OpenBK7238_XX_irRemoteESP.bin                                    845021                     847249
2368        OpenBK7231T_UG_XX_tuyaMCU.bin                                    482448                     484816
2368        OpenBK7231T_XX_tuyaMCU.rbl                                       482416                     484784
2380        OpenRTL8710A_XX.bin                                              790612                     792992
2380        OpenRTL8710A_XX_ota.img                                          745560                     747940
2424        OpenRTL8710B_XX.bin                                              674716                     677140
2424        OpenW600_XX.fls                                                  551640                     554064
2448        OpenBK7231N_UG_XX_hlw8112.bin                                    445184                     447632
2448        OpenBK7231N_XX_hlw8112.rbl                                       445152                     447600
2496        OpenRTL8720E_XX.bin                                             1403456                    1405952
2496        OpenRTL8720E_XX_ota.img                                         1321568                    1324064
2512        OpenESP32S3_XX_4M.factory.bin                                   1073408                    1075920
2512        OpenESP32S3_XX_4M.img                                           1007872                    1010384
2528        OpenBK7231N_XX_sensors.bin                                       798081                     800609
2528        OpenBK7231T_XX_sensors.bin                                       766249                     768777
2544        OpenESP32_XX_4M.factory.bin                                     1072864                    1075408
2544        OpenESP32_XX_4M.img                                             1007328                    1009872
2560        OpenBK7231T_XX_irRemoteESP.bin                                   878805                     881365
2576        OpenBK7231N_XX_irRemoteESP.bin                                   903477                     906053
2592        OpenESP32S2_XX_4M.factory.bin                                   1047408                    1050000
2592        OpenESP32S2_XX_4M.img                                            981872                     984464
2736        OpenESP32C2_XX_2M.factory.bin                                    920384                     923120
2736        OpenESP32C2_XX_2M.img                                            854848                     857584
2736        OpenESP32C61_XX_4M.factory.bin                                  1213792                    1216528
2736        OpenESP32C61_XX_4M.img                                          1148256                    1150992
2752        OpenESP32C5_XX_4M.factory.bin                                   1251824                    1254576
2752        OpenESP32C5_XX_4M.img                                           1186288                    1189040
2760        OpenBK7231T_ALT_XX.bin                                           756373                     759133
2760        OpenBK7231U_XX.bin                                               758309                     761069
2760        OpenBK7238_XX.bin                                                752649                     755409
2768        OpenESP32C2_XX_4M.factory.bin                                   1050240                    1053008
2768        OpenESP32C2_XX_4M.img                                            984704                     987472
2768        OpenESP32C3_XX_2M.factory.bin                                   1026112                    1028880
2768        OpenESP32C3_XX_2M.img                                            960576                     963344
2768        OpenESP32C3_XX_4M.factory.bin                                   1155888                    1158656
2768        OpenESP32C3_XX_4M.img                                           1090352                    1093120
2768        OpenESP32C6_XX_4M.factory.bin                                   1253296                    1256064
2768        OpenESP32C6_XX_4M.img                                           1187760                    1190528
2784        OpenBK7231T_XX_berry.bin                                         875433                     878217
2792        OpenBK7231N_XX.bin                                               805681                     808473
2792        OpenBK7231T_XX.bin                                               772337                     775129
2800        OpenBK7231N_XX_berry.bin                                         908761                     911561
2804        OpenBK7231N_ALT_XX.bin                                           758769                     761573
2804        OpenBK7238_XX_berry.bin                                          853649                     856453
2956        obkSimulator_XX.zip                                             2487716                    2490672
3072        OpenXR872_XX.img                                                 791384                     794456
3144        OpenRDA5981_XX.bin                                               508916                     512060
3168        OpenESP8266_1MB_XX.factory.bin                                   817776                     820944
3168        OpenESP8266_2MB_XX.factory.bin                                   817776                     820944
3168        OpenESP8266_XX.img                                               752240                     755408
3224        OpenBK7231T_XX_tuyaMCU.bin                                       753629                     756853
3248        OpenBK7231N_XX_tuyaMCU.bin                                       782981                     786229
3252        OpenTR6260_XX.bin                                                657604                     660856
3392        OpenRTL8721DA_XX.bin                                            1517408                    1520800
3392        OpenRTL8721DA_XX_ota.img                                        1435520                    1438912
3584        OpenTXW81X_XX.bin                                                605200                     608784
3588        OpenECR6600_XX.bin                                               984657                     988245
3696        OpenBK7231N_XX_hlw8112.bin                                       690501                     694197
4096        OpenRTL8720D_XX.bin                                             1089536                    1093632
4096        OpenRTL8720D_XX_ota.img                                         1064992                    1069088
4848        OpenRTL8710B_XX_ota.img                                         1259328                    1264176

@divadiow
Copy link
Contributor

checking: what should be considered a successful test? driver starts, time and date sets OK, unplug all so battery keeps time, re-power OBK and check time is as expected? Leave for x period on battery alone then check correct time/date? 1 day, 1 hour, 5 mins etc etc

@MaxineMuster
Copy link
Contributor Author

I think it would be sufficient to test features in general.
For: if we can read and set the RTC as expected, other tests (e.g. in x minutes, in x days ...) would mainly tell us, if RTC itself works (or am I wrong)?

So the main test would be: are all images working at all - did I break anything basic.

An then we need to test, if all clock related functions do still work:

Is NTP working?
Are timed/repeating/sunset/sunrise events working as expected?
Most of the functions are tested in "selftests" in simulator, and since we use the same code base, it should work from my perspective.

For this I have a LN882H plug running with this version for some time now (though no RTC inside) with additionally enabled features ENABLE_CLOCK_DST, ENABLE_CLOCK_SUNRISE_SUNSET and ENABLE_CALENDAR_EVENTS. Sure, latest changes are not tested for a longer period, but it did work fine with prevoius version for a month or so.

All features I use are working:

Clock is set by NTP and can be changed with "clock_settime" (until next NTP event will change it back)
passing DST time is switching the clock as expected
sunrise and sunset events turn the plug on and off correctly

Can you or @openshwprojects think of some other useful tests?

@divadiow
Copy link
Contributor

divadiow commented Nov 15, 2025

I think it would be sufficient to test features in general. For: if we can read and set the RTC as expected, other tests (e.g. in x minutes, in x days ...) would mainly tell us, if RTC itself works (or am I wrong)?

yeh, I hadn't really thought through what I was saying

RTL87X0C seems OK.

startdriver DS3231 2 4

using example settime as standard :

DS3231_SetTime 19 50 01 13 8 25
time is present/set/correct after full power removal from RTL module. only the CR2032 for DS3231 present

image

that's a few things to test. fine. I need to engage with some of those other clock/time features - not done sunset stuff.

I feel the need for a tracking sheet...

image

@MaxineMuster
Copy link
Contributor Author

MaxineMuster commented Nov 15, 2025

That would be great to test, but is it worth all the work for all platforms - you might be the first to try it anyway, for most of theese features are not enabled for most of the platforms:

SUNRISE_SUNSET is present only in Windows simulator and Beken
CALENDAR_EVENTS a bit more, additionally to WIN and Beken on BL602, ESP, Realtek, ECR6600
CLOCK_DST (as "NTP_DST" in the other builds) is only present in WIN bulid by default (to allow testing the feature)

Don't get me wrong, I really appreciate your huge amount of work!!

@divadiow
Copy link
Contributor

well, the less there is to do the better. I get bored easily! I could do the flash, boot, run driver, set time, check time is still set after power-cycle? dunno?

startup/autoexec are columns because either N or BK7238 (mental note to go check again and note which) would just bootloop and then go into safe mode with startup command.

@divadiow
Copy link
Contributor

@MaxineMuster
Copy link
Contributor Author

I think this small set of tests will suffice in this case. Just to be sure, the image is working - maybe only ESP8266 would be good to test also with MQTT, I think I recall I had to do some special handling there to print the local time ...

Ah, yes, in "src/mqtt/new_mqtt.c"

+#ifdef PLATFORM_ESP8266
+		// while all other platforms will accept uint32_t as long unsigned, ESP8266 needs %u 
+		// biuild fails otherwise because of -Werror=format
+		// src/mqtt/new_mqtt.c:2036:24: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'uint32_t' {aka 'unsigned int'} [-Werror=format=]
+		// al other ESP:
+		/// src/mqtt/new_mqtt.c:2036:44: error: format '%d' expects argument of type 'int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
+		sprintf(dataStr, "%u", Clock_GetCurrentTime());
+#else
+		sprintf(dataStr, "%lu", Clock_GetCurrentTime());
+#endif
+		return MQTT_DoItemPublishString("datetime", dataStr);

@divadiow
Copy link
Contributor

struggling to get any i2c detection on 8266 at the moment, with any build. but i see a BMP: https://www.elektroda.com/rtvforum/topic4128678-30.html

don't suppose you remember pins used?

@MaxineMuster
Copy link
Contributor Author

MaxineMuster commented Nov 19, 2025

don't suppose you remember pins used?

For ESP8266 remember the "shifted" upper IO numbers due to "missing" IO6-IO8 and IO11.


#elif PLATFORM_ESP8266

espPinMapping_t g_pins[] = {
	{ "IO0", GPIO_NUM_0, false }, // 0
	{ "IO1", GPIO_NUM_1, false }, // 1
	{ "IO2", GPIO_NUM_2, false }, // 2
	{ "IO3", GPIO_NUM_3, false }, // 3
	{ "IO4", GPIO_NUM_4, false }, // 4
	{ "IO5", GPIO_NUM_5, false }, // 5
	{ "IO9", GPIO_NUM_9, false }, // 6
	{ "IO10", GPIO_NUM_10, false }, // 7
	{ "IO12", GPIO_NUM_12, false }, // 8
	{ "IO13", GPIO_NUM_13, false }, // 9
	{ "IO14", GPIO_NUM_14, false }, // 10
	{ "IO15", GPIO_NUM_15, false }, // 11
	{ "IO16", GPIO_NUM_16, false }, // 12
};

For SCL IO12 / SDA IO13:
startdriver DS3231 8 9
ESP8266_DS3231

@divadiow
Copy link
Contributor

For ESP8266 remember the "shifted" upper IO numbers due to "missing" IO6-IO8 and IO11.

yep, was doing all sorts on io4/5 and just i2c softscan.

anyway, dunno what was going on this morning

image

not getting any more than this showing in HA

image image

@MaxineMuster
Copy link
Contributor Author

MaxineMuster commented Nov 20, 2025

Mqtt should show actual time on the device somewhere...
And there is a special handling for ESP8266 in the code, so if time is present, it should be ok

@divadiow
Copy link
Contributor

there's this...

image

MaxineMuster and others added 7 commits November 22, 2025 17:32
…urrentTime()"

switch to obktime instead of time.h "gmtime"
change "deviceclock.c" to set DS3231 RTC on every clock set command if driver is running, so e.g. every NTP update will also adjust RTC time
…ceclock whenever clock is set.

so DS3231 driver can ste the clock, if needed - using "force" will force setting (no supprise ;-))
@divadiow
Copy link
Contributor

i've mostly been testing with 1792_merge_d5dcefa00d23 but I notice some newer builds now. maybe it doesn't matter so much for basic does it even boot/driver start kind of test?
image

@MaxineMuster
Copy link
Contributor Author

Thank you so much, the latest changes are no basic ones, just keeping up to date with "main" branch and some small additions.
I think it's o.k. now, if you don't feel you would like to spend more time on this. I really appreciate your reliable support!

Changing how/when a driver function is called should not enforce a complete new set of tests, if we know, it works as expected on some platforms here..

@divadiow
Copy link
Contributor

divadiow commented Nov 23, 2025

oh sure, no worries. There are so many platforms now!

RTL8721DA doesn't seem to work, but then I can't detect any i2c it seems. using PB18/PB19 and PB20/PB21. Not a popular platform anyway yet.

image boots fine though

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.

4 participants