NTP client app setting system time and X-NUCLEO-IDW01M1 Wi-Fi board time connecting to internet NTP UTC time server.

Dependencies:   NTPClient NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed

Fork of NTPClient_HelloWorld by ST Expansion SW Team

Example of retrieval of current time using an NTP server. Time is then used to perform a TLS secure connection to https://mbed.org.
The application is meant to be used with mbed OS 2 ("Classic") only (no mbedOS 5 support).

main.cpp

Committer:
donatien
Date:
2012-08-05
Revision:
2:bf7dc5f5bca9
Parent:
1:d263603373ac
Child:
3:ca8860f482e0

File content as of revision 2:bf7dc5f5bca9:

#include "mbed.h"
#include "EthernetInterface.h"
#include "NTPClient.h"

EthernetInterface eth;
NTPClient ntp;

int main() 
{
    eth.init(); //Use DHCP

    eth.connect();
   
    printf("Trying to update time...\r\n");
    if (ntp.setTime("0.pool.ntp.org") == 0)
    {
      printf("Set time successfully\r\n");
      time_t ctTime;
      ctTime = time(NULL);
      printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
    }
    else
    {
      printf("Error\r\n");
    } 
   
    eth.disconnect();  

    while(1) {
    }
}