Tweeting with mbed! (using SuperTweet)
Dependencies: EthernetNetIf NTPClient_NetServices TextLCD mbed
Diff: main.cpp
- Revision:
- 1:5f287a9e95c8
- Parent:
- 0:2e771f40cf84
--- a/main.cpp Sat Jun 11 16:19:38 2011 +0000 +++ b/main.cpp Tue Jun 14 09:25:04 2011 +0000 @@ -7,19 +7,24 @@ #include "mbed.h" #include "EthernetNetIf.h" #include "HTTPClient.h" -#include "TextLCD.h" // Orange Board +#include "NTPClient.h" +#include "TextLCD.h" Serial pc(USBTX, USBRX); // tx, rx TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7 EthernetNetIf eth; +NTPClient ntp; int main() { + + // Tweet informations char message[64], name[32], twID[32], twPW[32]; sprintf(message, "hogehogefugafuga"); - sprintf(name, "INPUT_YOUR_NAME"); // ex) @kagamikan - sprintf(twID, "INPUT_YOUR_ID"); // ex) udenokai - sprintf(twPW, "INPUT_YOUR_PASSWORD"); // ex) hoge + sprintf(name, "hoge"); // ex) @kagamikan + sprintf(twID, "fuga"); // ex) udenokai + sprintf(twPW, "piyo"); // ex) hoge + // Setup IP Network pc.printf("\r\nSetting up...\r\n"); lcd.printf("Setting up..."); EthernetErr ethErr = eth.setup(); @@ -33,12 +38,21 @@ lcd.cls(); lcd.printf("IP Address:\n%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); - time_t sec = time(NULL); + // Setting time with NTP + Host server(IpAddr(), 123, "ntp.nict.jp"); + ntp.setTime(server); + time_t ctTime; + ctTime = time(NULL); + ctTime += 32400; //set jst time + + // Building the tweet char tweet[128], ts[32]; - strftime(ts, 32, "%I:%M %p\n", localtime(&sec)); - sprintf(tweet, "%s (%s's mbed at %s UTC) #udenokai", message, name, ts); + strftime(ts, 32, "%I:%M %p\n", localtime(&ctTime)); + sprintf(tweet, "%s (%s's mbed at %s JST) #udenokai", message, name, ts); + pc.printf(tweet); - HTTPClient twitter; + // Sending the tweet + HTTPClient twitter; HTTPMap msg; msg["status"] = tweet; twitter.basicAuth(twID, twPW); @@ -52,5 +66,6 @@ lcd.cls(); lcd.printf("\nTweet failed (%d)", r); } + return 0; } \ No newline at end of file