khoih-prog/DS323x_Generic

setTime() does not set system time

rnsi opened this issue · 4 comments

rnsi commented

Describe the bug

According to the docs, setTime() will "// set the system time to UTC". However time() still reports uptime seconds.

Steps to Reproduce

In DS323x_Generic/examples/Time/ESP/RTC_ESP/RTC_ESP.ino , call time() function.

Expected behavior

time() should contain the same value as rtc.now()

Actual behavior

time() is unaffected.

Information

Please ensure to specify the following:

  • Arduino IDE version 1.8.19
  • ESP8266 Core Version ESP8266 core v3.0.0
  • Contextual information - set system time from RTC
  • Call time() function from RTC_ESP example

The setTime() function is one of the TimeLib library and it certainly can't know about every board to set the system time. You can post an issue there to ask for help.

Also check the similar issue in ESP8266 Forum TIMELIB : HOW TO SET TIME(NULLPTR) ?

You can also adapt this NTP-TZ-DST example to use.

It's your responsibility to set the system time yourself, if you'd like to use, when you already have the accurate time from RTC.

As this issue has nothing to do with this library, I'm closing it now.

Good Luck,

Hi @rnsi

I already write a new example RTC_ESP_Complex to serve your purpose.

The terminal output when running on ESP8266_NODEMCU_ESP12E

Start RTC_ESP_Complex on ESP8266_NODEMCU_ESP12E
Timezone_Generic v1.9.1
DS323x_Generic v1.2.2
Connecting to HueNet1
...................
You're connected to the network, IP = 192.168.2.94
Packet received
Seconds since Jan 1 1900 = 3854581698
Unix time = 1645592898
The UTC time is 5:08:18
============================
05:08:18 Wed 23 Feb 2022 UTC
00:08:18 Wed 23 Feb 2022 EST
System Time UTC: Wed Feb 23 05:08:18 2022

============================
05:08:27 Wed 23 Feb 2022 UTC
00:08:27 Wed 23 Feb 2022 EST
System Time UTC: Wed Feb 23 05:08:28 2022

============================
05:08:37 Wed 23 Feb 2022 UTC
00:08:37 Wed 23 Feb 2022 EST
System Time UTC: Wed Feb 23 05:08:38 2022

============================
05:08:47 Wed 23 Feb 2022 UTC
00:08:47 Wed 23 Feb 2022 EST
System Time UTC: Wed Feb 23 05:08:48 2022

============================
05:08:57 Wed 23 Feb 2022 UTC
00:08:57 Wed 23 Feb 2022 EST
System Time UTC: Wed Feb 23 05:08:58 2022

Cheers,

rnsi commented

That's perfect!

Thank you very much for your quick response and solution. It is very much appreciated.

Hi @rnsi

The new DS323x_Generic releases v1.2.3 has just been published. Your contribution is noted in Contributions and Thanks

Best Regards,


Releases v1.2.3

  1. Optimize code by using passing by reference instead of by value
  2. Add ESP_Complex examples to update system time from RTC time. Check setTime() does not set system time #1
  3. Update Packages' Patches