Advertisement
Guest User

Untitled

a guest
May 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. import RPi.GPIO as gpio
  2. import os
  3. import json
  4. import MFRC522
  5. import time
  6.  
  7.  
  8. gpio.setmode(gpio.BCM)
  9. gpio.setup(   a   ,    gpio.OUT)                                            #relé, definir a
  10. gpio.setup(   b   ,    gpio.IN)                                             #rfid, definir b
  11.  
  12. master_key = '123'
  13. new_key = False
  14.  
  15. LeitorRFID = MFRC522.MFRC522()
  16.  
  17. while True:
  18.    
  19.     status, tag_type = LeitorRFID.MFRC522_Request(LeitorRFID.PICC_REQIDL)
  20.     if status == LeitorRFID.MI_OK:
  21.         with open('keys.json') as json_file:
  22.             sheet=json.load(json_file)
  23.         status, key = LeitorRFID.MFRC522_Anticoll()
  24.         if status == LeitorRFID.MI_OK:
  25.             key = ':'.join(['%X' % x for x in key])
  26.             if new_key:                                                     # definir como guardar as keys
  27.                
  28.                 #adicionar key em sheet
  29.                 #with open(‘keys.json’, ‘w’) as outfile:
  30.                     #json.dump(sheet,outfile)
  31.            
  32.                 new_key = False
  33.                
  34.             else:
  35.                 if key == master_key:
  36.                     new_key = True
  37.                
  38.                 elif key in sheet:
  39.                     gpio.output( a ,  gpio.HIGH)
  40.                     os.system('mpg321 /home/pi/music/' + authorized + '.mp3')
  41.                     time.sleep(0.2)
  42.                     gpio.output( a ,  gpio.LOW)
  43.                    
  44.                        
  45.                 else:
  46.                     os.system('mpg321 /home/pi/music/' + not_authorized + '.mp3')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement