a

Dependencies:   EthernetNetIf HTTPClient mbed

Fork of TwitterExample by Donatien Garnier

Committer:
donatien
Date:
Mon Jun 14 10:29:54 2010 +0000
Revision:
0:96e3b1c49f9b
Child:
2:2a9775a81062

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:96e3b1c49f9b 1 #include "mbed.h"
donatien 0:96e3b1c49f9b 2 #include "EthernetNetIf.h"
donatien 0:96e3b1c49f9b 3 #include "HTTPClient.h"
donatien 0:96e3b1c49f9b 4
donatien 0:96e3b1c49f9b 5 EthernetNetIf eth;
donatien 0:96e3b1c49f9b 6
donatien 0:96e3b1c49f9b 7 int main() {
donatien 0:96e3b1c49f9b 8
donatien 0:96e3b1c49f9b 9 printf("Init\n");
donatien 0:96e3b1c49f9b 10
donatien 0:96e3b1c49f9b 11 printf("\r\nSetting up...\r\n");
donatien 0:96e3b1c49f9b 12 EthernetErr ethErr = eth.setup();
donatien 0:96e3b1c49f9b 13 if(ethErr)
donatien 0:96e3b1c49f9b 14 {
donatien 0:96e3b1c49f9b 15 printf("Error %d in setup.\n", ethErr);
donatien 0:96e3b1c49f9b 16 return -1;
donatien 0:96e3b1c49f9b 17 }
donatien 0:96e3b1c49f9b 18 printf("\r\nSetup OK\r\n");
donatien 0:96e3b1c49f9b 19
donatien 0:96e3b1c49f9b 20 HTTPClient twitter;
donatien 0:96e3b1c49f9b 21
donatien 0:96e3b1c49f9b 22 HTTPMap msg;
donatien 0:96e3b1c49f9b 23 msg["status"] = "I am tweeting from my mbed!"; //A good example of Key/Value pair use with Web APIs
donatien 0:96e3b1c49f9b 24
donatien 0:96e3b1c49f9b 25 twitter.basicAuth("myuser", "mypass"); //We use basic authentication, replace with you account's parameters
donatien 0:96e3b1c49f9b 26
donatien 0:96e3b1c49f9b 27 //No need to retieve data sent back by the server
donatien 0:96e3b1c49f9b 28 HTTPResult r = twitter.post("http://twitter.com/statuses/update.xml", msg, NULL);
donatien 0:96e3b1c49f9b 29 if( r == HTTP_OK )
donatien 0:96e3b1c49f9b 30 {
donatien 0:96e3b1c49f9b 31 printf("Tweet sent with success!\n");
donatien 0:96e3b1c49f9b 32 }
donatien 0:96e3b1c49f9b 33 else
donatien 0:96e3b1c49f9b 34 {
donatien 0:96e3b1c49f9b 35 printf("Problem during tweeting, return code %d\n", r);
donatien 0:96e3b1c49f9b 36 }
donatien 0:96e3b1c49f9b 37
donatien 0:96e3b1c49f9b 38 return 0;
donatien 0:96e3b1c49f9b 39
donatien 0:96e3b1c49f9b 40 }