def keepingLEScanRunning(): #LE-Scanning gets disabled sometimes, especially if you have a lot of BLE connections, this thread periodically enables BLE scanning again global BLERestartCounter while True: time.sleep(1) now = time.time() if now - lastBLEPacketReceived > args.watchdogtimer: print("Watchdog: Did not receive any BLE packet within", int(now - lastBLEPacketReceived), "s. Restarting BLE scan. Count:", BLERestartCounter) disable_le_scan(sock) enable_le_scan(sock, filter_duplicates=False) BLERestartCounter += 1 print("") time.sleep(5) #give some time to take effect
if args.onlydevicelist and not args.devicelistfile: print( "Error: --onlydevicelist requires --devicelistfile <devicelistfile>" ) os._exit(1) dev_id = args.interface # the bluetooth device is hci0 toggle_device(dev_id, True) try: sock = bluez.hci_open_dev(dev_id) except: print("Cannot open bluetooth device %i" % dev_id) raise enable_le_scan(sock, filter_duplicates=False) try: prev_data = None def le_advertise_packet_handler(mac, adv_type, data, rssi): global lastBLEPaketReceived if args.watchdogtimer: lastBLEPaketReceived = time.time() lastBLEPaketReceived = time.time() #print("reveived BLE packet") data_str = raw_packet_to_str(data) ATCPaketMAC = data_str[10:22].upper() macStr = mac.replace(":", "").upper() atcIdentifier = data_str[6:10].upper() if (atcIdentifier == "1A18"