Simple example demonstrating how to use the NTP Client to set the time
Dependencies: NTPClient mbed mbed-rtos EthernetInterface
Fork of HTTPClient_HelloWorld by
Revision 2:bf7dc5f5bca9, committed 2012-08-05
- Comitter:
- donatien
- Date:
- Sun Aug 05 16:17:31 2012 +0000
- Parent:
- 1:d263603373ac
- Commit message:
- Initial commit
Changed in this revision
diff -r d263603373ac -r bf7dc5f5bca9 HTTPClient.lib --- a/HTTPClient.lib Sun Aug 05 16:12:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/donatien/code/HTTPClient/#be61104f4e91
diff -r d263603373ac -r bf7dc5f5bca9 NTPClient.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NTPClient.lib Sun Aug 05 16:17:31 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/NTPClient/#881559865a93
diff -r d263603373ac -r bf7dc5f5bca9 main.cpp --- a/main.cpp Sun Aug 05 16:12:30 2012 +0000 +++ b/main.cpp Sun Aug 05 16:17:31 2012 +0000 @@ -1,47 +1,29 @@ #include "mbed.h" #include "EthernetInterface.h" -#include "HTTPClient.h" +#include "NTPClient.h" EthernetInterface eth; -HTTPClient http; -char str[512]; +NTPClient ntp; int main() { eth.init(); //Use DHCP eth.connect(); - - //GET data - printf("Trying to fetch page...\n"); - int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128); - if (!ret) + + printf("Trying to update time...\r\n"); + if (ntp.setTime("0.pool.ntp.org") == 0) { - printf("Page fetched successfully - read %d characters\n", strlen(str)); - printf("Result: %s\n", str); + 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 - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); - } - - //POST data - HTTPMap map; - HTTPText text(str, 512); - map.put("Hello", "World"); - map.put("test", "1234"); - printf("Trying to post data...\n"); - ret = http.post("http://httpbin.org/post", map, &text); - if (!ret) - { - printf("Executed POST successfully - read %d characters\n", strlen(str)); - printf("Result: %s\n", str); - } - else - { - printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); - } - + printf("Error\r\n"); + } + eth.disconnect(); while(1) {