Twitter API 1.1 test program. (use SuperTweet.net)

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed mpl115a2

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" // basicauth enabled. http://mbed.org/users/kazushi2008/code/HTTPClient/
00004 #include "MPL115A2.h"
00005 
00006 I2C i2c(p9, p10);        // sda, scl
00007 Serial pc(USBTX, USBRX); // tx, rx
00008 
00009 MPL115A2 p_sensor(&i2c);
00010 
00011 EthernetInterface eth;
00012 HTTPClient twitter;
00013 char str[512];
00014 
00015 int main() 
00016 {
00017     char info[128];
00018     
00019     p_sensor.begin();   
00020     p_sensor.ReadSensor();
00021     
00022     sprintf(info, "I am tweeting from my mbed! Pressure = %f, Temperature = %f",  p_sensor.GetPressure(),p_sensor.GetTemperature());
00023     printf("%s",info);
00024 
00025     eth.init(); //Use DHCP
00026 
00027     eth.connect();
00028         
00029     //POST data
00030     HTTPMap map;
00031     HTTPText inText(str, 512);
00032     map.put("status", info);
00033 
00034     printf("\nTrying to post data...\n");
00035     twitter.basicAuth("myuser", "mypass"); //We use basic authentication, replace with you account's parameters
00036     int ret = twitter.post("http://api.supertweet.net/1.1/statuses/update.json", map, &inText);
00037     if (!ret)
00038     {
00039       printf("Executed POST successfully - read %d characters\n", strlen(str));
00040       printf("Result: %s\n", str);
00041     }
00042     else
00043     {
00044       printf("Error - ret = %d - HTTP return code = %d\n", ret, twitter.getHTTPResponseCode());
00045     }
00046         
00047     eth.disconnect();  
00048 
00049     while(1) {
00050     }
00051 }