raspberry-pi/registrer.py

21 lines
645 B
Python
Raw Normal View History

2022-01-12 21:21:24 +00:00
from mfrc522 import SimpleMFRC522#rfid reader library
from requests import post#make post requests
from RPi import GPIO
import json
with open('./settings.json') as json_settings:#open json file with settings
settings = json.loads(json_settings.read())#read the json to a python object
reader = SimpleMFRC522()
try:
while True:
id, text = reader.read()#read rfid
print(id)
print(text)
post(settings['url'], {'rfid': str(id) + str(text)})#send POST with rfid
#add code to keep a local backup database
except KeyboardInterrupt:#ctrl + c
GPIO.cleanup()#clean up the gpio
raise#exit program