JST時間と固定のメッセージをツイートするよ
Dependencies: EthernetNetIf NTPClient_NetServices TextLCD mbed
Diff: main.cpp
- Revision:
- 0:9235a8e0a631
diff -r 000000000000 -r 9235a8e0a631 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Jun 11 19:40:57 2011 +0000 @@ -0,0 +1,78 @@ +/* + * UDENOKAI #5 SAMPLE PROGRAM: Tweeting with mbed! + * + * Using SuperTweet.Net API Proxy (setup required). + * Based on cookbook/Twitter + */ +#include "mbed.h" +#include "EthernetNetIf.h" +#include "HTTPClient.h" +#include "TextLCD.h" // Orange Board + +//tuika +#include "NTPClient.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() { + char message[64], name[32], twID[32], twPW[32]; + sprintf(message, "hogehogefugafuga"); + sprintf(name, "@hoge"); // ex) @kagamikan + sprintf(twID, "foo"); // ex) udenokai + sprintf(twPW, "boo"); // ex) hoge + time_t ctTime; + + pc.printf("\r\nSetting up...\r\n"); + lcd.printf("Setting up..."); + EthernetErr ethErr = eth.setup(); + if(ethErr) { + printf("Error %d in setup.\n", ethErr); + lcd.printf("\nError %d in setup.", ethErr); + return -1; + } + IpAddr ip = eth.getIp(); + pc.printf("\r\nSetup OK\r\n"); + lcd.cls(); + lcd.printf("IP Address:\n%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); + + time_t sec = time(NULL); + char tweet[128], ts[32]; + + + + //kokowotuika + Host server(IpAddr(), 123, "ntp.nict.jp"); + ntp.setTime(server); + ctTime = time(NULL); + ctTime += 32400; //set jst time + + //localtime no hikisuu wo henkou + strftime(ts, 32, "%I:%M %p\n", localtime(&ctTime)); + + + + sprintf(tweet, "%s (%s's mbed at %s JST) #udenokai", message, name, ts); + pc.printf( "%s (%s's mbed at %s JST) #udenokai", message, name , ts); //console nimo tui-to naiyou wo dasu + + HTTPClient twitter; + HTTPMap msg; + msg["status"] = tweet; + twitter.basicAuth(twID, twPW); + HTTPResult r = twitter.post("http://api.supertweet.net/1/statuses/update.xml", msg, NULL); + if(r == HTTP_OK) { + pc.printf("Tweet success!\n"); + lcd.cls(); + lcd.printf("\nTweet success!"); + } else { + pc.printf("Tweet failed (Code:%d)\n", r); + lcd.cls(); + lcd.printf("\nTweet failed (%d)", r); + } + + + return 0; +} \ No newline at end of file