Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as gpio
- import os
- import json
- import MFRC522
- import time
- gpio.setmode(gpio.BCM)
- gpio.setup( a , gpio.OUT) #relé, definir a
- gpio.setup( b , gpio.IN) #rfid, definir b
- master_key = '123'
- new_key = False
- LeitorRFID = MFRC522.MFRC522()
- while True:
- status, tag_type = LeitorRFID.MFRC522_Request(LeitorRFID.PICC_REQIDL)
- if status == LeitorRFID.MI_OK:
- with open('keys.json') as json_file:
- sheet=json.load(json_file)
- status, key = LeitorRFID.MFRC522_Anticoll()
- if status == LeitorRFID.MI_OK:
- key = ':'.join(['%X' % x for x in key])
- if new_key: # definir como guardar as keys
- #adicionar key em sheet
- #with open(‘keys.json’, ‘w’) as outfile:
- #json.dump(sheet,outfile)
- new_key = False
- else:
- if key == master_key:
- new_key = True
- elif key in sheet:
- gpio.output( a , gpio.HIGH)
- os.system('mpg321 /home/pi/music/' + authorized + '.mp3')
- time.sleep(0.2)
- gpio.output( a , gpio.LOW)
- else:
- os.system('mpg321 /home/pi/music/' + not_authorized + '.mp3')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement