コード例 #1
0
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
コード例 #2
0
ファイル: LYWSD03MMC.py プロジェクト: zhzhzhy/MiTemperature2
def signal_handler(sig, frame):
    if args.atc:
        disable_le_scan(sock)
    os._exit(0)
コード例 #3
0
ファイル: LYWSD03MMC.py プロジェクト: zhzhzhy/MiTemperature2
                                int(sensors[mac]["calpoint1"]),
                                int(sensors[mac]["calpoint2"]))
                            print(
                                "Humidity calibrated (2 points calibration): ",
                                measurement.humidity)
                        elif "humidityOffset" in sensors[mac]:
                            measurement.humidity = humidity + int(
                                sensors[mac]["humidityOffset"])
                            print("Humidity calibrated (offset calibration): ",
                                  measurement.humidity)
                    else:
                        measurement.sensorname = mac
                    if (args.callback):
                        measurements.append(measurement)
                    #print("Length:", len(measurements))
                    print("")

        if args.watchdogtimer:
            keepingLEScanRunningThread = threading.Thread(
                target=keepingLEScanRunning)
            keepingLEScanRunningThread.start()
            logging.debug("keepingLEScanRunningThread started")

        # Blocking call (the given handler will be called each time a new LE
        # advertisement packet is detected)
        parse_le_advertising_events(sock,
                                    handler=le_advertise_packet_handler,
                                    debug=False)
    except KeyboardInterrupt:
        disable_le_scan(sock)