RFID Card Reader help
hello all,
i'm looking setting rc522 rfid reader/writer , need pulling , storing card id numbers. i'm using mega2560. i'm trying "simple" access granted (green led) access denied (red led).
i'm using rc522 library miguelbalboa , rfid_default_keys example sketch base, works fine , can read 3 of badges.
from i've learned reading have try , pull card id number dump_byte_array function , create string. compare array of cards have. sounds simple cannot find way acquire card id , store it.
i've searched past 3 days , seem find same builds , sketches not 1 i'm looking for. i'm "noob" may have on looked in search. may making way more complicated have thats why i'm asking experts.
anywho. have figured out here how grab data cards,
and here how write serial port.
i don't know how can intercept information , make usable form me.
and here whole sketch. put in steve bill , bob , card id's don't lose them.
i'm looking setting rc522 rfid reader/writer , need pulling , storing card id numbers. i'm using mega2560. i'm trying "simple" access granted (green led) access denied (red led).
i'm using rc522 library miguelbalboa , rfid_default_keys example sketch base, works fine , can read 3 of badges.
from i've learned reading have try , pull card id number dump_byte_array function , create string. compare array of cards have. sounds simple cannot find way acquire card id , store it.
i've searched past 3 days , seem find same builds , sketches not 1 i'm looking for. i'm "noob" may have on looked in search. may making way more complicated have thats why i'm asking experts.
anywho. have figured out here how grab data cards,
code: [select]
}
void dump_byte_array(byte *buffer, byte buffersize) {
(byte = 0; < buffersize; i++) {
serial.print(buffer[i] < 0x10 ? " 0" : " ");
serial.print(buffer[i], hex);
}
}
and here how write serial port.
code: [select]
void loop() {
// new cards
if ( ! mfrc522.picc_isnewcardpresent())
return;
// select 1 of cards
if ( ! mfrc522.picc_readcardserial())
return;
// show details of picc (that is: tag/card)
serial.print("card id:");
dump_byte_array(mfrc522.uid.uidbyte, mfrc522.uid.size);
serial.println();
serial.print("picc type: ");
byte picctype = mfrc522.picc_gettype(mfrc522.uid.sak);
i don't know how can intercept information , make usable form me.
and here whole sketch. put in steve bill , bob , card id's don't lose them.
code: [select]
#include <spi.h>
#include <mfrc522.h>
#define rst_pin 5 // configurable, see typical pin layout above
#define ss_pin 53 // configurable, see typical pin layout above
#define steve c3 b0 8b f4
#define bill a3 3e 75 d5
#define bob d6 b7 e7 3d
mfrc522 mfrc522(ss_pin, rst_pin); // create mfrc522 instance.
// number of known default keys (hard-coded)
// note: synchronize nr_known_keys define defaultkeys[] array
#define nr_known_keys 8
// known keys, see: https://code.google.com/p/mfcuk/wiki/mifareclassicdefaultkeys
byte knownkeys[nr_known_keys][mfrc522::mf_key_size] = {
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // ff ff ff ff ff ff = factory default
{0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5}, // a0 a1 a2 a3 a4 a5
{0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5}, // b0 b1 b2 b3 b4 b5
{0x4d, 0x3a, 0x99, 0xc3, 0x51, 0xdd}, // 4d 3a 99 c3 51 dd
{0x1a, 0x98, 0x2c, 0x7e, 0x45, 0x9a}, // 1a 98 2c 7e 45 9a
{0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7}, // d3 f7 d3 f7 d3 f7
{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, // aa bb cc dd ee ff
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 00 00 00 00 00 00
};
/*
* initialize.
*/
void setup() {
pinmode (led1, output);
serial.begin(9600); // initialize serial communications pc
spi.begin(); // init spi bus
mfrc522.pcd_init(); // init mfrc522 card
serial.println("try used default keys print block 0 of mifare picc.");
}
/*
* helper routine dump byte array hex values serial.
*/
void dump_byte_array(byte *buffer, byte buffersize) {
(byte = 0; < buffersize; i++) {
serial.print(buffer[i] < 0x10 ? " 0" : " ");
serial.print(buffer[i], hex);
}
}
/*
* try using picc (the tag/card) given key access block 0.
* on success, show key details, , dump block data on serial.
*
* @return true when given key worked, false otherwise.
*/
boolean try_key(mfrc522::mifare_key *key)
{
boolean result = false;
byte buffer[18];
byte block = 0;
byte status;
// serial.println("authenticating using key a...");
status = mfrc522.pcd_authenticate(mfrc522::picc_cmd_mf_auth_key_a, block, key, &(mfrc522.uid));
if (status != mfrc522::status_ok) {
// serial.print("pcd_authenticate() failed: ");
// serial.println(mfrc522.getstatuscodename(status));
return false;
}
// read block
byte bytecount = sizeof(buffer);
status = mfrc522.mifare_read(block, buffer, &bytecount);
if (status != mfrc522::status_ok) {
// serial.print("mifare_read() failed: ");
// serial.println(mfrc522.getstatuscodename(status));
}
else {
// successful read
result = true;
serial.print("success key:");
dump_byte_array((*key).keybyte, mfrc522::mf_key_size);
serial.println();
// dump block data
serial.print("block "); serial.print(block); serial.print(":");
dump_byte_array(buffer, 16);
serial.println();
}
serial.println();
mfrc522.picc_halta(); // halt picc
mfrc522.pcd_stopcrypto1(); // stop encryption on pcd
return result;
}
/*
* main loop.
*/
void loop() {
// new cards
if ( ! mfrc522.picc_isnewcardpresent())
return;
// select 1 of cards
if ( ! mfrc522.picc_readcardserial())
return;
digitalwrite(led1, high);
// show details of picc (that is: tag/card)
serial.print("card id:");
dump_byte_array(mfrc522.uid.uidbyte, mfrc522.uid.size);
serial.println();
serial.print("picc type: ");
byte picctype = mfrc522.picc_gettype(mfrc522.uid.sak);
// try known default keys
mfrc522::mifare_key key;
(byte k = 0; k < nr_known_keys; k++) {
// copy known key mifare_key structure
(byte = 0; < mfrc522::mf_key_size; i++) {
key.keybyte[i] = knownkeys[k][i];
}
// try key
if (try_key(&key)) {
// found , reported on key , block,
// no need try other keys picc
break;
}
}
}
quote
from i've learned reading have try , pull card id number dump_byte_array function , create string.no, have card data array of bytes. can compare array array of bytes. don't piss away resources on strings.
quote
i don't know how can intercept information , make usable form me.you don't need "intercept" anything. data right there, in mfrc522.uid.uidbyte. number of elements in uidbyte array in mfrc522.uid.size.
Arduino Forum > Using Arduino > Programming Questions > RFID Card Reader help
arduino
Comments
Post a Comment