New to micropython & the ESP32, somewhat familiar with BLE. Using the ubluetooth library on the ESP32, I've been able to successfully gap_scan, gap_connect and gattc_read (mostly). However, on a read, the full payload I am expecting is larger than the default MTU. I found that the 'rxbuf' can be configured and tried setting that to a few different values up to 517 (the max if I understand correctly), but this didn't change the data returned.
I have been able to successfully connect & read from this other peripheral using the nRF Connect app on Android, but with the same results until I configured a larger MTU size. As I understand, this actually triggers a MTU exchange request to the gatt server on the peripheral, which then responds with a MTU exchange response.
Is there a way to exchange a new MTU in micropython?
ubluetooth: ability to set MTU after connecting to peripheral device?
Re: ubluetooth: ability to set MTU after connecting to peripheral device?
Unfortunately right now there's no Python-level API for this. It's on the TODO list: https://github.com/micropython/micropython/issues/5186
If you're happy to build your own firmware, then you can modify MP_BLUETOOTH_DEFAULT_ATTR_LEN in extmod/modbluetooth.h or modify the call to ble_att_set_preferred_mtu in extmod/nimble/modbluetooth_nimble.c
If you're happy to build your own firmware, then you can modify MP_BLUETOOTH_DEFAULT_ATTR_LEN in extmod/modbluetooth.h or modify the call to ble_att_set_preferred_mtu in extmod/nimble/modbluetooth_nimble.c
Re: ubluetooth: ability to set MTU after connecting to peripheral device?
If you have thoughts on how this should work, please comment on that bug.
Some ideas:
- If you modify hte rxbuf size, it should also implicitly set the mtu to be at least that big?
- Add an explicit "set MTU" function to the BLE type.
Some ideas:
- If you modify hte rxbuf size, it should also implicitly set the mtu to be at least that big?
- Add an explicit "set MTU" function to the BLE type.
Re: ubluetooth: ability to set MTU after connecting to peripheral device?
Thanks for the response @jimmo. Might be fun to give building MP myself a try, I'll post up if I have any success.
If I get into the weeds enough to have any worthwhile suggestions I'll definitely add a comment. Without being too familiar with the internals, as a user of the API I would either prefer an explicit function or perhaps a MTU arg on the gap_connect function, which would immediately set the MTU on successful connection. The arg 'rxbuf' isn't readily apparent as equivalent to MTU to somebody new to the scene.
If I get into the weeds enough to have any worthwhile suggestions I'll definitely add a comment. Without being too familiar with the internals, as a user of the API I would either prefer an explicit function or perhaps a MTU arg on the gap_connect function, which would immediately set the MTU on successful connection. The arg 'rxbuf' isn't readily apparent as equivalent to MTU to somebody new to the scene.
Re: ubluetooth: ability to set MTU after connecting to peripheral device?
I was able to build MP myself successfully and flash it to the esp32, so I then took a shot at modifying the constant specified above, but it didn't appear to have any effect. I also tried changing the call to ble_att_set_preferred_mtu to a few different values without any apparent change in behavior. I made sure to clean and make again each time, and even tried a bogus value to ensure my changes were being picked up. I haven't dug any further to see if I can determine if the MTU request is actually being sent/acknowledged yet.
Re: ubluetooth: ability to set MTU after connecting to peripheral device?
OK, interesting. I'll hopefully get around to this in the next few weeks (but lots of other priorities too), so keep an eye on https://github.com/micropython/micropython/issues/5186