class DoorbotListener(): def __init__(self): self.carddb = CardDB() def listen(self, port=50000): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # s.bind(('<broadcast>', port)) s.bind(('', port)) s.setblocking(0) while True: try: result = select.select([s],[],[]) payload = result[0][0].recv(1024) (event, serial, _) = payload.split("\n") if event == 'RFID': name = self.carddb.nickForCard(serial) if name: self.doorOpened(serial, name) else: self.unknownCard(serial) elif (event == 'BELL'): self.doorbell() elif (event == 'START'): self.startup() #for triggering sounds, the "serial" field is just the name of a .wav file elif (event == "TRIGGER"): self.trigger(serial) except Exception, e: print 'Exception in handler %s' % repr(e)
class DoorbotListener(): def __init__(self): self.carddb = CardDB() def listen(self, port=50000): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # s.bind(('<broadcast>', port)) s.bind(('', port)) s.setblocking(0) while True: try: result = select.select([s], [], []) payload = result[0][0].recv(1024) (event, serial, _) = payload.split("\n") if event == 'RFID': name = self.carddb.nickForCard(serial) if name: self.doorOpened(serial, name) else: self.unknownCard(serial) elif (event == 'BELL'): self.doorbell() elif (event == 'START'): self.startup() #for triggering sounds, the "serial" field is just the name of a .wav file elif (event == "TRIGGER"): self.trigger(serial) except Exception, e: print 'Exception in handler %s' % repr(e)
def __init__(self): self.carddb = CardDB()
def __init__(self): self.carddb = CardDB(dict(config.items('default'))['carddb'])