Use NTP to update time


  • Ameba x 1


In this example, we use the Ameba time library to handle unix-like time format and related conversion. Please download the library from:
And follow the tutorial to install the .zip library to Ameba:

Open the sample code in “File” -> “Examples” -> “AmebaTime” -> “TimeNTP”
Please modify the sample code to provide the WiFi ssid/password information for WiFi connection. Then upload the sample to Ameba and press reset button.

In execution, the program first sends an NTP request to NTP server. When the  response is received, the time library handles to time conversion.

Code Reference

First, to set the function to get time value for the Time library, specify the function pointer in setSyncProvider().
The function must return the unix time format (i.e., the total seconds from January,1,1970) with type time_t, which is in fact unsigned long type.
In getNtpTime(), we get the time from NTP server as in the AmebaWiFi example WiFiUdpNtpClient. Then do the timezone conversion. To get related time values, we can call these functions: year(), month(), day(), hour(), minute(), second()
Please confirm that QQ communication software is installed