forked from miketissenbaum/connectedspaces
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrfidTest.py
44 lines (38 loc) · 1.2 KB
/
rfidTest.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
"""
Continuously read.
"""
import serial
import re
import webbrowser
import requests
ser = serial.Serial('/dev/tty.usbserial-AI02KGDC', 9600) # here you have to write your port. If you dont know how to find it just write ls -l /dev/tty.* in your terminal (i'm using mac)
def rfidResponse(responseID):
# rID = responseID.strip();
# print repr(responseID)
print responseID
# if responseID == "750047FB76BF":
# print "This one"
# payload = {"name":'Batman'}
# print "Sending"
# r = requests.post("http://127.0.0.1:5000/index", params=payload)
# print(r.url)
# else:
# print "other one"
payload = {"cardID":responseID}
print payload
# r = requests.post("http://127.0.0.1:5000/index", data=payload)
# webbrowser.open_url("http://52.43.36.201/member/" + payload)
print payload
webbrowser.open_new("http://localhost:3000/member/" + payload["cardID"])
while True:
try:
response = ser.readline()
#stringResponse = str(response) # you don't need this line
responseParse = re.search('[A-Z0-9]{12}(?=\s+)', response) #your NFC ID should be of fixed length
if responseParse:
rfidResponse(responseParse.group(0))
else:
print 'No NFC ID received'
except KeyboardInterrupt:
break
ser.close()