Tweeting with mbed! (using SuperTweet)

Dependencies:   EthernetNetIf NTPClient_NetServices TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
kagamikan
Date:
Sat Jun 11 16:19:38 2011 +0000
Child:
1:5f287a9e95c8
Commit message:

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
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 16:19:38 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 16:19:38 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/TextLCD.lib	Sat Jun 11 16:19:38 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 16:19:38 2011 +0000
@@ -0,0 +1,56 @@
+/*
+ * 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
+
+Serial pc(USBTX, USBRX); // tx, rx
+TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7
+EthernetNetIf eth;
+
+int main() {
+  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
+
+  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];
+  strftime(ts, 32, "%I:%M %p\n", localtime(&sec));
+  sprintf(tweet, "%s (%s's mbed at %s UTC) #udenokai", message, name, ts);
+
+  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 16:19:38 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912