Dependencies:   EthernetNetIf mbed

Committer:
donatien
Date:
Mon Jun 21 09:06:18 2010 +0000
Revision:
2:2d0011b9bb1e
Parent:
0:c292522f5311
Child:
4:45a7d7fc1161

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:c292522f5311 1 // RFID Tweeter
donatien 2:2d0011b9bb1e 2 /*
donatien 2:2d0011b9bb1e 3 Update: 21-06-2010
donatien 2:2d0011b9bb1e 4 The basic authentication service for twitter is going down at the end of the week.
donatien 2:2d0011b9bb1e 5 To continue using that program, the code has been updated to use http://supertweet.net which acts as an API proxy.
donatien 2:2d0011b9bb1e 6 Simply visit the website to setup your twitter account for this API.
donatien 2:2d0011b9bb1e 7 See: http://www.supertweet.net/about/documentation
donatien 2:2d0011b9bb1e 8 */
donatien 0:c292522f5311 9
donatien 0:c292522f5311 10 #include "mbed.h"
donatien 0:c292522f5311 11 #include "ID12RFID.h"
donatien 0:c292522f5311 12 #include "EthernetNetIf.h"
donatien 0:c292522f5311 13 #include "HTTPClient.h"
donatien 0:c292522f5311 14
donatien 0:c292522f5311 15 #define TWITTER_USER "donatiengarnier"
donatien 0:c292522f5311 16 #define TWITTER_PASSWORD "myverysecurepassword"
donatien 0:c292522f5311 17
donatien 0:c292522f5311 18 #define IDS_COUNT 3
donatien 0:c292522f5311 19 const int ids_list[IDS_COUNT] = {89481809, 89481810, 89481811};
donatien 0:c292522f5311 20 const char* names_list[IDS_COUNT] = {"Donatien", "Simon", "Dan"};
donatien 0:c292522f5311 21
donatien 0:c292522f5311 22 EthernetNetIf ethernet;
donatien 0:c292522f5311 23 HTTPClient twitter;
donatien 0:c292522f5311 24
donatien 0:c292522f5311 25 ID12RFID rfid(p14);
donatien 0:c292522f5311 26 DigitalOut tag_present(LED1);
donatien 0:c292522f5311 27 DigitalOut tweet_ok(LED4);
donatien 0:c292522f5311 28
donatien 0:c292522f5311 29 int main() {
donatien 0:c292522f5311 30 ethernet.setup();
donatien 0:c292522f5311 31 twitter.basicAuth(TWITTER_USER, TWITTER_PASSWORD);
donatien 0:c292522f5311 32
donatien 0:c292522f5311 33 while(true) {
donatien 0:c292522f5311 34 int id = rfid.read();
donatien 0:c292522f5311 35 tag_present = 1;
donatien 0:c292522f5311 36 for(int i = 0; i < IDS_COUNT; i++) {
donatien 0:c292522f5311 37 if (ids_list[i] == id) {
donatien 0:c292522f5311 38 HTTPMap msg;
donatien 0:c292522f5311 39 msg["status"] = names_list[i];
donatien 0:c292522f5311 40 msg["status"] += " just arrived home!";
donatien 2:2d0011b9bb1e 41 HTTPResult r = twitter.post("http://api.supertweet.net/1/statuses/update.xml", msg, NULL);
donatien 0:c292522f5311 42 tweet_ok = !r;
donatien 0:c292522f5311 43 }
donatien 0:c292522f5311 44 }
donatien 0:c292522f5311 45 tag_present = 0;
donatien 0:c292522f5311 46 }
donatien 0:c292522f5311 47 }