How does WiFi.getTime() internally work? -> Documentation is very sparse

Hi everybody,

there is this cute helper function WiFi.getTime() (WiFi101 - Arduino Reference)

There it says "The time is retrieved from the WiFi module which periodically fetches the NTP time from an NTP server." But what does periodically mean? From which servers? Which accuracy will be reached? It is hard to get the information from looking at the code which is why I want to ask here if anybody does already know the answers :slight_smile:

Why do I need this information? I want to provide timestamps for measuring values and would like to call WiFi.getTime() every second. Thereore I would like to better understand whats going on under the hood. A more precise documentation would have been great for non-native developers like me :wink:

Thanks in advance!

Welcome to the forum.

There was a similar question in the forum just a day ago. I have done a little experiment with Wireshark and Arduino Nano 33 IoT. I observed the following sequence:

  • DNS request for 0.pool.ntp.org
  • DNS response with 4 IP addresses all owned by different companies (data center and network stuff)
  • NTP Version 4, client request to the first IP address received before
  • NTP Version 4, server response back

If you want to try this yourself:

https://www.wireshark.org/

Because WiFi needs an accurate clock, I suspect the internal time is stable and therefore the NTP calls likely do not happen very often. So, simply tracing all traffic with Wireshark to figure out the schedule will likely not work. The first call happens in the first 30 seconds or minute after starting WiFi.

do you ask for the WiF101 library?
the library gets the time from the firmware in the ATMEL WINC1500.

Klaus_K:
Welcome to the forum.

There was a similar question in the forum just a day ago. I have done a little experiment with Wireshark and Arduino Nano 33 IoT. I observed the following sequence:

  • DNS request for 0.pool.ntp.org
  • DNS response with 4 IP addresses all owned by different companies (data center and network stuff)
  • NTP Version 4, client request to the first IP address received before
  • NTP Version 4, server response back

If you want to try this yourself:

https://www.wireshark.org/

Because WiFi needs an accurate clock, I suspect the internal time is stable and therefore the NTP calls likely do not happen very often. So, simply tracing all traffic with Wireshark to figure out the schedule will likely not work. The first call happens in the first 30 seconds or minute after starting WiFi.

Hi Klaus, thank you for sharing. Smart solution at least for some questions :slight_smile: But reading documentation would be nicer than reengineering :slight_smile: Indeed, I didn't stumble over the similar question. Seems to me that google did not know this one yet. Sorry for that.

Juraj:
do you ask for the WiF101 library?
the library gets the time from the firmware in the ATMEL WINC1500.

Hi Juraj, that is exactly the case yes. I am using a WINC1500 module. I will have a closer look. Or do you already know the internals of the firmware and can tell me more?
Thanks

stev-e:
But reading documentation would be nicer than reengineering :slight_smile:

I like documentation too, but documentation for software is much harder to maintain then for hardware. That is why hardware documentation is often of much higher quality.

Anyway, I repeated my experiment with an ATWINC1500 board. The result is slightly different.

  • DNS request for time-c.nist.gov
  • DNS response with 1 IP address owned by NIST
  • NTP Version 4, client request to the IP address
  • NTP Version 3, server response back

With this information I searched through the library source code and found the following.

..\libraries\WiFi101\src\driver\include\m2m_wifi.h

Synchronous function to enable/disable the native Simple Network Time Protocol(SNTP) client in the WINC1500 firmware.
The SNTP is enabled by default at start-up.The SNTP client at firmware is used to synchronize the system clock to the UTC time from the well known time servers (e.g. "time-c.nist.gov"). The SNTP client uses a default update cycle of 1 day.

I looked at the firmware for the module and the name of the time server is hard coded into the firmware binary. So, if you do not want your module to use this time server you must disable the function and set the system time to the firmware yourself.

Hi Klaus, thanks again. I don't know yet if I would want to change the server. I will need to experiment a little bit to see what the standard behaviour is if e.g. there was no connection on controller startup time or the server couldn't be reached etc. My bigger concern was/is how precise the clock will be in the meantime until the next sync is scheduled. I found that the WINC1500 comes with a extra oscillator (https://ww1.microchip.com/downloads/en/DeviceDoc/ATWINC15x0B-MU-IEEE-802.11-b-g-n-Network-Controller-DS70005374B.pdf). I will have a look how much drift there is throughout the day.

Also quite interesting: http://ww1.microchip.com/downloads/en/devicedoc/atmel-42420-winc1500-software-design-guide_userguide.pdf

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.