pygatt
pygatt copied to clipboard
Sending 100 packets per second But only receive 40-50 notifications.
import pygatt
import logging
from binascii import hexlify
from time import sleep
logging.basicConfig()
logging.getLogger('pygatt').setLevel(logging.DEBUG)
def handle_data(handle, value):
print('Received data: {} from handle" {}'.format(hexlify(value), handle))
HUB_UUID = '2d30c082-f39f-4ce6-923f-3484ea480596' # Characteristic for Notifications
HUB_MAC = 'CA:FD:0C:B1:5B:AF' # MAC address of the Move Hub
#Either using BlueGiga external USB adapter or the internal BLE adapter of the Raspberry Pi
adapter = pygatt.BGAPIBackend() # only 40-50 of 100 notifications per second
try:
adapter.start()
sleep(1)
device = adapter.connect(HUB_MAC,address_type=pygatt.BLEAddressType.random)
sleep(1)
device.subscribe(HUB_UUID,callback=handle_data)
print('Wait for callback ...')
sleep(100)
finally:
adapter.stop()
I wouldn't be surprised if there are many performance optimizations we could make to this library. PRs are welcome! In the meantime, I don't have any devices that send notifications at this rate, so it's hard for me to test.