I am trying to send and receive data via BLE UART from App Inventor to LEGO MINDSTORMS (SPIKE) programmed in Python.
I carefully read the topic that was marked as solved by @Gerriko_io and closed on september 17, 2022.
but still I can't make my app disconnect from the BLE peripheral device, in my case a LEGO MINDSTORMS hub.
It's not possible to connect using Connect with listpicker index, (possible solution found by who posted the original topic ) as it returns OS error 133. Passing the MAC address to the Connect with address works fine, and it quickly connects and start exchanging data. I am not using timers and Reads, but just Register for Strings and I can send data by pressing a button, so very sporadically.
There's no way to trigger the IRQ_CENTRAL_DISCONNECT event in the python script BLEHandler. The LEGO hub won't disconnect.
The python library is
and the script I'm running is
from projects.mpy_robot_tools.bt import UARTPeripheral from utime import sleep_ms server = UARTPeripheral(name="server") print("Waiting for connection") while 1: if server.is_connected(): data = server.readline() if data: print(data) server.write(data+b" echo\n") else: sleep_ms(200)
I am using the latest build by @ewpatton (2022-09-02) that forces disconnection.
The other extension build I tried was BLE-device-sort.aix (2020-12-23) but didn't work either.
I remark that with the nRF connect app, I can connect, exchange data and disconnect correctly from the LEGO peripheral being controlled by the very same python script.
The project is posted below.