NTP Client Test with the Vodafone USB Modem library

Dependencies:   NTPClient VodafoneUSBModem mbed-rtos mbed

Fork of VodafoneK3770NTPClientTestBeta by Donatien Garnier

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "VodafoneUSBModem.h"
00003 #include "NTPClient.h"
00004 
00005 void test(void const*) 
00006 {
00007     VodafoneUSBModem modem;
00008     NTPClient ntp;
00009     
00010     int ret = modem.connect("pp.vodafone.co.uk");
00011     if(ret)
00012     {
00013       printf("Could not connect\n");
00014       return;
00015     }
00016     
00017     printf("Trying to update time...\r\n");
00018     if (ntp.setTime("0.pool.ntp.org") == 0)
00019     {
00020       printf("Set time successfully\r\n");
00021       time_t ctTime;
00022       ctTime = time(NULL);
00023       printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
00024     }
00025     else
00026     {
00027       printf("Error\r\n");
00028     } 
00029     
00030     modem.disconnect();  
00031 
00032     while(1) {
00033     }
00034 }
00035 
00036 
00037 int main()
00038 {
00039   Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
00040   DigitalOut led(LED1);
00041   while(1)
00042   {
00043     led=!led;
00044     Thread::wait(1000);  
00045   }
00046 
00047   return 0;
00048 }