This program post the tweet with random number. It make random seed with open analog pin. On your try, please change username and password for your accounts.
main.cpp@0:aa8f8270834a, 2009-12-01 (annotated)
- Committer:
- utaani
- Date:
- Tue Dec 01 12:43:27 2009 +0000
- Revision:
- 0:aa8f8270834a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
utaani | 0:aa8f8270834a | 1 | // twitter client test |
utaani | 0:aa8f8270834a | 2 | // written by utaani@ueno.org |
utaani | 0:aa8f8270834a | 3 | |
utaani | 0:aa8f8270834a | 4 | #include "mbed.h" |
utaani | 0:aa8f8270834a | 5 | #include "HTTPClient.h" |
utaani | 0:aa8f8270834a | 6 | #define DEBUG |
utaani | 0:aa8f8270834a | 7 | |
utaani | 0:aa8f8270834a | 8 | DigitalOut led(LED1); // for finised indicator |
utaani | 0:aa8f8270834a | 9 | HTTPClient http; // twitter client |
utaani | 0:aa8f8270834a | 10 | |
utaani | 0:aa8f8270834a | 11 | #ifdef DEBUG |
utaani | 0:aa8f8270834a | 12 | Serial pc(USBTX, USBRX); // for debug |
utaani | 0:aa8f8270834a | 13 | #endif |
utaani | 0:aa8f8270834a | 14 | |
utaani | 0:aa8f8270834a | 15 | AnalogIn seed(p15); // for random seed |
utaani | 0:aa8f8270834a | 16 | |
utaani | 0:aa8f8270834a | 17 | const char user[] = "username"; |
utaani | 0:aa8f8270834a | 18 | const char pass[] = "password"; |
utaani | 0:aa8f8270834a | 19 | const char url[] = "http://twitter.com/statuses/update.xml"; |
utaani | 0:aa8f8270834a | 20 | |
utaani | 0:aa8f8270834a | 21 | int main(void) { |
utaani | 0:aa8f8270834a | 22 | char response[4096]; // buffer for results |
utaani | 0:aa8f8270834a | 23 | char msg[1024]; // buffer for messages |
utaani | 0:aa8f8270834a | 24 | int result,i; |
utaani | 0:aa8f8270834a | 25 | |
utaani | 0:aa8f8270834a | 26 | srand(seed.read_u16()); // init random with AnalogIn (for multipul post) |
utaani | 0:aa8f8270834a | 27 | sprintf(msg, "status=This is test from mbed.(%d)", rand()%100); // make message |
utaani | 0:aa8f8270834a | 28 | |
utaani | 0:aa8f8270834a | 29 | #ifdef DEBUG |
utaani | 0:aa8f8270834a | 30 | pc.printf("started\r\n"); |
utaani | 0:aa8f8270834a | 31 | #endif |
utaani | 0:aa8f8270834a | 32 | |
utaani | 0:aa8f8270834a | 33 | http.auth(user, pass); |
utaani | 0:aa8f8270834a | 34 | result = http.post(url, msg, response, 4096); |
utaani | 0:aa8f8270834a | 35 | |
utaani | 0:aa8f8270834a | 36 | #ifdef DEBUG |
utaani | 0:aa8f8270834a | 37 | pc.printf("result=%d\r\n",result); |
utaani | 0:aa8f8270834a | 38 | for(i=0;i<result;i++) { |
utaani | 0:aa8f8270834a | 39 | pc.putc(response[i]); |
utaani | 0:aa8f8270834a | 40 | } |
utaani | 0:aa8f8270834a | 41 | pc.printf("\r\n"); |
utaani | 0:aa8f8270834a | 42 | #endif |
utaani | 0:aa8f8270834a | 43 | |
utaani | 0:aa8f8270834a | 44 | // finished loop |
utaani | 0:aa8f8270834a | 45 | while(1) { |
utaani | 0:aa8f8270834a | 46 | led = !led; |
utaani | 0:aa8f8270834a | 47 | wait(0.2); |
utaani | 0:aa8f8270834a | 48 | } |
utaani | 0:aa8f8270834a | 49 | } |