NTPClient using the mbed_official WiflyInterface

Dependencies:   NTPClient WiflyInterface mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "WiflyInterface.h"
00003 #include "NTPClient.h"
00004 
00005 /* wifly interface:
00006 *     - p9 and p10 are for the serial communication
00007 *     - p19 is for the reset pin
00008 *     - p26 is for the connection status
00009 *     - "mbed" is the ssid of the network
00010 *     - "password" is the password
00011 *     - WPA is the security
00012 */
00013 WiflyInterface wifly(p9, p10, p19, p26, "mbed", "password", WPA);
00014 NTPClient ntp;
00015 
00016 int main() 
00017 {
00018     wifly.init(); //Use DHCP
00019 
00020     wifly.connect();
00021    
00022     printf("Trying to update time...\r\n");
00023     if (ntp.setTime("0.pool.ntp.org") == 0)
00024     {
00025       printf("Set time successfully\r\n");
00026       time_t ctTime;
00027       ctTime = time(NULL);
00028       printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
00029     }
00030     else
00031     {
00032       printf("Error\r\n");
00033     } 
00034    
00035     wifly.disconnect();  
00036 
00037     while(1) {
00038     }
00039 }