Use StewGate sample

Dependencies:   EthernetInterface HTTPClient NTPClient mbed-rtos mbed

Fork of HTTPClient_HelloWorld by Donatien Garnier

StewGateを使ってメンションを取得・ツイートするサンプルです。 main.cppの40行目を各自StewGateで取得したトークンを入力してください。 main.cppの45行目が0のとき、ツイートします。1でメンション取得です。

Revision:
3:9c0e1bc428ea
Parent:
2:270e2d0bb85a
--- a/main.cpp	Thu Aug 30 15:42:06 2012 +0000
+++ b/main.cpp	Tue Mar 18 16:05:43 2014 +0000
@@ -1,37 +1,57 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 #include "HTTPClient.h"
+#include "NTPClient.h"
+#include <time.h>
+#include <locale.h>
 
+Serial pc(USBTX, USBRX); // tx, rx
 EthernetInterface eth;
 HTTPClient http;
+NTPClient ntp;
 char str[512];
+char JSTTime[128];
 
 int main() 
 {
     eth.init(); //Use DHCP
+    eth.connect();
+    printf("IP Address is %s\n", eth.getIPAddress());
 
-    eth.connect();
-    
-    //GET data
-    printf("\nTrying to fetch page...\n");
-    int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
-    if (!ret)
+    printf("Trying to update time...\r\n");
+    if (ntp.setTime("0.pool.ntp.org") == 0)
     {
-      printf("Page fetched successfully - read %d characters\n", strlen(str));
-      printf("Result: %s\n", str);
+      printf("Set time successfully\r\n");
+      time_t ctTime;
+      ctTime = time(NULL);
+      ctTime += 32400;  //Conv UTC to JST
+      sprintf(JSTTime,"%s", ctime(&ctTime));
+      printf("%s",JSTTime);
     }
     else
     {
-      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-    }
-    
-    //POST data
+      printf("Error\r\n");
+    } 
     HTTPMap map;
     HTTPText inText(str, 512);
-    map.put("Hello", "World");
-    map.put("test", "1234");
-    printf("\nTrying to post data...\n");
-    ret = http.post("http://httpbin.org/post", map, &inText);
+/******************************************************/
+//Input your StewGate Token
+/******************************************************/
+    const char StewGate_Token[] = "";
+    map.put("_t", StewGate_Token);
+/****************************************/
+// Switch Get Tweet or Post Tweet
+/****************************************/
+#if 0
+    printf("\nTrying to Get Tweet\n");
+    int ret = http.post("http://stewgate-u.appspot.com/api/last_mention/", map, &inText);
+#else
+    char PostTweet[512];
+    sprintf(PostTweet,"test in mbed %s",JSTTime);
+    map.put("msg", PostTweet);
+    printf("\nTrying to Post Tweet\n");
+    int ret = http.post("http://stewgate-u.appspot.com/api/post/", map, &inText);
+#endif
     if (!ret)
     {
       printf("Executed POST successfully - read %d characters\n", strlen(str));
@@ -40,38 +60,7 @@
     else
     {
       printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-    }
-    
-    //PUT data
-    strcpy(str, "This is a PUT test!");
-    HTTPText outText(str);
-    //HTTPText inText(str, 512);
-    printf("\nTrying to put resource...\n");
-    ret = http.put("http://httpbin.org/put", outText, &inText);
-    if (!ret)
-    {
-      printf("Executed PUT successfully - read %d characters\n", strlen(str));
-      printf("Result: %s\n", str);
-    }
-    else
-    {
-      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-    }
-    
-    //DELETE data
-    //HTTPText inText(str, 512);
-    printf("\nTrying to delete resource...\n");
-    ret = http.del("http://httpbin.org/delete", &inText);
-    if (!ret)
-    {
-      printf("Executed DELETE successfully - read %d characters\n", strlen(str));
-      printf("Result: %s\n", str);
-    }
-    else
-    {
-      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-    }
-    
+    }    
     eth.disconnect();  
 
     while(1) {