hbldh / bleak

A cross platform Bluetooth Low Energy Client for Python using asyncio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple BLE devices packet loss.

13Pixel opened this issue · comments

  • bleak version: [v0.21.1]
  • Python version: python 3.10
  • Operating System: Ubuntu 22.04.3 LTS
  • BlueZ version (bluetoothctl -v) in case of Linux: bluetoothctl: 5.64

Description

Maybe It's more of BLE issue and not this library...

I have BLE devices(ESP32) which sends data(306bytes) with notify every 40ms. MTU size on device is set to 512.
When I try to send data with one device - it works as expected - I receive all packets without data loss.

The problem appears when I try to receive data from 2 or more devices.

I run two instances of same python(with bleak) code(code is very simple - when computer gets notification that there is data - he reads it and adds data to queue, after some time - notifications stops and program prints all data in queue).

Issue is that after I start reading data from second device, I start to miss packets from first device. Data loss quite high - 40%.

What I Did

I tried to send less data (100bytes every 40ms) and I get same issue.

Tried send more data from one device (450bytes every 16ms) And data loss was 0 when I reading from only one device, so I confirmed that problem isn't with throughput.

Maybe someone had same issues and know how to fix this or have ideas what I could try, how to identify where is the problem?

Thanks you.

I would suggest logging Bluetooth traffic using a sniffer to see what is going on over the airwaves. This will let you see empty packets that you can't see by logging HCI packets on the host computer.

My experience (with writing to peripherals in addition to getting notifications) is that when multiple peripherals are connected to a single adapter on the central that throughput can take a big hit because of the connection interval. BlueZ has a default connection interval of 50ms. It seems like some adapters are better than others of turning off the radio early during a connection interval. But even the "good" adapters sometimes have issues.