-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread.py
executable file
·76 lines (64 loc) · 2.32 KB
/
read.py
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
#!/usr/bin/env python
import RPi.GPIO as GPIO
import MFRC522
import signal
import time
import subprocess
read_loop = True
online = False
rfid_status = 0
rfid_read = 0
card_uid = None
client_error = 0
# Capture SIGINT for cleanup when the script is aborted
def end_read(signal, frame):
global read_loop
global online
print "Exiting read loop."
read_loop = False
online = False
GPIO.cleanup()
# Hook the SIGINT
signal.signal(signal.SIGINT, end_read)
# Create Reader
Reader = MFRC522.MFRC522()
# This loop is checking for chips
while read_loop:
(status, tag_type) = Reader.MFRC522_Request(Reader.PICC_REQIDL)
if status == Reader.MI_OK:
rfid_read = 0
online = True
while online:
(rfid_status, uid) = Reader.MFRC522_Anticoll()
if rfid_status == Reader.MI_OK:
if rfid_read == 0:
rfid_read = 1
client_error = 1
card_uid = format(uid[0], "x") + format(uid[1], "x") + format(uid[2], "x") + format(uid[3], "x")
print "Card detected."
print "Card UID: " + card_uid
print "Calling t00niebox client script"
print "-----"
try:
response = subprocess.check_output(["/home/t00niebox/t00niebox-client/dispatch", card_uid])
client_error = 0
except subprocess.CalledProcessError:
client_error = 1
print "-----"
print "t00niebox script returned an error."
print "-----"
else:
online = False
print "Card removed."
if client_error == 0:
print "Calling t00niebox client script"
print "-----"
try:
response = subprocess.check_output(["/home/t00niebox/t00niebox-client/dispatch", "00000000"])
except subprocess.CalledProcessError:
print "-----"
print "t00niebox client script returned an error."
print "-----"
else:
print "Skipping pause command due to t00niebox client script error."
time.sleep(1 / 4)