japanese tweeting sample with newer version libraries

Dependencies:   TextLCD mbed

Committer:
nxpfan
Date:
Fri Aug 31 08:29:07 2012 +0000
Revision:
1:57304b082776
Parent:
0:66c7c9c4f765
mbed-lib has been updated also

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxpfan 0:66c7c9c4f765 1 /*
nxpfan 0:66c7c9c4f765 2 Update: 21-06-2010
nxpfan 0:66c7c9c4f765 3 The basic authentication service for twitter is going down at the end of the week.
nxpfan 0:66c7c9c4f765 4 To continue using that program, the code has been updated to use http://supertweet.net which acts as an API proxy.
nxpfan 0:66c7c9c4f765 5 Simply visit the website to setup your twitter account for this API.
nxpfan 0:66c7c9c4f765 6 See: http://www.supertweet.net/about/documentation
nxpfan 0:66c7c9c4f765 7 */
nxpfan 0:66c7c9c4f765 8
nxpfan 0:66c7c9c4f765 9 #include "mbed.h"
nxpfan 0:66c7c9c4f765 10 #include "EthernetNetIf.h"
nxpfan 0:66c7c9c4f765 11 #include "HTTPClient.h"
nxpfan 0:66c7c9c4f765 12 #include "TextLCD.h"
nxpfan 0:66c7c9c4f765 13
nxpfan 0:66c7c9c4f765 14 TextLCD lcd(p24, p25, p26, p27, p28, p29); // rs, e, d0-d3
nxpfan 0:66c7c9c4f765 15 //TextLCD lcd( p24, p26, p27, p28, p29, p30 ); // rs, e, d0-d3
nxpfan 0:66c7c9c4f765 16
nxpfan 0:66c7c9c4f765 17 EthernetNetIf eth;
nxpfan 0:66c7c9c4f765 18
nxpfan 0:66c7c9c4f765 19 int main() {
nxpfan 0:66c7c9c4f765 20
nxpfan 0:66c7c9c4f765 21 printf("Init\n"); lcd.locate( 0, 0 ); lcd.printf("Init ");
nxpfan 0:66c7c9c4f765 22 printf("\r\nSetting up...\r\n"); lcd.locate( 0, 0 ); lcd.printf("Setting up ");
nxpfan 0:66c7c9c4f765 23
nxpfan 0:66c7c9c4f765 24 EthernetErr ethErr = eth.setup();
nxpfan 0:66c7c9c4f765 25 if(ethErr)
nxpfan 0:66c7c9c4f765 26 {
nxpfan 0:66c7c9c4f765 27 printf("Error %d in setup.\n", ethErr); lcd.locate( 0, 0 ); lcd.printf("error %d", ethErr);
nxpfan 0:66c7c9c4f765 28 return -1;
nxpfan 0:66c7c9c4f765 29 }
nxpfan 0:66c7c9c4f765 30 printf("\r\nSetup OK\r\n"); lcd.locate( 0, 0 ); lcd.printf("Setup OK ");
nxpfan 0:66c7c9c4f765 31
nxpfan 0:66c7c9c4f765 32 HTTPClient twitter;
nxpfan 0:66c7c9c4f765 33
nxpfan 0:66c7c9c4f765 34 HTTPMap msg;
nxpfan 0:66c7c9c4f765 35
nxpfan 0:66c7c9c4f765 36 //msg["status"] = "twitter test AAAA"; //A good example of Key/Value pair use with Web APIs
nxpfan 0:66c7c9c4f765 37 LocalFileSystem local("local");
nxpfan 0:66c7c9c4f765 38 char s[256];
nxpfan 0:66c7c9c4f765 39 FILE *fp;
nxpfan 0:66c7c9c4f765 40
nxpfan 0:66c7c9c4f765 41 printf("\r\nreading a message file.\r\n");
nxpfan 0:66c7c9c4f765 42
nxpfan 0:66c7c9c4f765 43 if(NULL == (fp = fopen("/local/tweet.txt","r")) ) {
nxpfan 0:66c7c9c4f765 44 printf("\r\nError: The message file cannot be accessed\r\n"); lcd.locate( 0, 0 ); lcd.printf("File access error");
nxpfan 0:66c7c9c4f765 45 return -1;
nxpfan 0:66c7c9c4f765 46 }
nxpfan 0:66c7c9c4f765 47
nxpfan 0:66c7c9c4f765 48 fgets(s,256,fp);
nxpfan 0:66c7c9c4f765 49 fclose(fp);
nxpfan 0:66c7c9c4f765 50
nxpfan 0:66c7c9c4f765 51 msg["status"] = s; lcd.locate( 0, 0 ); lcd.printf("File read done ");
nxpfan 0:66c7c9c4f765 52 twitter.basicAuth("USER_ID", "PASSWORD"); //We use basic authentication, replace with you account's parameters
nxpfan 0:66c7c9c4f765 53
nxpfan 0:66c7c9c4f765 54 //No need to retieve data sent back by the server
nxpfan 0:66c7c9c4f765 55 HTTPResult r = twitter.post("http://api.supertweet.net/1/statuses/update.xml", msg, NULL);
nxpfan 0:66c7c9c4f765 56 if( r == HTTP_OK )
nxpfan 0:66c7c9c4f765 57 {
nxpfan 0:66c7c9c4f765 58 printf("Tweet sent with success!\n"); lcd.locate( 0, 0 ); lcd.printf("Done ");
nxpfan 0:66c7c9c4f765 59 }
nxpfan 0:66c7c9c4f765 60 else
nxpfan 0:66c7c9c4f765 61 {
nxpfan 0:66c7c9c4f765 62 printf("Problem during tweeting, return code %d\n", r);lcd.locate( 0, 0 ); lcd.printf("Got error ");
nxpfan 0:66c7c9c4f765 63 }
nxpfan 0:66c7c9c4f765 64
nxpfan 0:66c7c9c4f765 65 return 0;
nxpfan 0:66c7c9c4f765 66
nxpfan 0:66c7c9c4f765 67 }