Pico + Feather memory allocation failed
martyphee opened this issue · comments
Marty Phee commented
I'm working with a Pico and an AirLift FeatherWing
It's connecting to my Wifi and making a request to a service but I keep getting
MemoryError: memory allocation failed, allocating 9589 bytes
The server response is very small
{"data":"weather API running smoothly","status":"success"}
I've tried various ways of getting the response: text, json, iter_conect but always the same error
I add some gc memory dumps and it looks like it has enough. Not sure what to look at.
Alloc 35488
mem: 173536
Fetching status
200
Traceback (most recent call last):
File "<stdin>", line 36, in <module>
MemoryError: memory allocation failed, allocating 9589 bytes
Program
import board
import gc
import busio
from digitalio import DigitalInOut
import adafruit_requests as requests
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
WEATHER_STATUS_API = "my server"
esp32_cs = DigitalInOut(board.GP13)
esp32_ready = DigitalInOut(board.GP14)
esp32_reset = DigitalInOut(board.GP15)
spi = busio.SPI(board.GP10, board.GP11, board.GP12)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
requests.set_socket(socket, esp)
while not esp.is_connected:
try:
esp.connect_AP("...", "....")
except RuntimeError as e:
print("Unable to connect to wifi", e)
time.sleep(2)
gc.collect()
print("Alloc", gc.mem_alloc())
print("mem: ", gc.mem_free())
print("Fetching status")
r = requests.get(WEATHER_STATUS_API)
print(r.status_code)
#print(str(r.content()))
print(b"".join(r.iter_content(chunk_size=32)))
# print("-" * 40)
r.close()