Dependencies:   EthernetNetIf mbed

main.cpp

Committer:
donatien
Date:
2010-06-17
Revision:
0:c292522f5311
Child:
2:2d0011b9bb1e

File content as of revision 0:c292522f5311:

// RFID Tweeter

#include "mbed.h"
#include "ID12RFID.h"
#include "EthernetNetIf.h"
#include "HTTPClient.h"

#define TWITTER_USER "donatiengarnier"
#define TWITTER_PASSWORD "myverysecurepassword"

#define IDS_COUNT 3
const int ids_list[IDS_COUNT] = {89481809, 89481810, 89481811};
const char* names_list[IDS_COUNT] = {"Donatien", "Simon", "Dan"};

EthernetNetIf ethernet;
HTTPClient twitter;

ID12RFID rfid(p14);
DigitalOut tag_present(LED1);
DigitalOut tweet_ok(LED4);

int main() {
  ethernet.setup();
  twitter.basicAuth(TWITTER_USER, TWITTER_PASSWORD);

  while(true) {
    int id = rfid.read();
    tag_present = 1;
    for(int i = 0; i < IDS_COUNT; i++) {
      if (ids_list[i] == id) {
        HTTPMap msg;
        msg["status"] = names_list[i];
        msg["status"] += " just arrived home!";
        HTTPResult r = twitter.post("http://twitter.com/statuses/update.xml", msg, NULL);
        tweet_ok = !r;
      }
    }
    tag_present = 0;
  }
}