def __init__(self, systemHandler, settings, logger, tokens, outputHandler, pi, pinDef): import pigpio # pigpio is started in main, but this is necessary here for pullup definitions try: import wiegand except ImportError: print("*** Wiegand.py not found - please download it and place it in the root directory for this folder ***\n") print("This should do the trick, assuming you're in the root directory now:") print("wget http://abyz.me.uk/rpi/pigpio/code/wiegand_py.zip") print("unzip wiegand_py.zip") print("rm -rf wiegand_old.py wiegand_py.zip\n") exit() # internalise settings, tokens, logger, outputHandler, pi and pinDef self.__systemHandler = systemHandler del systemHandler self.__settings = settings del settings self.__logger = logger del logger self.__tokens = tokens del tokens self.__outputHandler = outputHandler del outputHandler self.__pi = pi del pi self.__pinDef = pinDef del pinDef # see if __settings are set if self.__settings.allSettings is False: return # the __settings we're going to get are settingsToGet = ["delimiter", "timeout", "bruteforceThresholdTime", "bruteforceThresholdAttempts", "overspeedThresholdTime", "lockoutTime"] # make sure they exist # if exist, update __params list for s in settingsToGet: try: self.__settings.allSettings["inputHandling"][s] except Exception: # self.__logger.log("WARN", "unable to read setting", e) pass else: self.__logger.log("DBUG", "input handler: new setting", {"parameter": s, "value": self.__settings.allSettings["inputHandling"][s]}) self.__params[s] = self.__settings.allSettings["inputHandling"][s] # initialise some pins for pullup and glitchfilter self.__pi.set_glitch_filter(self.__pinDef.pins["doorbellButton"], 100000) self.__pi.set_glitch_filter(self.__pinDef.pins["doorSensor"], 50000) self.__pi.set_pull_up_down(self.__pinDef.pins["doorbellButton"], pigpio.PUD_UP) self.__pi.set_pull_up_down(self.__pinDef.pins["doorSensor"], pigpio.PUD_UP) # set the wiegand reading # will call function __wiegandCallback on receiving data w = wiegand.decoder(self.__pi, self.__pinDef.pins["wiegand0"], self.__pinDef.pins["wiegand1"], self.__wiegandCallback) # done return
def __init__(self): import pigpio import wiegand pi = pigpio.pi() self.reader = wiegand.decoder(pi, 14, 15, self.wiegand_callback, bit_timeout=3)
def _setup_gpio(self): self.pi = pigpio.pi() self.pi.write(self.buzzer_pin, 1) a = self.pi.callback(self.arm_alarm_button_pin, pigpio.FALLING_EDGE, self._arm_alarm) b = self.pi.callback(self.alarm_sounding_status_pin, pigpio.FALLING_EDGE, self._alarm_sounding) self.wiegand = wiegand.decoder(self.pi, self.unknown_pin_b, self.unknown_pin_c, self._tag_scanned, self.unknown_pin_d) print("GPIO setup complete.")
def do_cp(): name = 'cpdaemon' logger = logging.getLogger(name) handler = logging.FileHandler('/tmp/%s.log' % (name)) formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') handler.setFormatter(formatter) logger.addHandler(handler) logger.setLevel(logging.WARNING) while True: try: pi = pigpio.pi() w = wiegand.decoder(pi, 27, 17, callback) localtime = time.asctime( time.localtime(time.time()) ) print "Started Localtime: ", localtime while 1: time.sleep(1) except Exception, ex: logger.error(ex) w.cancel() pi.stop() GPIO.cleanup()
print("bits={} facility={} id={}".format(bits, facility, id_num)) if (bits == 26): ident = str(facility) + str(id_num) if ident in cached_allows and cached_allows[ident] > utc.localize(datetime.utcnow()): print "Cached authorization is present and valid" open_door() else: url = 'http://rpiambulance.com/doorauth.php' values = {'facility_id': facility, 'card_id': id_num} data = urllib.urlencode(values) req = urllib2.Request(url, data) response = urllib2.urlopen(req) html = response.read() vars = json.loads(html) print vars if vars['authorized'] == True: cached_allows[ident] = dateutil.parser.parse(vars['until']).astimezone(utc) open_door() pigpio.start() w = wiegand.decoder(23, 24, callback) time.sleep(300) w.cancel() pigpio.stop()
def cancel(self): """ Cancel the Wiegand decoder. """ self.cb_0.cancel() self.cb_1.cancel() if __name__ == "__main__": import time import pigpio import wiegand def callback(bits, value): print("bits={} value={}".format(bits, value)) pigpio.start() w = wiegand.decoder(14, 15, callback) time.sleep(300) w.cancel() pigpio.stop()
""" Cancel the Wiegand decoder. """ self.cb_0.cancel() self.cb_1.cancel() if __name__ == "__main__": import time import pigpio import wiegand def callback(bits, value): print("bits={} value={:026b}".format(bits, value)) card_id = int("{:026b}".format(value)[1:25], 2) print("Card ID: {:010d}".format(card_id)) pi = pigpio.pi() w = wiegand.decoder(pi, 14, 15, callback) time.sleep(1000) w.cancel() pi.stop()
SENSE_B = 27 readQueue = Queue.Queue() #Weigand ReaderInterrupts def read_callback(bits, code): if bits == 26: fac = (code >> 17) & 0xFF id = (code >> 1) & 0xFFFF readQueue.put(str(fac) + str(id).zfill(5)) #Setup Weigand IO pi = pigpio.pi() dec = wiegand.decoder(pi, SENSE_A, SENSE_B, read_callback) #Setup broadcast socket sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) #Wait for cardto be read while True: if not readQueue.empty(): id = readQueue.get() print id sock.sendto( '{"action" : "cardRead", "location" : "frontDoor", "id" : "' + id + '" }', ('255.255.255.255', 50505))
self.cb_0.cancel() self.cb_1.cancel() if __name__ == "__main__": import time import pigpio import wiegand def callback(bits, value): print("bits={} value={}".format(bits, value)) if (value == 43456586): pi.write(6, 1) time.sleep(2) pi.write(6, 0) print("s") pi = pigpio.pi() w = wiegand.decoder(pi, 13, 26, callback) time.sleep(300) w.cancel() pi.stop()
'Please provide proper arguments; e.g. python keypad.py <name> <portA> <portB>' ) def convert_val_pin(value): try: value = '{:26b}'.format(value) value = value[:25] value = value[5:25] return int(value, 2) except: return None def callback(bits, value): #print('bits={} value={:026b}'.format(bits, value)) pin = convert_val_pin(value) try: params = {'pin': pin, 'name': name} requests.get(url='http://localhost:4000/kp/', params=params) except: pass pi = pigpio.pi() w = wiegand.decoder(pi, portA, portB, callback) time.sleep(300) #w.cancel() #pi.stop()
if bits == 4: readDigit(value) # pinpad else: tryAuth(value) # fob # Setup logging logger = logging.getLogger("Door Log") logger.setLevel(LOG_LEVEL) handler = RotatingFileHandler(LOG_FILE, maxBytes=10*1024*1024, backupCount=5) formatter = logging.Formatter(LOG_FORMAT, LOG_TIME_FORMAT) handler.setFormatter(formatter) logger.addHandler(handler) logger.debug('Setting up wiegand decoder callbacks') pi = pigpio.pi() w = wiegand.decoder(pi, W0_PIN, W1_PIN, callback) logger.debug('Setting GPIO pin modes') pi.set_mode(BUZZ_PIN, pigpio.OUTPUT) pi.set_mode(LED_PIN, pigpio.OUTPUT) pi.set_mode(DOOR_PIN, pigpio.OUTPUT) logger.debug('Setting initial GPIO pin states') pi.write(BUZZ_PIN, 1) pi.write(LED_PIN, 1) pi.write(DOOR_PIN, 1) thread.start_new_thread(flashPin, (BUZZ_PIN, .1, 4, .1)) thread.start_new_thread(flashPin, (LED_PIN, .1, 4, .1)) logger.info('Startup complete')
def cancel(self): """ Cancel the Wiegand decoder. """ self.cb_0.cancel() self.cb_1.cancel() if __name__ == "__main__": import time import pigpio import wiegand def callback(bits, value): print("bits={} value={}".format(bits, value)) pi = pigpio.pi() w = wiegand.decoder(pi, 24, 25, callback) time.sleep(300) w.cancel() pi.stop()
def start(self, d0pin, d1pin): log("Starting wiegand daemon...", newline=False) self.pi = pigpio.pi() self.w = wiegand.decoder(self.pi, d0pin, d1pin, self.callback) log("done!", timestamp=False)
def start(self, d0pin, d1pin): sys.stdout.write("Starting wiegand daemon...") self.pi = pigpio.pi() self.w = wiegand.decoder(self.pi, d0pin, d1pin, self.callback) sys.stdout.write("done!\n")
def cancel(self): """ Cancel the Wiegand decoder. """ self.cb_0.cancel() self.cb_1.cancel() if __name__ == "__main__": import time import pigpio import wiegand def callback(bits, value): print("bits={} value={}".format(bits, value)) pi = pigpio.pi() w = wiegand.decoder(pi, 22, 27, callback) time.sleep(300) w.cancel() pi.stop()