-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (36 loc) · 1.22 KB
/
main.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
import binascii
import structlog
import logging
import sys
import requests
import time
import argparse
parser=argparse.ArgumentParser()
parser.add_argument('endpoint',default="https://coworking-flex.alsacedigitale.org/api")
args=parser.parse_args()
logging.basicConfig(
format="%(message)s",
stream=sys.stdout,
level=logging.DEBUG,
)
logger = structlog.get_logger()
mirror = open("/dev/mirror", "rb")
ENDPOINT=args.endpoint+"/rfid/{id}/detect"
while True:
data = mirror.read(16)
if data != b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00':
rfid_id = binascii.hexlify(data)[4:]
if data[0:2] == b'\x02\x01': # Puce posée
logger.debug("Detected chip", rfid_id=rfid_id)
json_data={
"rfid_id": rfid_id
}
for i in range(5):
logger.debug('post')
resp=requests.post(ENDPOINT.format(id=rfid_id), json=json_data)
logger.debug('request reply',status_code=resp.status_code)
if resp.status_code<500:
break
time.sleep(5)
elif data[0:2] == b'\x02\x02': #Puce retirée
logger.debug("Chip left", rfid_id=rfid_id)