def do_read(): if uname()[0] == 'WiPy': rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") elif uname()[0] == 'esp32': rdr = mfrc522.MFRC522(sck=18, mosi=23, miso=19, rst=22, cs=21) else: raise RuntimeError("Unsupported platform") print("") print("Place card before reader to read from address 0x08") print("") try: while True: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, uid) = rdr.SelectTagSN() if stat == rdr.OK: print("Card detected %s" % uidToString(uid)) else: print("Authentication error") except KeyboardInterrupt: print("Bye")
def do_read(): if uname()[0] == 'WiPy': rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") elif uname()[0] == 'esp8266': rdr = mfrc522.MFRC522(0, 2, 4, 5, 14) elif uname()[0] == 'pyboard': rdr = mfrc522.MFRC522("PA5", "PA7", "PA6", "PA3", "PA4")
def do_read(): if uname()[0] == 'WiPy': rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") elif uname()[0] == 'esp8266': rdr = mfrc522.MFRC522(16, 13, 12, 0, 2) else: raise RuntimeError("Unsupported platform") print("") print("Place card before reader to read from address 0x08") print("") try: while True: (stat, tag_type) = rdr.request(rdr.REQIDL) print("Reading....") print("Reading22....") if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: print("New card detected") print(" - tag type: 0x%02x" % tag_type) print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) print("") content = "" for item in raw_uid: content += hex(item) print(content) if content == "17715019132184": print("Acceass OOO") else: print("Acceass XXXXX") time.sleep_ms(500) if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: print("Address 8 data: %s" % rdr.read(8)) rdr.stop_crypto1() else: print("Authentication error") else: print("Failed to select tag") except KeyboardInterrupt: print("Bye")
def do_read(addr): if uname()[0] == 'WiPy': rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") elif uname()[0] == 'esp8266': rdr = mfrc522.MFRC522(0, 2, 4, 5, 14) elif uname()[0] == 'esp32': rdr = mfrc522.MFRC522(18, 23, 19, 22, 2) else: raise RuntimeError("Unsupported platform") print("") print("Place card before reader to read from address 0x08") print("") try: flag = 1 while flag: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: print("New card detected") print(" - tag type: 0x%02x" % tag_type) print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) print("") if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, addr, key, raw_uid) == rdr.OK: info = rdr.read(addr) info1 = "" for x in info: info1 = info1 + chr(x) info1 = info1.split() print("Address 8 data: %s" % info1[0]) rdr.stop_crypto1() flag = 0 return info1[0] else: print("Authentication error") else: print("Failed to select tag") except KeyboardInterrupt: print("Bye")
def do_write(esp=None): if uname()[0] == 'WiPy': rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") elif uname()[0] == 'esp8266': if esp == 1: rdr = mfrc522.MFRC522(rst=2, cs=16, spiblk=1) else: rdr = mfrc522.MFRC522(rst=2, cs=16, sck=14, mosi=13, miso=12) else: raise RuntimeError("Unsupported platform") print("") print("Place card before reader to write address 0x08") print("") try: while True: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: print("New card detected") print(" - tag type: 0x%02x" % tag_type) print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) print("") if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: stat = rdr.write( 8, b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" ) rdr.stop_crypto1() if stat == rdr.OK: print("Data written to card") else: print("Failed to write data to card") else: print("Authentication error") else: print("Failed to select tag") except KeyboardInterrupt: print("Bye")
def do_read(): if uname()[0] == 'WiPy': rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") elif uname()[0] == 'esp8266': rdr = mfrc522.MFRC522(14, 13, 12, 2, 15) else: raise RuntimeError("Unsupported platform") print("") print("Place card before reader to read from address 0x08") print("") try: while True: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: print("New card detected") print(" - tag type: 0x%02x" % tag_type) print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) print(str(raw_uid)) print("") if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, 1, key, raw_uid) == rdr.OK: for x in range(16): z = rdr.read(x) print("Address 8 data: %s" % z) print(z) print("si no") #texto="" #for i in range(16): # texto+=(chr(z[i])) #print(texto) rdr.stop_crypto1() else: print("Authentication error") else: print("Failed to select tag") except KeyboardInterrupt: print("Bye")
def do_read(): if uname()[0] == 'WiPy': rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") elif uname()[0] == 'esp8266': rdr = mfrc522.MFRC522(0, 2, 4, 5, 14) elif uname()[0] == 'esp32': rdr = mfrc522.MFRC522(18, 23, 19, 22, 21) else: raise RuntimeError("Unsupported platform") print("") print("Place card before reader to read from address 0x08") print("") flag = 0 payload = "Not Set" try: while flag == 0: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: print("New card detected") print(" - tag type: 0x%02x" % tag_type) print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) print("") if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: payload = rdr.read(8) print("Address 8 data: %s" % payload) rdr.stop_crypto1() return payload else: print("Authentication error") else: print("Failed to select tag") flag = 1 except KeyboardInterrupt: print("Bye")
def do_read(config): if uname()[0] == 'WiPy': rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") elif uname()[0] == 'esp8266': rdr = mfrc522.MFRC522(0, 2, 4, 5, 14) else: raise RuntimeError("Unsupported platform") try: while True: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: uid = "%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3]) try: resturl = "http://" + config.get("broker") + ":" + str( config.get("noapport")) + config.get( "restcard") + "/" + uid req = requests.get(resturl) if req.json()["success"]: print("rest succes") else: print("rest error") except OSError: print("rest exception error") pass if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: print("Address 8 data: %s" % rdr.read(8)) rdr.stop_crypto1() else: print("Authentication error") else: print("Failed to select tag") except KeyboardInterrupt: print("Bye")
def loop(): global mfrc while (True): dis_CommandLine() inCmd = input() print(inCmd) if (inCmd == "scan"): print("Scanning...") mfrc = mfrc522.MFRC522() isScan = True while isScan: #SCAN FOR CARDS (status, TagType) = mfrc.MFRC522_Request(mfrc.PICC_REQIDL) #If a card is found if status == mfrc.MI_OK: print("Card detected") #Get the uid of the card (status, uid) = mfrc.MFRC522_Anticoll() #If we have the UID, continue if status == mfrc.MI_OK: print("Card UID: " + str(map(hex, uid))) #Select the scanned tag if mfrc.MFRC522_SelectTag(uid) == 0: print("MFRC522_SelectTag Failed!") if cmdloop(uid) < 1: isScan = False elif inCmd == "quit": destroy() exit() else: print("\tUnknown command\n" + "\tscan:scan card and dump\n" + "\tquit:exit program\n")
def do_write(): rdr = mfrc522.MFRC522() try: while True: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: print("New card detected") print(" - tag type: 0x%02x" % tag_type) print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) print("") if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, 1, key, raw_uid) == rdr.OK: #往指定的块中 写数据,数据长度最大为16个字节 #当前 是往 0x01即扇区0块1写数据 stat = rdr.write(1, b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\xff") rdr.stop_crypto1() if stat == rdr.OK: print("Data written to card") rdr.deinit() break else: print("Failed to write data to card") else: print("Authentication error") else: print("Failed to select tag") #set period of writing time.sleep(1) except KeyboardInterrupt: print("Bye")
def do_read(): rdr = mfrc522.MFRC522(14,13,12,2,15) oled.fill(0) oled.text("Ponga la targeta",0,0) oled.text("para leer datos...",0,10) oled.show() try: while True: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: targeta = "T.n:" + (str(raw_uid)) if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: z=rdr.read(8)(raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3]) texto="" for i in range(16): texto+=(chr(z[i])) oled.fill(0) oled.text("Targeta:",0,0) oled.text(str(z),0,10) oled.text("Datos:",0,20) oled.text(texto,0,30) oled.show() rdr.stop_crypto1() else: print("Authentication error") else: print("Failed to select tag") except KeyboardInterrupt: print("Bye")
def do_read(): rdr = mfrc522.MFRC522(0, 2, 4, 5, 14) print("Place card before reader to read from address 0x08") try: while True: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: beep() print("New card detected") print(" - tag type: 0x%02x" % tag_type) print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) print("") if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: print("Address 8 data: %s" % rdr.read(8)) rdr.stop_crypto1() else: print("Authentication error") else: print("Failed to select tag") except KeyboardInterrupt: beep_deinit() print("Bye")
def read(): #Provoca rst usando 0,2 #possivelmente precisa esperar um tempo para poder usar estes pinos #pois fazem parte o boot #rdr = mfrc522.MFRC522(0, 2, 4, 5, 14) rdr = mfrc522.MFRC522(12, 13, 4, 5, 14) while (True): print("") print("Place card before reader to read from address 0x08") print("") try: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: return (tag_type, raw_uid) #else: # return (False, 0, 0) #else: # return (False, 0, 0) except KeyboardInterrupt: print("Bye")
def rfid_read(): global device, led1, wdt led1.open('led1') rdr = mfrc522.MFRC522() while True: ret, cardid = read.do_read(rdr) if ret == True: print('card authen ok!') senddata = { 'cardinfo': 'findCard', 'cardid': "0x%02x%02x%02x%02x" % (cardid[0], cardid[1], cardid[2], cardid[3]) } data = {'params': ujson.dumps(senddata)} device.postProps(data) level = led1.read() if level == 1: led1.write(0) else: led1.write(1) else: print('card authen failed!') time.sleep(1) wdt.feed()
def do_write(): if uname()[0] == 'WiPy': rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") elif uname()[0] == 'esp8266': rdr = mfrc522.MFRC522(14, 13, 12, 2, 15) else: raise RuntimeError("Unsupported platform") print("") print("Place card before reader to write address 0x08") print("") try: while True: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: print("New card detected") print(" - tag type: 0x%02x" % tag_type) print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) print("") if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: stat = rdr.write(8, b'\nCristi gallina ') rdr.stop_crypto1() if stat == rdr.OK: print("Data written to card") else: print("Failed to write data to card") else: print("Authentication error") else: print("Failed to select tag") except KeyboardInterrupt: print("Bye")
def __init__(self): self.start_state = 0 self.details = '' self.name = '' self.scanned = False self.client = Client(account_sid, auth_token) # Create an object of the class MFRC522 self.MIFAREReader = mfrc522.MFRC522()
def __init__(self): #Provoca rst usando 0,2 #possivelmente precisa esperar um tempo para poder usar estes pinos #pois fazem parte do boot #rfid = mfrc522.MFRC522(0, 2, 4, 5, 14) # sck, mosi, miso, rst, cs(sda) # D6 D7 D2 D1 D5 self.rfid = mfrc522.MFRC522(12, 13, 4, 5, 14)
def do_write(): rdr = mfrc522.MFRC522(0, 2, 4, 5, 14) print("") print("Place card before reader to write address 0x08") print("") try: while True: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: print("New card detected") print(" - tag type: 0x%02x" % tag_type) print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) print("") if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] #key = [0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5] # write block 8 with (00:00:...:00) block = 0x08 if rdr.auth(rdr.AUTHENT1A, block, key, raw_uid) == rdr.OK: #if rdr.auth(rdr.AUTHENT1B, block, key, raw_uid) == rdr.OK: #stat = rdr.write(block, b"\xff\xff\xff\xff\xff\xff\xff\x07\x80\x79\xb0\xb1\xb2\xb3\xb4\xb5") #stat = rdr.write(block, b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F") stat = rdr.write(block, b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") rdr.stop_crypto1() if stat == rdr.OK: print("Data written to card") else: print("Failed to write data to card") else: print("Authentication error") ''' # write block B with (FF:FF...) default factory key block = 0x0B if rdr.auth(rdr.AUTHENT1A, block, key, raw_uid) == rdr.OK: #if rdr.auth(rdr.AUTHENT1B, block, key, raw_uid) == rdr.OK: stat = rdr.write(block, b"\xff\xff\xff\xff\xff\xff\xff\x07\x80\x69\xff\xff\xff\xff\xff\xff") rdr.stop_crypto1() if stat == rdr.OK: print("Default key written to card") else: print("Failed to write default key to card") else: print("Authentication error") ''' else: print("Failed to select tag") except KeyboardInterrupt: print("Bye")
def __init__(self): self.led = machine.Pin(self.LED_PIN, machine.Pin.OUT) self.button = machine.Pin(self.BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_UP) self.button_last_pressed = time.time() self.status = None self.current_folder = None self.pause() self.rdr = mfrc522.MFRC522(0, 2, 4, 5, 14) self.rfid_cards = rfidcards.RfidCards()
def do_read(): global canAccess working = True if uname()[0] == 'esp32': rdr = mfrc522.MFRC522(18, 23, 19, 4, 26) else: raise RuntimeError("Unsupported platform") print("") print("Place card before reader to read from address 0x08") print("") hex_uid = "" global start_reading start_reading = time.ticks_ms() try: while (working): client.check_msg() (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: start_reading = time.ticks_ms() print("New card detected") print(" - tag type: 0x%02x" % tag_type) hex_uid = twoDigitHex(raw_uid[0]) + twoDigitHex(raw_uid[1]) + twoDigitHex(raw_uid[2]) + twoDigitHex(raw_uid[3]) print(hex_uid) msg = ("UID={}".format(hex_uid)) client.publish(rfid_swipe, msg) print("Publish to broker") if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: print("Address 8 data: %s" % rdr.read(8)) rdr.stop_crypto1() else: print("Authentication error") else: print("Failed to select tag") sleep_ms(300) micropython.mem_info() client.wait_msg() sleep_ms(1000) print("Can Access Value") print(canAccess) else: if (abs(time.ticks_diff(time.ticks_ms(), start_reading) > 60000)): print("Going to sleep") client.publish(device_state, "OFF") sleep_ms(1000) machine.deepsleep() except KeyboardInterrupt: print("Bye")
def read_card_main(): global temperature global listening while continue_reading: import mfrc522 # Create an object of the class MFRC522 mfrc522 = mfrc522.MFRC522() # Scan for cards (status,TagType) = mfrc522.MFRC522_Request(mfrc522.PICC_REQIDL) # Get ambient temperature all the time if status == 2: if ser.in_waiting > 0: received_serial = ser.readline().decode().strip() temperature = round(float(received_serial),1) print('ambient: '+ str(temperature)) message = {} message["deviceid"] = "tempsensor1" import datetime as datetime now = datetime.datetime.now() message["date_time"] = now.isoformat() message["ambient_temp"] = temperature import json my_rpi.publish("sensors/ambient", json.dumps(message), 1) # If a card is found if status == 0: # Get the UID of the card (status,uid) = mfrc522.MFRC522_Anticoll() if uid: lcd.text("Please move", 1) lcd.text("closer", 2) ser.reset_input_buffer() tapRFID = True print("New card detected! UID of card is {}".format(uid)) ser.write("READY".encode()) while tapRFID: if ser.in_waiting > 0: received_serial = ser.readline().decode().strip() temperature = round(float(received_serial),1) print(temperature) tapRFID = False message = {} message["deviceid"] = 'empstore' message["rfid"] = listToString(uid) import datetime as datetime now = datetime.datetime.now() message["date_time"] = now.isoformat() message["temperature"] = temperature import json my_rpi.publish("sensors/temp", json.dumps(message), 1) activate_LCD()
def __init__(self, db): self.db = db self.net = a.acf_network(DEBUG=True) self.rfid = r.MFRC522(2, 16, spiblk=1) self.motor = ed.Motor(None, None, 0, 15, 500, 50) self.load = ls.LoadSensor() self.key_verified = False self.pet_detected = False self.feed = False self.base_wt = None self.feed_wt = None
def do_read(): pycom.heartbeat(False) # if uname()[0] == 'WiPy': # rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP14") # rdr = mfrc522.MFRC522("P14", "P16", "P15", "P22", "P14") rdr = mfrc522.MFRC522("P7", "P9", "P8", "P11", "P12") # elif uname()[0] == 'esp8266': # rdr = mfrc522.MFRC522(14, 16, 15, 22, 14) # else: # raise RuntimeError("Unsupported platform") print("") print("Place card before reader to read from address 0x08") print("") try: while True: pycom.rgbled(0x000000) (stat, tag_type, recv) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: print("New card detected") print(" - tag type: 0x%02x" % tag_type) print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) print("") pycom.rgbled(0xff00ff) if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: print("Address 8 data: %s" % rdr.read(8)) rdr.stop_crypto1() else: print("Authentication error") else: print("Failed to select tag") # else: # print("Something wrong") # print(" Status: " + str(stat)) # print("Tag Type: " + str(tag_type)) # print(" recv: " + str(recv)) time.sleep(0.7) except KeyboardInterrupt: print("Bye")
def __init__(self, window): #buzzer frame button buzzerFrame = Frame(window) Button(buzzerFrame, text="Buzzer_Control", padx=5, pady=5, command=self.userClickBuzzer).pack(expand=YES, fill=BOTH, padx=30, pady=10) buzzerFrame.pack(expand=YES, fill=BOTH) # rfid init self.MIFAREReader = MFRC522.MFRC522() # lcd init self.lcd = Lcd() # lcd frame lcdFrame = Frame(window) self.entryString1 = StringVar() self.entryString2 = StringVar() # grid # entry1Frame Label(lcdFrame, text="name").grid(row=0, column=0, sticky=W) Entry(lcdFrame, textvariable=self.entryString1, width=16).grid(row=0, column=1, sticky=W) self.entryString1.set("First Line") Label(lcdFrame, text="pwd").grid(row=1, column=0, sticky=W) Entry(lcdFrame, textvariable=self.entryString2, width=16).grid(row=1, column=1, sticky=W) self.entryString2.set("Second Line") Button(lcdFrame, text="Sign in", command=self.userClickSend, padx=0, pady=10).grid(row=2, column=1, sticky=W) lcdFrame.pack() # buzzer init #self.buzzer = Buzzer(16) GPIO.setwarnings(False) #GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM) GPIO.setup(16, GPIO.OUT) self.buzzer = GPIO.PWM(16, 60)
def __init__(self, window): #init fireStore cred = credentials.Certificate( '/home/pi/Documents/certificate/raspberryfirebase-firebase-adminsdk-y4f0x-cf4be2ca1a.json' ) firebase_admin.initialize_app(cred) self.firestore = firestore.client() #init lcd self.my_lcd = lcd() #init Rfid self.previousUid = [] self.MIFAREReader = MFRC522.MFRC522() self.rfidStatusHandler()
def __init__(self, window): # init fireStore cred = credentials.Certificate( '/home/pi/Documents/iotProject/eric-firebase-test-firebase-adminsdk-4bs2b-9871f102be.json' ) firebase_admin.initialize_app(cred) self.firestore = firestore.client() # init lcd self.my_lcd = lcd() # init Rfid self.previousUid = [] self.MIFAREReader = MFRC522.MFRC522() self.rfidStatusHandler()
def do_write(): spi = SPI(1, baudrate=2500000, polarity=0, phase=0) spi.init() rdr = mfrc522.MFRC522(spi=spi, gpioRst=0, gpioCs=2) print("") print("Place card before reader to write address 0x08") print("") try: while True: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: print("New card detected") print(" - tag type: 0x%02x" % tag_type) print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) print("") if rdr.select_tag(raw_uid) == rdr.OK: key = b'\xff\xff\xff\xff\xff\xff' if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: stat = rdr.write( 8, b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" ) rdr.stop_crypto1() if stat == rdr.OK: print("Data written to card") else: print("Failed to write data to card") else: print("Authentication error") else: print("Failed to select tag") except KeyboardInterrupt: print("Bye")
def main(): SPI = pyb.SPI(1) RC522_SDA = 'X4' RC522_RST = 'X2' rc52 = mfrc522.MFRC522() rc52.init_spi(SPI, RC522_RST, RC522_SDA) while True: (status, backBits) = rc52.SeekCard(0x52) if (status == 0): ( status, id, ) = rc52.Anticoll() print("card_id=", id) else: print("NO_CARD") pyb.delay(1000)
def alarmBeep(pwm): #當被呼叫時,立即發送line訊息提醒 urequests.get("http://maker.ifttt.com/trigger/BeefNoodles/with/key/bptNB3o0-7DqUh6j_poA_M") print("send") #當被呼叫時,持續做蜂鳴器發聲 while True: #當被呼叫時,代表sensor已偵測有破壞、壞人靠近,因此我們先檢測是否誤觸或是屋主回來 rfid=mfrc522.MFRC522(0,2,4,5,14) stat,tag_type=rfid.request(rfid.REQIDL) if stat==rfid.OK: stat,raw_uid=rfid.anticoll() if stat==rfid.OK: #如果有偵測到RFID卡片的讀取則 id="%02x%02x%02x%02x"%(raw_uid[0],raw_uid[1],raw_uid[2],raw_uid[3]) print("卡號:",id) #印出解除警報之卡片 time.sleep(0.1) pwm.deinit() break #表警報解除 因此跳出while迴圈,結束蜂鳴器呼叫聲 pwm.freq(1000) #由此可控制蜂鳴器大小聲 pwm.duty(128)
def __init__(self, window): #初始化lcd self.my_lcd = lcd() #初始化buzzer self.my_buzzer = Buzzer(16) #初始化RFID self.previousUid = [] self.MIFAREReader = MFRC522.MFRC522() self.rfidStatusHandler() #初始化firestore cred = credentials.Certificate( "/home/pi/raspberryfirebase-firebase-adminsdk-y4f0x-ce1ddd9e4b.json" ) firebase_admin.initialize_app( cred, {'databaseURL': 'https://raspberryfirebase.firebaseio.com/'}) self.firestore = firestore.client()