Created
March 27, 2010 15:04
-
-
Save ffaerber/346139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RFID reader for Arduino | |
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan> | |
// Modified for Arudino by djmatic | |
#include <Ethernet.h> | |
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; | |
byte ip[] = { 192, 168, 1, 200 }; | |
byte gateway[] = { 192, 168, 1, 1 }; | |
byte subnet[] = { 255, 255, 255, 0 }; | |
byte server[] = { 128, 121, 146, 100 }; | |
Client client(server, 80); | |
#define TWITTERURL "/statuses/update.xml" // URL zum Update Script | |
#define TWITTERUSERNAMEPW "ZmZhZXJi-----G9semRvc2U=" // Base64 enkodet USERNAME:PASSWORT | |
int val = 0; | |
char code[10]; | |
int bytesread = 0; | |
void setup() { | |
Ethernet.begin(mac, ip, gateway, subnet); // Ethernet initalisiere | |
Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps | |
delay(1000); // Kurz warten, um serielle Verbindung zu starten | |
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() { | |
fetchTwitterUpdate(); | |
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 | |
Serial.print("TAG code is: "); // possibly a good TAG | |
sendTwitterUpdate(code); // Nachricht versenden | |
Serial.println(code); // print the TAG code | |
} | |
bytesread = 0; | |
delay(500); // wait for a second | |
} | |
} | |
} | |
void sendTwitterUpdate(char* tweet) // Nachricht an Twitter übermitteln | |
{ | |
Serial.println("connecting..."); | |
if (client.connect()) { | |
Serial.println("connected"); | |
client.print("POST "); | |
client.print(TWITTERURL); | |
client.println(" HTTP/1.1"); | |
client.println("Host: twitter.com"); | |
client.print("Authorization: Basic "); | |
client.println(TWITTERUSERNAMEPW); | |
client.print("Content-Length: "); | |
client.println(9+strlen(tweet)); | |
client.println(""); | |
client.println("status="); | |
client.println(tweet); | |
Serial.println("twitter message send"); | |
} else { | |
Serial.println("connection failed"); | |
} | |
} | |
void fetchTwitterUpdate() // Rückmeldung von Twitter auslesen | |
{ | |
if (client.available()) { | |
char c = client.read(); | |
Serial.print(c); | |
} | |
if (!client.connected()) { | |
Serial.println(); | |
Serial.println("disconnecting."); | |
client.stop(); | |
} | |
} | |
// extra stuff | |
// digitalWrite(2, HIGH); // deactivate RFID reader |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment