#include <Ethernet.h>
#include <SPI.h>
// Set up the serial connection to the RFID reader module. In order to
// keep the Arduino TX and RX pins free for communication with a host,
// the sketch uses the SoftwareSerial library to implement serial
// communications on other pins.
#include <SoftwareSerial.h>
// The RFID module's TX pin needs to be connected to the Arduino. Module
// RX doesn't need to be connected to anything since we won't send
// commands to it, but SoftwareSerial requires us to define a pin for
// TX anyway so you can either connect module RX to Arduino TX or just
// leave them disconnected.
// If you have built the circuit exactly as described in Practical
// Arduino, use pins D2 / D3:
#define rxPin 6
#define txPin 7
// Create a software serial object for the connection to the RFID module
SoftwareSerial rfid = SoftwareSerial( rxPin, txPin );
// Set up outputs for the strike plate and status LEDs.
// If you have built the circuit exactly as described in Practical
// Arduino, use pins D12 and D13:
#define strikePlate 12
#define ledPin 13
// The tag database consists of two parts. The first part is an array of
// tag values with each tag taking up 5 bytes. The second is a list of
// names with one name for each tag (ie: group of 5 bytes).
char* allowedTags[] = {
"1C00EFE643", // Tag 1
"04146E8BDD", // Tag 2
"0413BBBF23", // Tag 3
"1B001421DA", // Tag 4
"1B001461DA", // Tag 5
"1B001321DA", // Tag 6
"1B001221DA", // Tag 7
"1B002421Db", // Tag 8
"1B011421D1", // Tag 9
"1B101421D2", // Tag 11
"1B101421D2", // Tag 12
"1B101421D2", // Tag 13
"1B101421D2", // Tag 14
};
// List of names to associate with the matching tag IDs
char* tagName[] = {
"Jonathan Oxer", // Tag 1
"Hugh Blemings", // Tag 2
"Dexter D Dog", // Tag 3
"Set Paper Low", // Tag 4
"Jonathan Oxer", // Tag 5
"Hugh Blemings", // Tag 6
"Dexter D Dog", // Tag 7
"Paper Low8", // Tag 8
"Jonathan Oxer", // Tag 9
"Hugh Blemings", // Tag 10
"Dexter D Dog", // Tag 11
"Paper Low12", // Tag 12
"Paper Low13", // Tag 13
"Paper Low14", // Tag 14
};
int cld1Pin = 4; // Card status pin
int rdtPin = 2; // Data pin
int reading = 0; // Reading status
volatile int buffer[400]; // Buffer for data
volatile int i = 0; // Buffer counter
volatile int bit = 0; // global bit
char cardData[40]; // holds card info
int charCount = 0; // counter for info
int DEBUG = 0;
unsigned int cnt=0;
char Card_Str[] = "11111111111111111111";
int scroll_pos=0;
int scroll_state=0;
// Check the number of tags defined
int numberOfTags = sizeof(allowedTags)/sizeof(allowedTags[0]);
char* states[]={
"checked out",
"Checked In ",
"Supplies Low ",
"Supplies High "
};
int incomingByte = 0; // To store incoming serial data
///////////////////////////////////////////////////////////////////////
//CONFIGURE ethernet
////////////////////////////////////////////////////////////////////////
byte ip[] = { 192, 168, 0, 199 }; //ip address to assign the arduino
byte server[] = {174,123,231,247}; //ip Address of the server you will connect to
//The location to go to on the server
//make sure to keep HTTP/1.0 at the end, this is telling it what type of file it is
//String location = "/~bildr/examples/ethernet/ HTTP/1.0";
//Rarly need to change this
byte subnet[] = { 255, 255, 255, 0 };
// if need to change the MAC address (Very Rare)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
Client client(server, 80); // port 80 is typical www page*/
////////////////////////////////////////////////////////////////////////
char inString[32]; // string for incoming serial data
int stringPos = 0; // string index counter
boolean startRead = false; // is reading?
/**
* Setup
*/
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
pinMode(strikePlate, OUTPUT);
digitalWrite(strikePlate, LOW);
Serial.begin(9600); // Serial port for connection to host
rfid.begin(9600); // Serial port for connection to RFID module
// The interrupts are key to reliable
// reading of the clock and data feed
attachInterrupt(0, changeBit, CHANGE);
attachInterrupt(1, writeBit, FALLING);
Serial.println("RFID reader starting up");
}
/**
* Loop
*/
/**
* Loop
*/
void loop() {
byte i = 0;
byte val = 0;
byte checksum = 0;
byte bytesRead = 0;
byte tempByte = 0;
byte tagBytes[6]; // "Unique" tags are only 5 bytes but we need an extra byte for the checksum
char tagValue[10];
int state=0;
get_supplies2(1);
// Read from the RFID module. Because this connection uses SoftwareSerial
// there is no equivalent to the Serial.available() function, so at this
// point the program blocks while waiting for a value from the module
if((val = rfid.read()) == 2) { // Check for header
bytesRead = 0;
while (bytesRead < 12) { // Read 10 digit code + 2 digit checksum
val = rfid.read();
// Append the first 10 bytes (0 to 9) to the raw tag value
if (bytesRead < 10)
{
tagValue[bytesRead] = val;
}
// Check if this is a header or stop byte before the 10 digit reading is complete
if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) {
break; // Stop reading
}
// Ascii/Hex conversion:
if ((val >= '0') && (val <= '9')) {
val = val - '0';
}
else if ((val >= 'A') && (val <= 'F')) {
val = 10 + val - 'A';
}
// Every two hex-digits, add a byte to the code:
if (bytesRead & 1 == 1) {
// Make space for this hex-digit by shifting the previous digit 4 bits to the left
tagBytes[bytesRead >> 1] = (val | (tempByte << 4));
if (bytesRead >> 1 != 5) { // If we're at the checksum byte,
checksum ^= tagBytes[bytesRead >> 1]; // Calculate the checksum... (XOR)
};
} else {
tempByte = val; // Store the first hex digit first
};
bytesRead++; // Ready to read next digit
}
// Send the result to the host connected via USB
if (bytesRead == 12) { // 12 digit read is complete
tagValue[10] = '\0'; // Null-terminate the string
Serial.print("Tag read: ");
for (i=0; i<5; i++) {
// Add a leading 0 to pad out values below 16
if (tagBytes[i] < 16) {
Serial.print("0");
}
Serial.print(tagBytes[i], HEX);
}
Serial.println();
Serial.print("Checksum: ");
Serial.print(tagBytes[5], HEX);
Serial.println(tagBytes[5] == checksum ? " -- passed." : " -- error.");
// Show the raw tag value
//Serial.print("VALUE: ");
//Serial.println(tagValue);
// Search the tag database for this particular tag
int tagId = findTag( tagValue );
// if tag is found
if( tagId > 0 )
Serial.print("Authorized tag ID ");
Serial.println(tagId);
if(tagId<30){//equipment
Serial.print("State:");
Serial.println(state);
Serial.println(states[state]);
switch (state) {
case 0: //checked out
Serial.print(tagName[tagId - 1]);
// Serial.println("Checked out, Scan ID to Check in");
if(Scan_ID()==1){//id scan ok
if(senddata(tagId,2)==1){
Serial.print("Updated Record");
}
else{
Serial.print("Could not access server");
}
}
else{
//Serial.println("ID Not valid or could not be read");
}
break;
case 1://checked in check out
Serial.print(tagName[tagId - 1]);
Serial.println(" Checked in, Scan ID to Check Out");
if(Scan_ID()==1){//id scan ok
if(senddata(tagId,1)==1){
// Serial.print("Updated Record");
}
else{
Serial.print("Could not access server");
}
}
else{
Serial.println("ID Not valid or could not be read");
}
break;
}//switch
}//equip if
else{ // supplies
}
{
}// tag if
Serial.println(); // Blank separator line in output
}
bytesRead = 0;
}
}