/
cardReaderITP.ino
95 lines (71 loc) · 1.84 KB
/
cardReaderITP.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
This sketch demonstrate how to run read an RFID
card reader and verify it against a database
using a python script using an Arduino Yún.
created 01 Oct 2013
by Surya Mattu
This example code is in the public domain.
This code uses the CardReader Library Luis Daniels
and I wrote for HID Card readers available
on Github here:
https://github.com/samatt/CardReader
*/
#include <Process.h>
#include <CardReader.h>
CardReader reader(2, 3);
long cardNumber = 0;
void setup() {
// Initialize Bridge
Bridge.begin();
attachInterrupt(1, readBit, RISING);
// Initialize Serial
Serial.begin(9600);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
// Wait until a Serial Monitor is connected.
while (!Serial);
Serial.println("ITP Card reader. Ready to read card.");
}
void loop() {
if (reader.cardRead()) {
Serial.print("Card ID: ");
cardNumber = reader.getIdNumber();
Serial.println(cardNumber);
if(runScript(cardNumber)){
Serial.println("Approved!");
digitalWrite(6,HIGH);
delay(1000);
digitalWrite(6,LOW);
}
else{
Serial.println("Denied ");
digitalWrite(7,HIGH);
delay(1000);
digitalWrite(7,LOW);
}
}
}
void readBit() {
reader.readBit();
}
bool runScript(long cardNumber) {
bool isVerified = false;
// Process that launches the python script
Process p;
p.begin("/usr/bin/python");
p.addParameter("/root/checkID.py");
p.addParameter(String(cardNumber));
p.run();
// Read data back from the script.
while (p.available()>0) {
char c = p.read();
//If the card ID is on the database the python script will return a 1
//value will come in as an ascii char
if( c == '1'){
isVerified = true;
}
}
// Ensure the last bit of data is sent.
Serial.flush();
return isVerified;
}