IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.59k stars 491 forks source link

BLE Gatt MTU exchange is limited to 23 bytes #375

Open modestid opened 4 years ago

modestid commented 4 years ago

The Raspbian Stretch Lite, Kernel Version: 4.14.52+, BlueZ Version: 5.43 always specifies 23 bytes as the receive MTU size. When making a Bluetooth LE GATT connection both devices exchange their MTU size. The smallest value of both is used, which dictates the notification data size. I need to increase the MTU size so I can notify with larger data packets. I've seen that the L2CAP PDU size limits the ATT mtu size, and that the patch "Change default MTU for L2CAP ATT channel" by Andre Guedes was introduced in [Linux 3.6], so I don't know why I'm still limited to 23 bytes. Does anyone have insight into this issue?

sterwen commented 4 years ago

I have the same issue. I have used the setMTU method and with the traces I can see that this is propagated and acknowledged, but receiving frame is still limited to 23 bytes. Investigation on-going on the device side as well

tzachi-dar commented 4 years ago

I also have this problem with a rpii. Please update if you find anything.

StefJar commented 4 years ago

same for me on my Ubuntu. Everyone that read this article tends to set the MTU to his needs

sterwen commented 4 years ago

On my side we are still investigating. We have but traces deep in the Bluez stack part of the bluepy-helper, and so far detected nothing wrong in there. Our investigations are now in the direction of the HCI layer and BLE Chip (TI), but this is not easy.

tzachi-dar commented 4 years ago

I'm also working on debugging the bluez code. Maybe we should open an issue there and see if they can help?

schneider42 commented 4 years ago

I'm observing a similar issue with another device (card10 badge). Did anyone of you make progress?

tzachi-dar commented 3 years ago

This was solved on https://github.com/IanHarvey/bluepy/commit/d6f425a11f68b7dd51ca7ca44c56a30e9716b6b4

To anyone getting here by google: What one should do is follow instructions on https://github.com/IanHarvey/bluepy on how to install bluepi from source.

Two things to note: 1) Make sure that your bluez version is at least 5.47 (use "bluetoothctl -v" to know what your version is). 2) if you want to use it with python 3, make sure to run python3 in places that the instructions say python.

Jurpp commented 3 years ago

As this issue is still open I would like to confirm that after manually building Bluepy from source my Raspberry Pi automatically negotiates an MTU of 247. Maybe we can make a new release containing this fix?

tzachi-dar commented 3 years ago

The issue is solved, but one needs to build it themselves. +1 for a new release.

grosdode commented 3 years ago

I tried to build it (clean pi 4):

sudo apt update
sudo apt full-upgrade
reboot
sudo apt-get install git build-essential libglib2.0-dev
git clone https://github.com/IanHarvey/bluepy.git
cd bluepy
python setup.py build
sudo python setup.py install

but I get an error “ImportError: cannot import name btle”. (I never build something like this before by myself)

lauraece commented 1 year ago

Any update to change MTU and see more than 20 bytes?

Thnks.

Ballen7 commented 1 year ago

I can also confirm that commit https://github.com/IanHarvey/bluepy/commit/d6f425a11f68b7dd51ca7ca44c56a30e9716b6b4 fixed this issue.

@grosdode as a last step, delete the bluepy folder e.g. sudo rm -rf <bluepy_repo_root>/bluepy