I have a lot of RFID cards that I'm using, but around 1/4 of them does not work with the code I have.
First off, I have an USB RFID card reader that I use to read and program the RFID cards, plus store their hexadecimal values to our SQL database.
After that I have an Arduino machine with a RFID reader(not the same reader as the USB one) that reads the RFID cards hexadecimal value and then sends this with a HTTP GET to our server were it'll validate in our SQL database. Based on this it returns success or false.
A majority of the cards works great but some does not.
Here is an example of a card that works, it has the RFID '08BEF8CA' which also is the value we have stored in the database, the Arduino device however reads the hexadecimal as 'CAF8BE08'. But this is the same hexadecimal just with a different endian, we fix this server-side(after the HTTP GET) and it works as intended.
Another card has the RFID '08BDDCAA', but the Arduino device returns 'AA00DCBD' for this card. Like the other card, it has a different endian. But for some reason the 08 has disappeared and is now 00, thus breaking the HTTP GET since we're not expecting that value.
Here is some code for the Arduino device
#include <Ethernet.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>
#define standby_pin A0//Blue LED
#define grant_pin A1//Green LED
#define grantbuzzer_pin A4//Buzzer
#define deny_pin A3//Red LED
#define denybuzzer_pin A4//Buzzer
// the timer object
SimpleTimer HBtimer;
char tag[10];
int tagindex=0;
SoftwareSerial mySerial(2, 3); //pin3 Rx, pin2 Tx
byte readCard[]={0xAA,0xBB,0x02,0x20,0x22};
int cardPresent=0;
int cardBytesRead;
int readComplete;
int CMD[64];
int comlen =0;
int out_flag =0;
boolean isReplyRead=0;
String strAuthResp;
String strTagID;
int aread=0,readCardBytes=0,readIndex=0,index=0;
char value[250];
int HBTimeout=60000;
int isConnected = 0;
void setup()
{
pinMode(standby_pin,OUTPUT);
pinMode(grant_pin,OUTPUT);
pinMode(deny_pin,OUTPUT);
pinMode(grantbuzzer_pin,OUTPUT);
pinMode(denybuzzer_pin,OUTPUT);
pinMode(5,INPUT);
digitalWrite(standby_pin,LOW);
digitalWrite(grant_pin,HIGH);
digitalWrite(deny_pin,HIGH);
Serial.begin(19200);
mySerial.begin(19200);
cardBytesRead=0;
readComplete=0;
delay(50);
mySerial.listen();
delay(10);
}
void loop()
{
HBtimer.run();
readComplete=0;
cardPresent=digitalRead(5);
cardPresent=!cardPresent;
if((cardPresent)&&(!readComplete)){
readCardF();
delay(50);
}//End IF
}//End Loop
void readCardF(){
mySerial.write(readCard, sizeof(readCard));
while(mySerial.available()&&readComplete<1){
byte C = mySerial.read();
if (C<16) Serial.print("0");
Serial.print(C,HEX);
cardBytesRead++;
if ((cardBytesRead>4)&&(cardBytesRead<9)){
byte hinibble = (C >> 4) & 0x0f;
byte lonibble = C & 0x0f;
tag[tagindex++] = bintohexascii(hinibble);
tag[tagindex++] = bintohexascii(lonibble);
} //End If
if (cardBytesRead==9) {
tagindex=0;
cardBytesRead=0;
readComplete=1;
Serial.println("");
Serial.println("RFID tag value= ");
Serial.println(tag);
Serial.println("");
strTagID=tag;
isReplyRead=0;
if(strTagID.length()==8){
//Success
//Call our HTTP GET function
//For testing purposes we call the resetFunc here so we can re-scan to keep testing
delay(100);
resetFunc();
}
else
{
Serial.println("Invalid Length of RFID Card");
delay(100);
resetFunc();
}
return;
}//End If carybytesread==9
}//End While
} //End Function
char bintohexascii(byte x)
{
char hex[16] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
return hex[x & 0x0f];
}
void resetFunc() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
I have an older Arduino device that can read these cards fine, and it uses pretty much the exact same functions to create the RFID, only real difference is that it is a different device and has a different frequence(or what the baud thing is?)
Thanks in before hand.