Twitter based on Neocat's Arduino Twiiter Lib

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

Fork of HTTPClient_HelloWorld by Donatien Garnier

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*----------------------------------------------------------------
00002 -                                                                -
00003 -  Simple twitter demo application                               -
00004 -  http://mbedtweet.appspot.com/                                 -
00005 -  Written by Escalion, based on ArduinoTweetLib by NeoCat       -
00006 -                                                                -
00007 ----------------------------------------------------------------*/
00008 #include "mbed.h"
00009 #include "EthernetInterface.h"
00010 #include "HTTPClient.h"
00011 
00012 Serial pc(USBTX, USBRX); // tx, rx
00013 EthernetInterface eth;
00014 HTTPClient http;
00015 char str[512];
00016 char ret;
00017 const char *DATA = "Test Tweet From Mbed!";
00018 const char *TOKEN = ""; //get this from http://mbedtweet.appspot.com/
00019 
00020 int main() 
00021 {
00022     eth.init(); //Use DHCP
00023 
00024     eth.connect();
00025     //POST data
00026     HTTPMap map;
00027     HTTPText inText(str, 512);
00028     map.put("token", TOKEN);
00029     map.put("status", DATA);
00030     printf("\nSending server tweet...\n");
00031     ret = http.post("http://mbedtweet.appspot.com/update", map, &inText);
00032     if (!ret)
00033     {
00034       printf("Executed POST successfully - read %d characters\n", strlen(str));
00035       printf("Result: %s\n", str);
00036     }
00037     else
00038     {
00039       printf("Error - ret = %d - HTTP return code = %d\n", str, http.getHTTPResponseCode());
00040     }
00041     
00042     eth.disconnect();  
00043 
00044     while(1) {
00045     }
00046 }