circuitpython: espidf memory error with 9.0 alpha.5
As requested, here is a report of a memory error with CP 9.0 the works under 8
The code runs OK with CP 8.2.8 but gives the following error with 9.0 Alpha.5
Adafruit CircuitPython 9.0.0-alpha.5 on 2023-11-15; Adafruit QT Py ESP32S2 with ESP32S2
>>>
>>>
soft reboot
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
ip 10.0.0.53
Traceback (most recent call last):
File "adafruit_requests.py", line 515, in _get_socket
espidf.MemoryError:
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "code.py", line 31, in <module>
File "adafruit_io/adafruit_io.py", line 758, in create_and_get_feed
File "adafruit_io/adafruit_io.py", line 722, in get_feed
File "adafruit_io/adafruit_io.py", line 565, in _get
File "adafruit_requests.py", line 711, in get
File "adafruit_requests.py", line 650, in request
File "adafruit_requests.py", line 496, in _get_socket
RuntimeError: Sending request failed
Code done running.
Here is the code
import alarm
import ipaddress
import wifi
import socketpool
import time
import adafruit_requests
import ssl
import espidf
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
import adafruit_ahtx0
import board
import busio
from secrets import secrets
import microcontroller
print("ip", wifi.radio.ipv4_address)
pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())
# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]
# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(aio_username, aio_key, requests)
# Get the 'temperature' feed from Adafruit IO
temperature_feed = io.create_and_get_feed("qtpys2-aht20-temperature")
humidity_feed = io.create_and_get_feed("qtpys2-aht20-humidity")
i2c = busio.I2C(board.SCL1,board.SDA1)
# Create sensor object, communicating over the board's default I2C bus
sensor = adafruit_ahtx0.AHTx0(i2c)
while True:
try:
temperature = sensor.temperature
temperature = temperature * (9./5.) + 32. # convert to F
humidity = sensor.relative_humidity
# set temperature value to two precision points
temperature = "%0.2f" % (temperature)
humidity = "%0.2f" % (humidity)
print("Current Temperature: {0}*F".format(temperature))
print("Sending to Adafruit IO...")
io.send_data(temperature_feed["key"], temperature)
print("Current Humidity: {0}%".format(humidity))
print("Sending to Adafruit IO...")
io.send_data(humidity_feed["key"], humidity)
time.sleep(300)
except KeyboardInterrupt:
print("Keyboard Interrupt")
except Exception as e:
print("Exception occured: reset in 5 seconds")
time.sleep(5)
microcontroller.reset()
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Comments: 15 (6 by maintainers)
Commits related to this issue
- Allocate to SPIRAM first on ESP This leaves internal memory for FreeRTOS and other IDF buffers. Fixes #8682 — committed to adafruit/circuitpython by tannewt 5 months ago
- Switch to using SPIRAM through caps_alloc We used to default to `malloc()` using SPIRAM but it disables dynamic WiFi TX buffers. The increased static buffer allocation prevents MBEDTLS from allocatin... — committed to adafruit/circuitpython by tannewt 5 months ago
Here is a reduced example which triggers the error:
import os import espidf import ssl import wifi import socketpool import adafruit_requests
pool = socketpool.SocketPool(wifi.radio) requests = adafruit_requests.Session(pool, ssl.create_default_context())
aio_username = os.getenv(“ADAFRUIT_IO_USERNAME”) aio_key = os.getenv(“ADAFRUIT_IO_KEY”)
location = “Europe/Zurich” TIME_URL = “https://io.adafruit.com/api/v2/%s/integrations/time/struct?x-aio-key=%s&tz=%s” % (aio_username, aio_key, location)
print(f"{espidf.get_total_psram()=}“) print(f”{espidf.heap_caps_get_total_size()=}“) print(f”{espidf.heap_caps_get_free_size()=}“) print(f”{espidf.heap_caps_get_largest_free_block()=}")
response = requests.get(TIME_URL)