pygatt icon indicating copy to clipboard operation
pygatt copied to clipboard

Sending 100 packets per second But only receive 40-50 notifications.

Open zhaichenhao1889 opened this issue 6 years ago • 1 comments

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()

zhaichenhao1889 avatar Dec 06 '19 02:12 zhaichenhao1889

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.

peplin avatar Feb 21 '21 01:02 peplin