mbed_twitter
Dependencies: EthernetNetIf mbed ID12RFID
main.cpp@0:3198150a151c, 2012-01-26 (annotated)
- Committer:
- vkarthikr
- Date:
- Thu Jan 26 12:41:36 2012 +0000
- Revision:
- 0:3198150a151c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vkarthikr | 0:3198150a151c | 1 | // RFID Tweeter |
vkarthikr | 0:3198150a151c | 2 | /* |
vkarthikr | 0:3198150a151c | 3 | The basic authentication service for twitter is going down. |
vkarthikr | 0:3198150a151c | 4 | To continue using that program, the code has been updated to use http://supertweet.net which acts as an API proxy. |
vkarthikr | 0:3198150a151c | 5 | Simply visit the website to setup your twitter account for this API. |
vkarthikr | 0:3198150a151c | 6 | See: http://www.supertweet.net/about/documentation |
vkarthikr | 0:3198150a151c | 7 | */ |
vkarthikr | 0:3198150a151c | 8 | |
vkarthikr | 0:3198150a151c | 9 | #include "mbed.h" |
vkarthikr | 0:3198150a151c | 10 | #include "ID12RFID.h" |
vkarthikr | 0:3198150a151c | 11 | #include "EthernetNetIf.h" |
vkarthikr | 0:3198150a151c | 12 | #include "HTTPClient.h" |
vkarthikr | 0:3198150a151c | 13 | |
vkarthikr | 0:3198150a151c | 14 | #define TWITTER_USER "mbed_cloud" |
vkarthikr | 0:3198150a151c | 15 | #define TWITTER_PASSWORD "password" |
vkarthikr | 0:3198150a151c | 16 | |
vkarthikr | 0:3198150a151c | 17 | #define ACTIVE 1 |
vkarthikr | 0:3198150a151c | 18 | #define INACTIVE 0 |
vkarthikr | 0:3198150a151c | 19 | |
vkarthikr | 0:3198150a151c | 20 | |
vkarthikr | 0:3198150a151c | 21 | |
vkarthikr | 0:3198150a151c | 22 | const char* names_list[2] = {"Prasanna", "Ganesh"}; |
vkarthikr | 0:3198150a151c | 23 | |
vkarthikr | 0:3198150a151c | 24 | EthernetNetIf ethernet; |
vkarthikr | 0:3198150a151c | 25 | HTTPClient twitter; |
vkarthikr | 0:3198150a151c | 26 | |
vkarthikr | 0:3198150a151c | 27 | DigitalIn RFID(p11); |
vkarthikr | 0:3198150a151c | 28 | DigitalOut PersonDetected(LED1); |
vkarthikr | 0:3198150a151c | 29 | DigitalOut tweet_ok(LED4); |
vkarthikr | 0:3198150a151c | 30 | |
vkarthikr | 0:3198150a151c | 31 | int main() |
vkarthikr | 0:3198150a151c | 32 | { |
vkarthikr | 0:3198150a151c | 33 | |
vkarthikr | 0:3198150a151c | 34 | int GoAhead = 0,i=0,count =0; |
vkarthikr | 0:3198150a151c | 35 | char text[5]; |
vkarthikr | 0:3198150a151c | 36 | ethernet.setup(); |
vkarthikr | 0:3198150a151c | 37 | twitter.basicAuth(TWITTER_USER, TWITTER_PASSWORD); |
vkarthikr | 0:3198150a151c | 38 | |
vkarthikr | 0:3198150a151c | 39 | while(true) |
vkarthikr | 0:3198150a151c | 40 | { |
vkarthikr | 0:3198150a151c | 41 | |
vkarthikr | 0:3198150a151c | 42 | GoAhead = 0; |
vkarthikr | 0:3198150a151c | 43 | if(ACTIVE == RFID) |
vkarthikr | 0:3198150a151c | 44 | { |
vkarthikr | 0:3198150a151c | 45 | // wait(1); |
vkarthikr | 0:3198150a151c | 46 | if(ACTIVE == RFID) |
vkarthikr | 0:3198150a151c | 47 | { |
vkarthikr | 0:3198150a151c | 48 | GoAhead = 1; |
vkarthikr | 0:3198150a151c | 49 | } |
vkarthikr | 0:3198150a151c | 50 | else |
vkarthikr | 0:3198150a151c | 51 | { |
vkarthikr | 0:3198150a151c | 52 | GoAhead = 0; |
vkarthikr | 0:3198150a151c | 53 | } |
vkarthikr | 0:3198150a151c | 54 | } |
vkarthikr | 0:3198150a151c | 55 | |
vkarthikr | 0:3198150a151c | 56 | if(1 == GoAhead) |
vkarthikr | 0:3198150a151c | 57 | { |
vkarthikr | 0:3198150a151c | 58 | |
vkarthikr | 0:3198150a151c | 59 | HTTPMap msg; |
vkarthikr | 0:3198150a151c | 60 | PersonDetected = 1; |
vkarthikr | 0:3198150a151c | 61 | snprintf(text, sizeof(text), " %d", count++); |
vkarthikr | 0:3198150a151c | 62 | msg["status"] = text; |
vkarthikr | 0:3198150a151c | 63 | |
vkarthikr | 0:3198150a151c | 64 | ///////Dont Change above here |
vkarthikr | 0:3198150a151c | 65 | |
vkarthikr | 0:3198150a151c | 66 | |
vkarthikr | 0:3198150a151c | 67 | |
vkarthikr | 0:3198150a151c | 68 | msg["status"] += " Hi friend, "; |
vkarthikr | 0:3198150a151c | 69 | msg["status"] += " Final Testing "; |
vkarthikr | 0:3198150a151c | 70 | // msg["status"] += "For you all "; |
vkarthikr | 0:3198150a151c | 71 | msg["status"] += names_list[i]; |
vkarthikr | 0:3198150a151c | 72 | msg["status"] += " arrived"; |
vkarthikr | 0:3198150a151c | 73 | |
vkarthikr | 0:3198150a151c | 74 | printf("\n testing in computer"); |
vkarthikr | 0:3198150a151c | 75 | |
vkarthikr | 0:3198150a151c | 76 | |
vkarthikr | 0:3198150a151c | 77 | |
vkarthikr | 0:3198150a151c | 78 | ///////Dont Change from here |
vkarthikr | 0:3198150a151c | 79 | HTTPResult r = twitter.post("http://api.supertweet.net/1/statuses/update.xml", msg, NULL); |
vkarthikr | 0:3198150a151c | 80 | tweet_ok = !r; |
vkarthikr | 0:3198150a151c | 81 | if(0 == r) |
vkarthikr | 0:3198150a151c | 82 | { |
vkarthikr | 0:3198150a151c | 83 | wait(2); |
vkarthikr | 0:3198150a151c | 84 | } |
vkarthikr | 0:3198150a151c | 85 | |
vkarthikr | 0:3198150a151c | 86 | |
vkarthikr | 0:3198150a151c | 87 | i++; |
vkarthikr | 0:3198150a151c | 88 | if(i>1) |
vkarthikr | 0:3198150a151c | 89 | { |
vkarthikr | 0:3198150a151c | 90 | i = 0; |
vkarthikr | 0:3198150a151c | 91 | } |
vkarthikr | 0:3198150a151c | 92 | } |
vkarthikr | 0:3198150a151c | 93 | // wait(3); |
vkarthikr | 0:3198150a151c | 94 | tweet_ok = 0; |
vkarthikr | 0:3198150a151c | 95 | PersonDetected = 0; |
vkarthikr | 0:3198150a151c | 96 | // wait(2); |
vkarthikr | 0:3198150a151c | 97 | |
vkarthikr | 0:3198150a151c | 98 | } |
vkarthikr | 0:3198150a151c | 99 | } |