BLE characteristic is limited to 20 bytes in Rpi3

Hello, I am using DWM1001 modules to read distances between tag-anchor. I have 1 tag and 4 anchor, I made an script in python that I run on the terminal of my raspberry pi and get the distances between the tag and the anchors but I only receive 20bytes so I can´t get the full information. I know that I have to change MTU to read/write more than 20 bytes but I don´t know exactly how to do it, can any body help me?

Thanks.

Hi @laura.ece !
I’ve never tried what you’re doing, but I have a suggestion.

I believe the BLE app configures the MTU size before starting communication.
Using an RPi you may try bluez:
$ sudo apt install bluez
Then connect to the device and set the mtu size using the following commands:
$ gatttool -b <mac_address> -I

mtu <size>

After sending the command, the device should respond with a confirmation message. Then you can exit the gatttool by typing exit (or pressing Ctrl+C).

Once you have set the MTU size, you should be able to read/write more than 20 bytes of data from the remote device.

Let me know if it worked!
Best regards!

I have bluez version 5.47, this is the response I got:

pi@raspberrypi:~ $ gatttool -b dd:09:56:ee:61:8a -I
[dd:09:56:ee:61:8a][LE]> mtu 150
Command Failed: Disconnected
[dd:09:56:ee:61:8a][LE]>

Hi, @laura.ece !

One more thing is, the BLE device must support a larger MTU size, and I don’t know if 150 bytes is ok for a DWM1001 module. If you’re not sure, you can try a small value and see if it takes effect.
By the way, which python BLE library are you using? It probably has a function to set the MTU size inside your script.

Best regards!

Hello, I have tried with mtu 30 and it´s still the same error. The librarys I´m using in python are:
import os
import sys
import pygatt
import time
import logging
import binascii
from binascii import hexlify
import struct
import subprocess

Thanks.

Hi @laura.ece!

Using pygatt you can try to set the MTU size right after connecting using .exchange_mtu(size):

    adapter = pygatt.GATTToolBackend()
    adapter.start()
    peripheral = adapter.connect(mac_address)

    # Set the MTU size
    peripheral.exchange_mtu(size)

Best regards!

It worked! Thank you.

1 Like