Post.php

pass post.php with ?ID=tag number

$ID=substr($_GET['id'],0,-3); //removes trailing carriage return
$currentBeer;

//opening up database for finding RFID tag and associated beer
$file=fopen("beerdb","r");
while(!feof($file)){
	$currentLine=fgets($file);
	if(strstr($currentLine, $ID)){
		$currentBeer=substr($currentLine,11, strlen($currentLine));
	}
}

//looking up a random quote to post to Twitter
$rand=file("randq");
	srand ((double) microtime() * 1000000);
$randnum = rand(0,count($rand)-1);
$text = $rand[$randnum];

//setting up cURL
$curlPost = ("status=".$text.$currentBeer);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://twitter.com/statuses/update.xml');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");// where username is your twitter name and password is your password
$data = curl_exec($ch);
curl_close($ch);
//cURL done

//echo $curlPost;
//echo "";

beerdb

database of RFID tags with their associated beers. Database is in the format RFID,Beername

1F00D074DB;Heineken Light
1F00D0640C;Orval

randq

database of random beer quotes to reduce collisions in twitter posts. One quote per line

Currently in consumption: 
Enjoying a nice, cold, 
A lovely day for a 
Why waste a perfectly good 
Hooray 

Processing Daemon

Daemon running on laptop to catch RFID events

import processing.serial.*;

String currentTag;
Serial myPort;

void setup() { 
  myPort = new Serial(this, Serial.list()[0],2400);
  myPort.bufferUntil(10);
}  

void draw(){
}
void serialEvent(Serial myPort){
  currentTag = myPort.readStringUntil(10); 
  link("http://omrishiv.com/projects/beer_twitter/post.php?id=" + currentTag);
//println(currentTag);
}

Arduino RFID Sketch

Rewritten Arduino RFID Sketch to catch duplicate tags

int  val = 0; 
char code[10]; 
int bytesread = 0;
char prevcode[10];

void setup() { 
  Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps 
  pinMode(2,OUTPUT);   // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin 
  digitalWrite(2, LOW);                  // Activate the RFID reader
}  
void loop() { 

  if(Serial.available() > 0) {          // if data available from reader 
    if((val = Serial.read()) == 10) {   // check for header 
      bytesread = 0; 
      while(bytesread<10) {              // read 10 digit code 
        if( Serial.available() > 0) { 
          val = Serial.read(); 
          if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading 
            break;                       // stop reading 
          } 
          code[bytesread] = val;         // add the digit           
          bytesread++;                   // ready to read next digit  
        } 
      } 
      if(bytesread == 10) {        // if 10 digit read is complete 
        for(int i = 0; i<10; i++){
          if(prevcode[i]!=code[i]){
//            Serial.print("prevcode different than code");
//            Serial.println("current code: "); 
            Serial.print(code);        // print the TAG code 
            for(int x=0;x<10;x++){
              prevcode[x]=code[x];
            }
            return;
          }
        }

      }
      bytesread = 0; 
      delay(500);                       // wait for a second 
    } 
  } 
}