This is made by seminal03_SIT_mechanical_engineering. This quotes ban4jp"CyaSSL_Twitter-OAuth4Tw".
Dependencies: EthernetInterface HTTPClient-wolfSSL NTPClient OAuth4Tw mbed-rtos mbed wolfSSL
Fork of CyaSSL-Twitter-OAuth4Tw by
Diff: main.cpp
- Revision:
- 2:392b8e079c7a
- Parent:
- 1:4dfa9d41f414
- Child:
- 4:fcadeb9bdcbd
--- a/main.cpp Sun Dec 14 08:08:14 2014 +0000 +++ b/main.cpp Sun Feb 01 17:39:08 2015 +0000 @@ -34,18 +34,45 @@ printf("Trying to update time...\n"); - //ret = ntp.setTime("pool.ntp.org"); - ret = ntp.setTime("ntp.nict.jp"); - if (!ret) { - time_t ctTime = time(NULL); - printf("Time is set to (UTC): %s\n", ctime(&ctTime)); - } else { - printf("Error\n"); + time_t ctTime; + NTPResult result; + + while(1) { + result = ntp.setTime("pool.ntp.org"); + //result = ntp.setTime("pool.ntp.org", NTP_DEFAULT_PORT, 2000); + + if (result == NTP_OK) { + time(&ctTime); + printf("Time is set to (UTC): %s\n", ctime(&ctTime)); + break; + } + + switch (result) { + case NTP_CONN: ///<Connection error + printf("Connection error\n"); + break; + case NTP_TIMEOUT: ///<Connection timeout + printf("Connection timeout\n"); + break; + case NTP_PRTCL: ///<Protocol error + printf("Protocol error\n"); + break; + case NTP_DNS: ///<Could not resolve name + printf("Could not resolve name\n"); + break; + default: + printf("Error result=%d\n", result); + return -1; + } + + wait(5); } std::string uri = "https://api.twitter.com/1.1/statuses/update.json"; uri += "?status="; uri += OAuth4Tw::url_escape("Hello World!"); + uri += OAuth4Tw::url_escape(" - "); + uri += OAuth4Tw::url_escape(ctime(&ctTime)); std::string postarg; std::string postres = oa4t.post(uri.c_str(), postarg); printf("postres: %s\n", postres.c_str());