I'm trying to develop a BLE central app to read OBDII readings using Micropython. I've started off by using the ble_simple_peripheral.py and ble_simple_central.py programs from the MP bluetooth examples on two ESP32 devices running MP v1.14 (because I'm using Russ Hughes ST7789 module). Those are working but I now need the peripheral to send larger chunks of data (about 150 bytes) and the central is only receiving 20 bytes, presumably limited by the MTU setting. After a fair amount of googling I've found that I can/should be able to use BLE.config - which I can do to change the 'rxbuf' size (which has had no affect) but I get an error (NameError: name 'mtu' isn't defined) when trying 'mtu' (BLE.config(mtu,150)).
Is there a way (other than building a new MP port which I'm not capable of) of changing the MTU size? Alternatively, is there another ESP32 port that has BLE plus the ability to display on a ST7899 screen (such as the TTGO)?
I would be very grateful for any help/advice/suggestions - many thanks.
How can I override BLE MTU? (or alternative solution)
-
- Posts: 27
- Joined: Sat Jul 03, 2021 5:10 pm
Re: How can I override BLE MTU? (or alternative solution)
Shouldn't mtu be a literal?
Code: Select all
BLE.config('mtu', 150)
-
- Posts: 27
- Joined: Sat Jul 03, 2021 5:10 pm
Re: How can I override BLE MTU? (or alternative solution)
Thanks for the reply, but that doesn't work either. It gives an error: TypeError: must query one param
If I do: ble.config(rxbuf=500) that works but ble.config(mtu=150) or any other variation of that gives an error of one sort or another.
From the various error messages I would guess that mtu is not defined (although it is specified in the ubluetooth docs), so, if that is true, the question is whether it is possible to implement it in some way (other than rebuilding Micropython which I'm not yet capable of doing) or whether there is some other ESP32 port of MP that does have that parameter (and the ability to write to a ST7789 display).
If I do: ble.config(rxbuf=500) that works but ble.config(mtu=150) or any other variation of that gives an error of one sort or another.
From the various error messages I would guess that mtu is not defined (although it is specified in the ubluetooth docs), so, if that is true, the question is whether it is possible to implement it in some way (other than rebuilding Micropython which I'm not yet capable of doing) or whether there is some other ESP32 port of MP that does have that parameter (and the ability to write to a ST7789 display).
Re: How can I override BLE MTU? (or alternative solution)
Yeah, the docs pretty clearly state that it's read-write, just like 'rxbuf', but I wonder if it's read-only in the ESP32 port? Did you try print(BLE.config('mtu')) to query the value?
-
- Posts: 27
- Joined: Sat Jul 03, 2021 5:10 pm
Re: How can I override BLE MTU? (or alternative solution)
Ha! it has worked - but only if I set 'mtu' AFTER I've called central = BLESimpleCentral(ble) using ble.config(mtu=500) (I set it to 500 because it is already set to 256 although I'm only getting 20 characters returned in notify).
I'll test whether that makes a material difference tomorrow.
Maybe one of the BLE gurus (@Jimmo?) can explain what is going on.
However, as of now (prior to further testing), that seems to have done the trick so many thanks for your suggestions.
Code: Select all
ble = bluetooth.BLE()
# ble.config(mtu=500) <---------- gives error: OSError: [Errno 19] ENODEV
central = BLESimpleCentral(ble)
ble.config(mtu=500)
print("MTU = ",ble.config('mtu')) # <------ works if after call to BLESimpleCentral"
Maybe one of the BLE gurus (@Jimmo?) can explain what is going on.
However, as of now (prior to further testing), that seems to have done the trick so many thanks for your suggestions.
Re: How can I override BLE MTU? (or alternative solution)
You can't set the mtu until BLE has been activated (i.e. `ble.active(True)`). BLESimpleCentral does this for you in the constructor.dougconran wrote: ↑Mon Jul 05, 2021 10:09 pmMaybe one of the BLE gurus (@Jimmo?) can explain what is going on.
FYI, if you're doing BLE stuff, you might find https://github.com/micropython/micropyt ... oth/aioble useful. Much easier than working with the low-level ubluetooth API.
-
- Posts: 27
- Joined: Sat Jul 03, 2021 5:10 pm
Re: How can I override BLE MTU? (or alternative solution)
Ah, many thanks, both for the clarification and the suggestion - I'll do just that.
-
- Posts: 27
- Joined: Sat Jul 03, 2021 5:10 pm
Re: How can I override BLE MTU? (or alternative solution)
I'm still struggling with this (setting 'mtu' to anything other than 20 chrs). I have added the following code to both the peripheral and central but the peripheral is still only transmitting 20 chrs. The one other thing that I've done is to change one of the UART_TX flags from _FLAG_READ to _FLAG_INDICATE (because that is what the OBD2 reader I'm using advertises).
I've not yet tried 'aioble' in large part because I'm using MP v1.14 (for screen display reasons) and that requires at least v1.15. Any help on where I go from here would be much appreciated. - TIA
Code: Select all
def __init__(self, ble, name="DLINK"):
self._ble = ble
self._ble.active(True)
ble.config(mtu=500)
self._ble.irq(self._irq)
...