JST時間と固定のメッセージをツイートするよ

Dependencies:   EthernetNetIf NTPClient_NetServices TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
meisei0517
Date:
Sat Jun 11 19:40:57 2011 +0000
Commit message:
Tweet4Udenokai-kai

Changed in this revision

EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
NTPClient.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Sat Jun 11 19:40:57 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Sat Jun 11 19:40:57 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#d0be6af2d1db
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NTPClient.lib	Sat Jun 11 19:40:57 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/NTPClient/#7c3f1199256a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Sat Jun 11 19:40:57 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jun 11 19:40:57 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912