ESP32 BLE support

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
gregd99
Posts: 4
Joined: Mon Feb 22, 2021 1:24 am

ESP32 BLE support

Post by gregd99 » Mon Feb 22, 2021 1:34 am

Hi All,
This is my first ever post in this forum. Thanks to all for the work to have python available on the ESP32.

I have a BLE uart implemented on the SparkFun Thing using the Arduino environment but am struggling to get the same working with python. At this stage all I am doing is echoing chars set from putty on a win10 laptop to the ESP32. This means that my PC end and the ESP32 hw are all good.

I have seen some older comments saying that BLE is not supported on ESP32 python.... but then some discussions that seem to say the opposite.

Could someone please confirm that BLE is available on the ESP32 micro python build?

and... is there an example script that someone could point me to? I see many for the Arduino environment but not for the microPython env.

Thanks very much.
Regards

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ESP32 BLE support

Post by jimmo » Mon Feb 22, 2021 4:48 am

gregd99 wrote:
Mon Feb 22, 2021 1:34 am
I have a BLE uart implemented on the SparkFun Thing using the Arduino environment but am struggling to get the same working with python. At this stage all I am doing is echoing chars set from putty on a win10 laptop to the ESP32. This means that my PC end and the ESP32 hw are all good.
If you're not already aware of http://docs.micropython.org/en/latest/r ... rd.py.html then that's a very handy tool for getting started with copying files etc. Also worth checking out rshell.
gregd99 wrote:
Mon Feb 22, 2021 1:34 am
Could someone please confirm that BLE is available on the ESP32 micro python build?
Yes, it's been supported for a little while now, although I recommend using the v1.14 release. Please see https://docs.micropython.org/en/latest/ ... tooth.html

The ESP32 support is not _quite_ as full-featured as other ports (it's missing pairing & bonding and l2cap channels) but it supports scanning, advertising, central and peripheral, as well as gatt client and server.

Examples here: https://github.com/micropython/micropyt ... /bluetooth

The BLE API is extremely low-level, and not particularly friendly -- I designed it to be the minimum thing to make the required functionality available. I've been working on a high-level wrapper based on asyncio for it. See https://github.com/jimmo/micropython-li ... ble/aioble

gregd99
Posts: 4
Joined: Mon Feb 22, 2021 1:24 am

Re: ESP32 BLE support

Post by gregd99 » Mon Feb 22, 2021 10:37 am

Thanks very much. I have progress!

Code: Select all

MicroPython v1.14 on 2021-02-02; ESP32 module with ESP32

Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
bytearray(b'\x02\x01\x06\x0c\tmicropython\x03\x03\x1a\x18\x11\x07\x9e\xca\xdc$\x0e\xe5\xa9\xe0\x93\xf3\xa3\xb5\x01\x00@n')
micropython
[UUID(0x181a), UUID('6e400001-b5a3-f393-e0a9-e50e24dcca9e')]
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
ImportError: no module named 'ble_uart_peripheral'
>>> 
The ble advertise script works... at least runs to completion.

When trying to run the uart script I get the error above. The offending line is

Code: Select all

from ble_uart_peripheral import BLEUART
In a normal python world, I would look to install the module ble_uart_peripheral. In the microPython world, is that possible? or all libraries are included in the fw downloaded to the ESP, and nothign can be added/removed outside of a rebuild?

Thanks very much for any assistance.

gregd99
Posts: 4
Joined: Mon Feb 22, 2021 1:24 am

Re: ESP32 BLE support

Post by gregd99 » Mon Feb 22, 2021 11:16 am

OK.... that is a little embarrassing...
I just needed to copy the other files to the uc. I am not quite used to an embedded controller having a file system!

Is the idea that I should just run the uart_reply script? This runs and does not return (tick).
I am assuming that it rx'es a char from a remote device and echos it, while printing info on the console.

From my pc I can pair with the device (mpy_uart), but this does not create a COM port.

In the Arduino environment, I did not pair but created an explicit outgoing Bluetooth COM port. Should the procedure be the same? When I try it, I do not see the ESP in the COM port create dialogue.

Is there a blog, or a few instructions on how to establish the connection?

Thanks very much.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ESP32 BLE support

Post by jimmo » Wed Feb 24, 2021 12:35 am

gregd99 wrote:
Mon Feb 22, 2021 11:16 am
I just needed to copy the other files to the uc. I am not quite used to an embedded controller having a file system!
:)

