NTP Client test using a Sprint/Sierra Wireless 598U dongle
Dependencies: NTPClient SprintUSBModem mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include "SprintUSBModem.h" 00003 #include "NTPClient.h" 00004 00005 void test(void const*) 00006 { 00007 SprintUSBModem modem(p18); 00008 NTPClient ntp; 00009 00010 Thread::wait(5000); 00011 printf("Switching power on\r\n"); 00012 00013 modem.power(true); 00014 00015 int ret = modem.connect(); 00016 if(ret) 00017 { 00018 printf("Could not connect\r\n"); 00019 return; 00020 } 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 printf("Disconnecting\r\n"); 00036 00037 modem.disconnect(); 00038 00039 printf("Disconnected\r\n"); 00040 00041 modem.power(false); 00042 00043 printf("Powered off\r\n"); 00044 00045 while(1) { 00046 } 00047 } 00048 00049 00050 int main() 00051 { 00052 DBG_INIT(); 00053 DBG_SET_SPEED(115200); 00054 DBG_SET_NEWLINE("\r\n"); 00055 Thread testTask(test, NULL, osPriorityNormal, 1024 * 5); 00056 DigitalOut led(LED1); 00057 while(1) 00058 { 00059 led=!led; 00060 Thread::wait(1000); 00061 } 00062 00063 return 0; 00064 }
Generated on Thu Jul 21 2022 22:31:42 by 1.7.2