Ameba Arduino: [RTL8195AM] [RTL8710AF] Use NTP to update time

Preparation

  • Ameba x 1

Example

In this example, we use the Ameba time library to handle unix-like time format and related conversion. Please download the library from: https://github.com/ambiot/amb1_arduino/raw/master/Arduino_libraries/Time-1.0.1.zip
And follow the tutorial to install the .zip library to Ameba: https://www.arduino.cc/en/Guide/Libraries#toc4

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

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

setSyncProvider(getNtpTime);
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()
Copyrights ©瑞晟微电子(苏州)有限公司 2021. All rights reserved.
Please confirm that QQ communication software is installed