8000 ESP32 OSError: [Errno 12] ENOMEM urequests · Issue #8628 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

ESP32 OSError: [Errno 12] ENOMEM urequests #8628

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

Closed
chriscmorgan opened this issue May 4, 2022 · 7 comments
Closed

ESP32 OSError: [Errno 12] ENOMEM urequests #8628

chriscmorgan opened this issue May 4, 2022 · 7 comments

Comments

@chriscmorgan
Copy link
chriscmorgan commented May 4, 2022

I am getting the ENOMEM error when trying to use urequests to get data from our https api server. The error only occurs if BLE is also active at the same time. This didn't occur in 1.17 but using 1.18 now its happening. I needed the extra memory that 1.18 gives so in a bit of a bind. I am using the esp32-c3-wroom-2 (4MB RAM).

import bluetooth
ble = bluetooth.BLE()
ble.active(True)
config = station.ifconfig()
print (config[0])

request_url = 'https://<api server>' 
gc.collect()
print("Memory Free-8")
print(gc.mem_free())
print("before api request")

res = urequests.post(request_url, headers = {'content-type': 'application/json'}, data = post_data)
print(res)
print("after api request")

Error:

192.168.137.238
Memory Free-8
91408
before api request
Traceback (most recent call last):
  File "<stdin>", line 77, in <module>
  File "/mnt/c/Users/chris.morgan/Documents/code/ilume-hub-firmware/lib/urequests.py", line 60, in request
OSError: [Errno 12] ENOMEM

This error occurs only occurs on esp32c3-20220117-v1.18.bin but on esp32c3-20210902-v1.17.bin is works without error.
If I disable BLE it also works on 1.18 but I need it enabled all the time for my application.
I want to use 1.18 as 1.17 only enabled half the memory that 1.18 does and my application requires more memory.

Any help is really appreciated.

@chriscmorgan
Copy link
Author
chriscmorgan commented May 9, 2022

OK this actually seems to be due to the espidf version and not the micropython version.
Espidf 4.3.2 or 4.4 introduces this issue, there is more memory available for my python code to run but you can't have urequests and ble run at the same time. espidf4.3 works fine with both running but half the memory.
I can see 1.17 is compiled with 4.3 at: https://micropython.org/download/esp32c3/
while 1.18 is compiled with 4.4.

Any suggestions on how I can get the extra micropython memory while still being able to use urequests and ble?

@chrisovergaauw
Copy link
Contributor

I think your last question is better placed at the micropython forum to be honest.
I've ran into similar issues and dabbled with the mp_task_heap_size below to get my setup working.
https://github.com/micropython/micropython/blob/master/ports/esp32/main.c#L142

It's not really a fix and resulted in a "magic variable", so use it as a last resort.
I'm not relying on anything specific in the v4.4 so I downgraded to 4.2.3 (notice that's not 4.3.2 which you mentioned) and had a lot more success with running ble and network requests concurrently.

@puppet13th
Copy link

i think i have same issue regarding ble on esp32-c3 port.
my code uses ble + asyncio
there is no issue when running the code using esp32 port(firmware 1.18 and 1.19.1)
there is weird issue when running the code using esp32-c3 port(firmware 1.18 and 1.19.1)
now testing esp32-c3 running on firmware 1.17 -> looks good.
please check my forum post at

@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
jepler referenced this issue in jepler/circuitpython Aug 28, 2022
Turns out we already have one duplicate, so I 'endorsed' it, but probably
one should be reassigned.

Closes: adafruit#8628
@ciprianmisaila
Copy link

edit urequest.py. It does not close the connection at the end of request function. Too many sockets opened.

sina-hotmail added a commit to sina-hotmail/uPyInkbird that referenced this issue Jul 18, 2023
長時間動作してると urequests.py がエラーで止まるため

micropython/micropython#8628 (comment)
@hezi-biancheng
Copy link

当我尝试使用 urequests 从我们的 https api 服务器获取数据时,我收到 ENOMEM 错误。仅当 BLE 同时处于活动状态时,才会发生错误。这在 1.17 中没有发生,但现在使用 1.18 发生了。我需要 1.18 提供的额外内存,所以有点束缚。我正在使用 esp32-c3-wroom-2 (4MB RAM)。

import bluetooth
ble = bluetooth.BLE()
ble.active(True)
config = station.ifconfig()
print (config[0])

request_url = 'https://<api server>' 
gc.collect()
print("Memory Free-8")
print(gc.mem_free())
print("before api request")

res = urequests.post(request_url, headers = {'content-type': 'application/json'}, data = post_data)
print(res)
print("after api request")

错误:

192.168.137.238
Memory Free-8
91408
before api request
Traceback (most recent call last):
  File "<stdin>", line 77, in <module>
  File "/mnt/c/Users/chris.morgan/Documents/code/ilume-hub-firmware/lib/urequests.py", line 60, in request
OSError: [Errno 12] ENOMEM

此错误仅在esp32c3-20220117-v1.18.bin上发生,但在esp32c3-20210902-v1.17.bin上正常工作没有错误。如果我禁用 BLE,它也可以在 1.18 上运行,但我需要一直为我的应用程序启用它。我想使用 1.18,因为 1.17 只启用了 1.18 的一半内存,我的应用程序需要更多的内存。

任何帮助都非常感谢。
我也遇到了这个问题,但是我并没有打开蓝牙,在第一次连接时没有问题,第二次就出问题了,我现在特别苦恼,下面是我的导入列表:import ufont
import urequests
import utime
import random
import time
from machine import Timer
from st7735 import ST7735
from machine import SPI, Pin

@qfbt
Copy link
qfbt commented Oct 11, 2024

I met the similar error today, I finally found that it was the insufficiency of power cause it :
I used the expansion board,but I only gave power to esp32 for convenience.
That behavior may weaken the esp32's stability, so when I put sendto() in a loop, it corrupted in few rounds.
so I recommend to check the power supply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants
0