At the first, please get the token from Stewgate.

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 #include "HTTPClient.h"
00004 #include "rtos.h"
00005 
00006 DigitalOut myled(LED1);
00007 
00008 int main() {
00009     EthernetInterface eth;
00010     int retEth;
00011     HTTPClient http;
00012     int rethttp;
00013     //EthernetInterface eth;
00014     //HTTPClient http;
00015     char str[512];
00016     
00017     
00018     printf("Setting up ...\r\n");
00019     //ネットワークの初期設定DCHPを利用してネットワークを自動で設定している
00020     eth.init();
00021     retEth = eth.connect();
00022     
00023     //ネットワークの状況をprintfで表示
00024     if(!retEth)
00025     {
00026         printf("Network Setup OK\r\n");
00027             //POSTメソッドでstewgateにDataを送信
00028         //POST data
00029         HTTPMap map;
00030         HTTPText inText(str, 512);
00031         map.put("_t","your_token");
00032         map.put("msg","Tweet from mbed!! using stewgate");
00033         printf("\nTrying to post data...\n");
00034         rethttp = http.post("http://stewgate-u.appspot.com/api/post/", map, &inText);
00035         if (!rethttp)
00036         {
00037             printf("Executed POST successfully - read %d characters\n", strlen(str));
00038             printf("Result: %s\n", str);
00039         }
00040         else
00041         {
00042             printf("Error - ret = %d - HTTP return code = %d\n", rethttp,http.getHTTPResponseCode());
00043         }
00044     }
00045     else
00046     {
00047         printf("Network Error %d\r\n",retEth);
00048         
00049     }
00050     
00051 
00052 
00053     eth.disconnect();  
00054  
00055     while(1) {
00056         myled=0;
00057         wait(0.5);
00058         myled=1;
00059     }
00060 
00061 }