Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
jimmo
Posts: 1170
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by jimmo » Wed Jan 22, 2020 12:33 am

Hi,

Yes, BLE is now implemented for the ESP32 and PYBD.

Probably best start with the documentation at http://docs.micropython.org/en/latest/l ... tooth.html and the code examples at https://github.com/micropython/micropyt ... /bluetooth There's both examples of central and peripheral role functionality, and the identical code should work on both ESP32 and PYBD.

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

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by iotman » Wed Jan 22, 2020 12:40 am

Hi Jimmo, awesome, thank you so much!

Cheers, AB

Rajendra Waghmare
Posts: 8
Joined: Mon Feb 18, 2019 12:30 pm

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by Rajendra Waghmare » Thu Jan 23, 2020 11:58 am

I am migrating from Micropython 1.11 to 1.12. In micropython 1.11, I was using urequests module for cloud communication. I had 2 threads communicating with cloud simultaneously. They were working fine.
They work fine on 1.12 official release as well.

Now, when I run two threads simultaneously using urequests with above build . I get following error.

Code: Select all

[Errno 12] ENOMEM
I have configured 4MB PSRAM and used gc.collect() periodically. Out of 4 MB, 3MB RAM is always free.

Looks like, may be I have to take latest from 1.12 and try. Please comment on this.

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

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by jimmo » Thu Jan 23, 2020 11:45 pm

This is related to https://github.com/micropython/micropython/issues/5543

The memory that it's running out of isn't the MicroPython heap (which is on PSRAM), rather it's the internal RAM managed by the ESP IDF, where it allocates SSL buffers etc. We have no control over how/where the IDF allocates memory, but there may be some configuration we can tweak (see that bug and the linked issue #5303).

I'm a little bit surprised to hear this is an issue with the PSRAM build (although the fragmentation would still make it harder to allocate the SSL buffers).

I think for now stick with the release version, although seeing as you raised it in this thread I'm assuming you need BLE. So possibly see if you have any luck with the idf4 build instead?

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

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by iotman » Wed Jan 29, 2020 8:10 pm

Hi Jimmo, I just wanted to mention that I followed the simple demo in this forum post to start my BLE adventures:

viewtopic.php?f=18&t=5090&p=43164&hilit ... ate#p43164

I can confirm that it also worked perfectly on my ESP32 OLED boards, so it was a great place for a noob like me to start.

Thanks so much for your generous contribution!

Cheers, AB

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

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by jimmo » Sun Feb 02, 2020 11:18 pm

iotman wrote:
Wed Jan 29, 2020 8:10 pm
I can confirm that it also worked perfectly on my ESP32 OLED boards, so it was a great place for a noob like me to start.

Thanks so much for your generous contribution!
Great!! Thanks for letting us know :)

More examples to come... sooooon.

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

Re: Enabling Ethernet and BLE both on micropython version 1.12 for ESP32

Post by iotman » Mon Feb 03, 2020 4:08 pm

Hi Jimmo, great news, please keep it coming.

I thought the discussion elsewhere in this forum about the Xiaomi MiFlora BLE soil moisture sensor was particularly interesting because we are planning to send the data from sensors like that to Node-RED running on a Pi via MQTT (and cloud platforms like Blynk).

It has been done using the Arduino IDE, but not with Micropython yet, AFAIK.

Cheers, AB

Post Reply