Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 - BLE and HTTPS request issue (urequests and ubluetooth library) #7038

Closed
EstebanHardware opened this issue Mar 15, 2021 · 9 comments
Closed

Comments

@EstebanHardware
Copy link

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()
`

@EstebanHardware EstebanHardware changed the title BLE and HTTPS request issue (urequests and ubluetooth library) ESP32 - BLE and HTTPS request issue (urequests and ubluetooth library) Mar 15, 2021
@cookejames
Copy link

I'm having similar issues though it is with an MQTT over SSL and bluetooth resulting in ENOMEM even when gc.mem_free() reports 60KB memory free.

@dpgeorge
Copy link
Member

This is most likely due to the FreeRTOS heap running out of memory, not the MicroPython heap (ENOMEM means an OS memory error, a Python memory error is indicated by MemoryError exception).

The solution would be to use less memory for the MicroPython heap. A way to do this is provided in #6785, but that is not yet merged to master.

@cookejames
Copy link

This is most likely due to the FreeRTOS heap running out of memory, not the MicroPython heap (ENOMEM means an OS memory error, a Python memory error is indicated by MemoryError exception).

The solution would be to use less memory for the MicroPython heap. A way to do this is provided in #6785, but that is not yet merged to master.

Thanks, it seems plausible as I've rewritten my code in C++ and not had any problems. Is it possible to see the amount free on the FreeRTOS heap?

@cookejames
Copy link

This is most likely due to the FreeRTOS heap running out of memory, not the MicroPython heap (ENOMEM means an OS memory error, a Python memory error is indicated by MemoryError exception).

The solution would be to use less memory for the MicroPython heap. A way to do this is provided in #6785, but that is not yet merged to master.

If I get time in the next couple of days I'll build the PR you mentioned and see if that helps.

@dpgeorge
Copy link
Member

Is it possible to see the amount free on the FreeRTOS heap?

See the esp32.idf_heap_info(...) function.

@enesbcs
Copy link

enesbcs commented May 9, 2021

MicroPython v1.15-64-g1e2f0d280-dirty

SSL connection response:
connection failed [Errno 12] ENOMEM

import esp32
esp32.idf_heap_info(esp32.HEAP_DATA)
[(240, 0, 0, 0)]

Its not very informative.

@enesbcs
Copy link

enesbcs commented May 14, 2021

Tried the (micropython) heap "minus memory trick" in micropython main.c but still got ENOMEM (espidf) at SSL connection.

@noodlemind
Copy link

The issue doesn't seem to be related to the memory. Validated the available memory space before and after the each step of the program execution.

@jimmo
Copy link
Member

jimmo commented Jul 21, 2022

This issue is now being tracked in #8940.

@jimmo jimmo closed this as completed Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants