Created
June 23, 2012 00:00
-
-
Save possan/2975870 to your computer and use it in GitHub Desktop.
Arduino RFID Ethernet junk
This file contains hidden or 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
#include <SPI.h> | |
#include <Ethernet.h> | |
#include <SoftwareSerial.h> | |
SoftwareSerial mySerial(8, 9); | |
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x88 }; | |
IPAddress server(91,123,198,230); // Google | |
int port = 80; | |
EthernetClient client; | |
int sent = 0; | |
void setup() { | |
Serial.begin(9600); | |
mySerial.begin(9600); | |
Serial.println("begin..."); | |
// Ethernet.begin(mac, ip); | |
if (Ethernet.begin(mac) == 0) { | |
Serial.println("Failed to configure Ethernet using DHCP"); | |
for(;;); | |
} | |
Serial.print("My IP address: "); | |
for (byte thisByte = 0; thisByte < 4; thisByte++) { | |
Serial.print(Ethernet.localIP()[thisByte], DEC); | |
Serial.print("."); | |
} | |
Serial.println(); | |
delay(1000); | |
Serial.println("connecting..."); | |
} | |
char buf[100] = { 0, }; | |
int bwp = 0; | |
void tellServer() { | |
Serial.println("send request..."); | |
sent = 1; | |
client.stop(); | |
if (client.connect(server, port)) { | |
Serial.println("connected, send request..."); | |
client.print("GET /rfid.php?rfid="); | |
client.print(buf); | |
client.println(" HTTP/1.0"); | |
client.println("Host: www.on-axis.com"); | |
client.println(); | |
} | |
else { | |
// kf you didn't get a connection to the server: | |
Serial.println("connection failed"); | |
} | |
Serial.println("efter."); | |
} | |
void loop() { | |
if (mySerial.available()) { | |
char c = mySerial.read(); | |
if( c == '\n' ) { | |
Serial.print("GOT KEY: ["); | |
Serial.print(buf); | |
Serial.println("]\n"); | |
tellServer(); | |
memset(buf, 0, 100); | |
bwp = 0; | |
} else { | |
if((c >='0' && c <= '9') || (c >= 'A' && c <= 'F')) { | |
if (bwp < 50) buf[bwp] = c; | |
bwp ++; | |
} | |
} | |
} | |
if(sent) { | |
if (client.available()) { | |
char c = client.read(); | |
Serial.print(c); | |
} | |
if (!client.connected()) { | |
client.stop(); | |
} | |
sent = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment