The top section states that UTC is used. But later the default timezone is set to 8? Eastern Eight District? And when, on Pico I try to set the timezone=0, I get 'unexpected keyword argument 'timezone'... Color me confused.
How do I force ntptime.settime() method to maintain UTC? Which is what NTP servers return,
Reference https://mpython.readthedocs.io/en/maste ... ptime.html...
ntptime — Time synchronization
This module is used for time synchronization, providing accurate time, International Standard Time (UTC).
what is NTP
Network Time Protocol (NTP) is a protocol used to synchronize the time of the computer. It can synchronize the computer to its server or clock source (such as quartz clock, GPS, etc.). It can provide highly precise time calibration.
Method
ntptime.settime(timezone=8, server = 'ntp.ntsc.ac.cn')
Synchronize local time
timezone - Time zone time difference, the default is East Eight District, compensation 8 hours
server - You can specify the time server yourself, server is a string type. The default time server is “ntp.ntsc.ac.cn” .
The ntptime module documenation is confusing?
-
- Posts: 144
- Joined: Mon Jul 25, 2022 9:45 pm
Re: The ntptime module documenation is confusing?
Have you actually tried using ntptime without worrying about UTC?
With a suitable host set a simple ntptime.settime() delivers a correct UTC time. This is using the latest overnight build of 1.19 for the Pico W. And there is no timezone, or any other, keyword argument.
The documentation is clearly wrong but ntptime on the Pico W works just fine.
With a suitable host set a simple ntptime.settime() delivers a correct UTC time. This is using the latest overnight build of 1.19 for the Pico W. And there is no timezone, or any other, keyword argument.
The documentation is clearly wrong but ntptime on the Pico W works just fine.
-
- Posts: 144
- Joined: Mon Jul 25, 2022 9:45 pm
Re: The ntptime module documenation is confusing?
Yeah, I did some more testing, and got the ntptime.settime to honor UTC. But, yes, documentation being wrong just added to the confusion when my initial test returned non UTC.
Re: The ntptime module documenation is confusing?
Hey - this is an old question on an almost-closed forum. But it's still showing up in search results and perhaps confusing users.
The link given by the OP as the NTP documentation:
The micropython-lib ntptime library is here: micropython-lib/micropython/net/ntptime at master · micropython/micropython-lib. Please note that it only supports UTC time, with the reason given as "There's currently no timezone support in MicroPython, and the RTC is set in UTC time".
Peter Hinch wrote a version that allows a time offset to be set: micropython-samples/ntptime/ntptime.py at master · peterhinch/micropython-samples. Note that, unlike the micropython-lib version, it doesn't set the RTC to the time returned from the NTP server.
The link given by the OP as the NTP documentation:
is not the official library, and refers to a forked version of MicroPython for some IoT device developed in China.Jibun no kage wrote: ↑Mon Aug 15, 2022 2:16 amReference https://mpython.readthedocs.io/en/maste ... ptime.html...
The micropython-lib ntptime library is here: micropython-lib/micropython/net/ntptime at master · micropython/micropython-lib. Please note that it only supports UTC time, with the reason given as "There's currently no timezone support in MicroPython, and the RTC is set in UTC time".
Peter Hinch wrote a version that allows a time offset to be set: micropython-samples/ntptime/ntptime.py at master · peterhinch/micropython-samples. Note that, unlike the micropython-lib version, it doesn't set the RTC to the time returned from the NTP server.