Temp fork
Dependencies: EthernetInterface NTPClient mbed-rtos mbed
Fork of NTPClient_HelloWorld by
Diff: main.cpp
- Revision:
- 2:bf7dc5f5bca9
- Parent:
- 1:d263603373ac
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) {