BLE and HTTPS request issue (urequests and ubluetooth library)

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
estebancr
Posts: 1
Joined: Fri Mar 12, 2021 3:33 pm

BLE and HTTPS request issue (urequests and ubluetooth library)

Post by estebancr » Sat Mar 13, 2021 12:49 am

Hi community!

As a first time person, I am new here and only a couple of months into working with ESP32. Therefore, any help from you will be appreciated.

I am working on a kind of BLE / WiFi gateway to detect some beacons and send them over the internet.

I only have a problem when I activate the BLE and try to send a request using the https protocol. (The problem does not occur with the http protocol)

Some clues:
-If I make an http request I can have the BLE active without any problem
-If I make an https request without active BLE, the requests work fine
-If I make an https request with BLE active, an OSError: [Errno 12] ENOMEM occurs. The problem appears when the urequests library invokes the ussl.wrapsocked function on line 60
-The micropython.mem_info(1) shows enough free space RAM memory

The development board is a generic 4MB ESP-WROOM-32.
Currently running firmware esp32-idf3-20200902-v1.13.bin, but I tried with:
-esp32-20210310-unstable-v1.14-84-g59a129f22.bin
-esp32-idf3-20180511-v1.9.4.bin
-esp32-idf3-20190529-v1.11.bin
-esp32-idf3-20191220-v1.12.bin
-esp32-idf3-20210202-v1.14.bin
-esp32-idf4-20210202-v1.14.bin
And also with my own build, but the same problem occurs.

Here the example code:

import network
import time
import urequests
import micropython
import webrepl
import gc
import ubluetooth

#GARBAGE COLLECTION
gc.collect()
gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())
gc.enable()

#CONNECT TO WIFI
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
print('--WLAN INIT--')
wlan.connect("Psarocolius" , "Oropendola2021")

#WAIT WHILE CONECTION IS DONE
var = 0
while (not wlan.isconnected() and var<10):
var += 1
print("--WLAN CONNETION TRY ",var)
time.sleep(1)
if wlan.isconnected():
print('--WLAN SERVICE ON-- ', wlan.ifconfig())

#HTTPS URL TO POST REQUEST
url = 'https://www.google.com/'

#ACTIVE BLUETOOTH
ble = ubluetooth.BLE()
ble.active(True)

#DESACTIVATE BLUETOOTH
#time.sleep(1)
#ble.active(False)

#MEM INFO
gc.mem_free()
#micropython.mem_info(1)

#POST REQUEST
respon = urequests.post(url)
print('Status Code: ',respon.status_code)

#MEM INFO
#micropython.mem_info(1)
gc.mem_free()

Post Reply