If you haven't seen it, take a look at pyboard.py or rshell for working with files.
gregd99 wrote:
Mon Feb 22, 2021 11:16 am
In the Arduino environment, I did not pair but created an explicit outgoing Bluetooth COM port.
Do you know if the Arduino example was doing Bluetooth Classic (RFCOMM) or BLE Nordic Uart Service. The MicroPython example is the latter, which I don't know if Windows supports turning into a COM port.

gregd99
Posts: 4
Joined: Mon Feb 22, 2021 1:24 am

Re: ESP32 BLE support

Post by gregd99 » Wed Feb 24, 2021 9:43 am

Thanks very much for your help.
Do you know if the Arduino example was doing Bluetooth Classic (RFCOMM) or BLE Nordic Uart Service.
"This example creates a bridge between Serial and Classical Bluetooth (SPP)"

...and google tells me that the Nordic Uart Service is not supported by win10. It happens that I received a bag of Nordic bluetooth dongles today, but I was hoping not to need them for this purpose.

Do you know if the RFCOMM protocol is supported in uPython at all?

Thanks

puttley
Posts: 4
Joined: Mon Feb 22, 2021 3:00 am

Re: ESP32 BLE support

Post by puttley » Wed Feb 24, 2021 11:35 pm

gregd99 wrote:
Mon Feb 22, 2021 10:37 am
Thanks very much. I have progress!

Code: Select all

MicroPython v1.14 on 2021-02-02; ESP32 module with ESP32

Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
bytearray(b'\x02\x01\x06\x0c\tmicropython\x03\x03\x1a\x18\x11\x07\x9e\xca\xdc$\x0e\xe5\xa9\xe0\x93\xf3\xa3\xb5\x01\x00@n')
micropython
[UUID(0x181a), UUID('6e400001-b5a3-f393-e0a9-e50e24dcca9e')]
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
ImportError: no module named 'ble_uart_peripheral'
>>> 
The ble advertise script works... at least runs to completion.

When trying to run the uart script I get the error above. The offending line is

Code: Select all

from ble_uart_peripheral import BLEUART
In a normal python world, I would look to install the module ble_uart_peripheral. In the microPython world, is that possible? or all libraries are included in the fw downloaded to the ESP, and nothign can be added/removed outside of a rebuild?

Thanks very much for any assistance.
I'm trying to setup a BLE_REPL on ESP32 board and get the same error when running the REPL over BLE UART example. What am I missing and where do I find it? Much appreciated....thank you.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ESP32 BLE support

Post by jimmo » Thu Feb 25, 2021 12:05 am

puttley wrote:
Wed Feb 24, 2021 11:35 pm
I'm trying to setup a BLE_REPL on ESP32 board and get the same error when running the REPL over BLE UART example. What am I missing and where do I find it? Much appreciated....thank you.
You need to copy ble_uart_peripheral.py (and ble_advertising.py) to the board. Here are two good starting points for accessing the filesystem on the device:

http://docs.micropython.org/en/latest/r ... rd.py.html
https://github.com/dhylands/rshell

puttley
Posts: 4
Joined: Mon Feb 22, 2021 3:00 am

Re: ESP32 BLE support

Post by puttley » Mon Mar 01, 2021 12:24 am

jimmo wrote:
Thu Feb 25, 2021 12:05 am
puttley wrote:
Wed Feb 24, 2021 11:35 pm
I'm trying to setup a BLE_REPL on ESP32 board and get the same error when running the REPL over BLE UART example. What am I missing and where do I find it? Much appreciated....thank you.
You need to copy ble_uart_peripheral.py (and ble_advertising.py) to the board. Here are two good starting points for accessing the filesystem on the device:

http://docs.micropython.org/en/latest/r ... rd.py.html
https://github.com/dhylands/rshell
Thank you, I will try this.

Post Reply