The ntptime module documenation is confusing?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Jibun no kage
Posts: 144
Joined: Mon Jul 25, 2022 9:45 pm

The ntptime module documenation is confusing?

Post by Jibun no kage » Mon Aug 15, 2022 2:16 am

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” .

Shards
Posts: 39
Joined: Fri Jun 25, 2021 5:14 pm
Location: Milton Keynes, UK

Re: The ntptime module documenation is confusing?

Post by Shards » Mon Aug 15, 2022 11:45 am

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.

Jibun no kage
Posts: 144
Joined: Mon Jul 25, 2022 9:45 pm

Re: The ntptime module documenation is confusing?

Post by Jibun no kage » Mon Aug 15, 2022 4:23 pm

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.

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: The ntptime module documenation is confusing?

Post by scruss » Thu Jan 11, 2024 3:44 pm

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:
Jibun no kage wrote:
Mon Aug 15, 2022 2:16 am
Reference https://mpython.readthedocs.io/en/maste ... ptime.html...
is not the official library, and refers to a forked version of MicroPython for some IoT device developed in China.

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.

Post Reply