Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
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'})
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
#!/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()