Twitter client that can be directly tweet. (Intermediate server is not required.)
Dependencies: EthernetInterface HTTPClient-wolfSSL NTPClient OAuth4Tw mbed-rtos mbed wolfSSL
Fork of OAuth4Tw by
Diff: main.cpp
- Revision:
- 5:f0c0128cde62
- Parent:
- 4:fcadeb9bdcbd
- Child:
- 6:f5189d4f109f
diff -r fcadeb9bdcbd -r f0c0128cde62 main.cpp --- a/main.cpp Wed Jul 08 14:55:36 2015 +0000 +++ b/main.cpp Tue Jul 14 09:54:39 2015 +0000 @@ -13,7 +13,13 @@ "000000000-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // Access token "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); // Access token secret -static char res_buffer[1024] = ""; +#if defined(TARGET_LPC1768) +static char res_buffer[512]; +#elif defined(TARGET_K64F) +static char res_buffer[4096]; +#else +#error not tested platform. +#endif int main() { @@ -75,9 +81,9 @@ HTTPText res(res_buffer, sizeof(res_buffer)); while (1) { +#if 0 { char url[128]; - char post[128]; //TODO: fix required. need saving memory. time(&ctTime); @@ -85,20 +91,45 @@ "https://api.twitter.com/1.1/statuses/update.json" "?status=Hello World! - %s", ctime(&ctTime)); - HTTPResult result = oa4t.post(url, post, &res); + res_buffer[0] = '\0'; + HTTPResult result = oa4t.post(url, &res); printf("POST result = %d\n%s\n", result, res_buffer); } +#else + { + std::vector<std::string> post; + post.reserve(3); + + char status[64]; + char location_lat[24]; + char location_long[24]; + + time(&ctTime); + + snprintf(status, sizeof(status), "status=Hello Fujiyama! - %s", ctime(&ctTime)); + snprintf(location_lat, sizeof(location_lat), "lat=%f", 35.359577); + snprintf(location_long, sizeof(location_long), "long=%f", 138.731414); + post.push_back(status); + post.push_back(location_lat); + post.push_back(location_long); + + res_buffer[0] = '\0'; + HTTPResult result = oa4t.post("https://api.twitter.com/1.1/statuses/update.json", &post, &res); + printf("POST result = %d\n%s\n", result, res_buffer); + } +#endif { const char url[] = "https://api.twitter.com/1.1/users/show.json" "?screen_name=twitter"; + res_buffer[0] = '\0'; HTTPResult result = oa4t.get(url, &res); printf("GET result = %d\n%s\n", result, res_buffer); } - // Wait 300 seconds for next time. - for (int t=0; t<300; t++) { + // Wait 60 seconds for next time. + for (int t=0; t<60; t++) { myled = 1; wait(0.2); myled = 0;