bluetooth on esp32

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
iotman
Posts: 52
Joined: Sat Feb 02, 2019 4:06 pm
Location: Nanoose Bay, Canada
Contact:

Re: bluetooth on esp32

Post by iotman » Sat Sep 28, 2019 3:48 am

Hi @jimmo, thanks for that; I have read the github contributions, but the technical descriptions are way above my head. I can see that it has been a huge effort to produce the BLE capability, so we're very grateful for all that hard, hard work.

It seems you have successfully implemented it for the ESP32, so I'm wondering if there is a download somewhere we can try?

I'm also wondering if this will be a special BLE version of MicroPython we would download, or if it is a separate library that can be called?

Our needs are pretty simple; just a few BLE temperature sensors we want to occasionally monitor.

Regards, AB

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

Re: bluetooth on esp32

Post by jimmo » Sun Sep 29, 2019 10:57 am

Hi,
iotman wrote:
Sat Sep 28, 2019 3:48 am
It seems you have successfully implemented it for the ESP32, so I'm wondering if there is a download somewhere we can try?
Sorry there's not currently a download available for ESP32... it's just a very work-in-progress bit of code that was the minimum possible to demonstrate it working. If you feel like building the firmware from source though, you can build it from that branch, and I can possibly look at making some pre-built firmware images available in a few days time when I've had a chance to make some example code and documentation. (Just trying to get the STM32 version merged first!).
iotman wrote:
Sat Sep 28, 2019 3:48 am
I'm also wondering if this will be a special BLE version of MicroPython we would download, or if it is a separate library that can be called?
That's a good question... my preference is for simplicity, in which case all ESP32 firmware includes BLE. At this stage there's not really any reason not to do that because there's enough code space. Maybe in the future we could make a trimmed down ESP32 firmware with some features disabled (including BLE).

I recently added support for board-specific firmware, which is mainly to support things like pin naming. But I guess we could have BLE and non-BLE variants of each board too.
iotman wrote:
Sat Sep 28, 2019 3:48 am
Our needs are pretty simple; just a few BLE temperature sensors we want to occasionally monitor.
Cool, so it sounds like you're looking to use the "central role". I'll try and remember to include temperature sensors as one of the example code / documentation. (I'm currently using a heart rate monitor example).

User avatar
iotman
Posts: 52
Joined: Sat Feb 02, 2019 4:06 pm
Location: Nanoose Bay, Canada
Contact:

Re: bluetooth on esp32

Post by iotman » Sun Sep 29, 2019 6:23 pm

Hi @jimmo, ok, I'm ready whenever you are to test the new BLE component on an ESP32.

I'm not by any means an expert programmer, but I have produced several successful ESP32 products, so I can provide feedback from a very practical application point of view. The BLE sensors we use are relatively simple, monitoring environmental conditions like temperature, humidity, and light level, and we love the fact that they run on button batteries for about a year.

The problem we're having with them is that the range is not great, so we want to make a powered ESP32 device that will convert the data to a WiFi signal that can be uploaded to cloud platforms, such as Blynk (via MQTT).

I would expect this to be a relatively easy thing to do (famous last words?), and something that many users might ultimately want to do.

Cheers, AB

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

Re: bluetooth on esp32

Post by jimmo » Tue Oct 08, 2019 5:25 am

iotman wrote:
Sun Sep 29, 2019 6:23 pm
Hi @jimmo, ok, I'm ready whenever you are to test the new BLE component on an ESP32.
Thanks!

The PR was just merged. One important caveat is that it requires the newer version of the IDF which is currently in beta. So the default "stable" firmware won't have BLE enabled for now. However, I've asked Damien to add an additional firmware build target for IDF 4.x, so it should show up on the downloads page soon.

I'm working on documentation and samples now.

User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: bluetooth on esp32

Post by devnull » Tue Oct 08, 2019 10:52 am

Just downloaded and built the latest, and just to clarify, is it possible to enable bluetooth on this build or not ??

I can pull the latest IDF beta if necessary ??

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

Re: bluetooth on esp32

Post by jimmo » Tue Oct 08, 2019 11:03 am

devnull wrote:
Tue Oct 08, 2019 10:52 am
Just downloaded and built the latest, and just to clarify, is it possible to enable bluetooth on this build or not ??

I can pull the latest IDF beta if necessary ??
From GitHub? Yes, as long as you're building with IDF 4.x (i.e. IDF commit 310beae373446ceb9a4ad9b36b5428d7fdf2705f )

User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: bluetooth on esp32

Post by devnull » Tue Oct 08, 2019 11:08 am

No go on my DEBIAN 10, I am using python 3...

Code: Select all

make -j6 PYTHON2=python3
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
Building with ESP IDF v4
** ERROR **
EDP IDF requires pyparsing version less than 2.4
You will need to set up a Python virtual environment with pyparsing 2.3.1
Please see README.md for more information
Makefile:92: *** Incorrect pyparsing version.  Stop
.

Using previous IDF building is not a problem and no issue with pyparsing.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: bluetooth on esp32

Post by Roberthh » Tue Oct 08, 2019 11:42 am

I just compiled it on my debian 10 machine. Here, python defaults to python3. I had to look into README.md and had to call:

pip install pyserial 'pyparsing<2.4'

Then it worked.

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

Re: bluetooth on esp32

Post by jimmo » Tue Oct 08, 2019 11:43 am

For some reason, the IDF 4.x needs this older version of pyparsing, whereas IDF 3.3 happily worked on newer versions. You will need to set up a Python virtual environment with pyparsing 2.3.1.

(My best theory for this is that it actually always used the older version but in 4.x they started using features that aren't available in pyparsing 2.4).

Anyway, you'll need a virtual environment.

Code: Select all

cd ports/esp32
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install pip install -r /path/to/espressif/esp-idf/requirements.txt
make BOARD=GENERIC -j 16 deploy

User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: bluetooth on esp32

Post by devnull » Tue Oct 08, 2019 11:51 am

Thanks @Roberthh @jimmo;

pip install pyserial 'pyparsing<2.4' works for me :-)

Code: Select all

MicroPython v1.11-412-g2863dcdf4-dirty on 2019-10-08; ESP32 module with ESP32
Type "help()" for more information.
>>> import bluetooth as bt
>>> dir(bt)
['__class__', '__name__', 'BLE', 'FLAG_NOTIFY', 'FLAG_READ', 'FLAG_WRITE', 'UUID']
>>> dir(bt.BLE())
['__class__', 'active', 'config', 'gap_advertise', 'gap_connect', 'gap_disconnect', 'gap_scan', 'gattc_discover_characteristics', 'gattc_discover_descriptors', 'gattc_discover_services', 'gattc_read', 'gattc_write', 'gatts_notify', 'gatts_read', 'gatts_register_services', 'gatts_write', 'irq']
>>> 

Post Reply