def start(): adapter = get_provider().get_adapter() q = Queue() observer = Observer(adapter) observer.on_advertising_data = q.put # Put advertisement to queue observer.start() return (observer, q)
def sensor_data(json): print('sensor message:', json) if(json['sensorStatus'] == 'True'): adapter = get_provider().get_adapter() observer = Observer(adapter) observer.on_advertising_data = on_advertisement observer.start() time.sleep(5) observer.stop() emit('tempHumSensorUpdate', govee_devices) else: emit('tempHumSensorUpdate', {'data': 'data disabled'})
def start_listen_ble(): try: adapter = get_provider().get_adapter() global receiver_mac receiver_mac = adapter.get_device_info().address.address observer = Observer(adapter) observer.on_advertising_data = on_advertisement observer.start() except OSError: print( "Error listening for BLE advertisements, using fixed test data instead" ) start_send_test_data()
def start(bt_device=''): ''' Attributes: device (string): BLE device (default 0) ''' if not bt_device: bt_device = 0 else: # Old communication used hci0 etc. bt_device = bt_device.replace('hci', '') log.info('Start receiving broadcasts (device %s)', bt_device) q = Queue() adapter = get_provider().get_adapter(int(bt_device)) observer = Observer(adapter) observer.on_advertising_data = q.put observer.start() return (observer, q)
#!/usr/bin/env python3 import sys from time import sleep from bleson import get_provider, Observer # Get the wait time from the first script argument or default it to 10 seconds WAIT_TIME = int(sys.argv[1]) if len(sys.argv) > 1 else 10 def on_advertisement(advertisement): print(advertisement) adapter = get_provider().get_adapter() observer = Observer(adapter) observer.on_advertising_data = on_advertisement observer.start() sleep(WAIT_TIME) observer.stop()