ntp time

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
bellad
Posts: 96
Joined: Tue May 14, 2019 1:47 pm

ntp time

Post by bellad » Fri Oct 18, 2019 9:36 am

hello,
i try with ntptime.py and i change

Code: Select all

machine.RTC().datetime((tm[0], tm[1], tm[2], tm[6] + 1, tm[3], tm[4], tm[5], 0))
by

Code: Select all

machine.RTC().datetime((tm[0], tm[1], tm[2], tm[6]+1, tm[3]+2, tm[4], tm[5], 0))
with utime.localtime()
the first :

Code: Select all

(2019, 10, 18, 5, 9, 21, 10, 0)
good for weekday
the second :

Code: Select all

(2019, 10, 18, 11, 21, 17, 4, 291)
good for utc + 2h but no good for weekday

i no understand

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: ntp time

Post by kevinkk525 » Fri Oct 18, 2019 9:47 am

I use this:

Code: Select all

RTC_TIMEZONE_OFFSET=1
ntptime.settime()
tm = time.localtime()
tm = tm[0:3] + (0,) + (tm[3] + RTC_TIMEZONE_OFFSET,) + tm[4:6] + (0,)
machine.RTC().datetime(tm)
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

bellad
Posts: 96
Joined: Tue May 14, 2019 1:47 pm

Re: ntp time

Post by bellad » Fri Oct 18, 2019 11:08 am

ok thank's
but why the weekday is 4 instead of 5
4 = Thursday
5 = Friday

what do you have a weekday ?

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: ntp time

Post by kevinkk525 » Fri Oct 18, 2019 1:10 pm

The weekday is consistent with the CPython3 output. I would have expected it to be 5 but apparently 4 is correct:
https://docs.python.org/3/library/time. ... truct_time

Monday is 0.
Being used to crontab I expected Sunday to be 0 but python thinks differently.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

bellad
Posts: 96
Joined: Tue May 14, 2019 1:47 pm

Re: ntp time

Post by bellad » Fri Oct 18, 2019 1:20 pm

ok , thank for info ,
it's very strange , but we are going to do with ,
by adding +1 for weekday and ,for me ,adding +2 for the hour

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: ntp time

Post by kevinkk525 » Fri Oct 18, 2019 1:24 pm

I wouldn't modify the weekday to stay compatible to the typical Python implementation but that's your choice..
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

bellad
Posts: 96
Joined: Tue May 14, 2019 1:47 pm

Re: ntp time

Post by bellad » Fri Oct 18, 2019 2:08 pm

but i no understand , today we are friday
the micropython today is 4
if i look at utime function
utime.localtime([secs])

Convert a time expressed in seconds since the Epoch (see above) into an 8-tuple which contains: (year, month, mday, hour, minute, second, weekday, yearday) If secs is not provided or None, then the current time from the RTC is used.

year includes the century (for example 2014).
month is 1-12
mday is 1-31
hour is 0-23
minute is 0-59
second is 0-59
weekday is 0-6 for Mon-Sun
yearday is 1-366
we should be the number 5

rpr
Posts: 99
Joined: Sat Oct 27, 2018 5:17 pm

Re: ntp time

Post by rpr » Fri Oct 18, 2019 2:19 pm

0 = Monday.

bellad
Posts: 96
Joined: Tue May 14, 2019 1:47 pm

Re: ntp time

Post by bellad » Fri Oct 18, 2019 2:21 pm

yes , we are friday = 5
utime.localtime()
(2019, 10, 18, 11, 21, 17, 4, 291)

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: ntp time

Post by kevinkk525 » Fri Oct 18, 2019 2:50 pm

bellad wrote:
Fri Oct 18, 2019 2:21 pm
yes , we are friday = 5
utime.localtime()
(2019, 10, 18, 11, 21, 17, 4, 291)
Monday: 0
Tuesday: 1
Wednesday: 2
Thursday: 3
Friday: 4
...
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply