After only 43 loops my program runs out of memory, looking at the heap I can see it's fragmented and can't allocate what is needed. Is there anyway I can fix this?
Below is my script after reading forums and various blogs for the last few hours. I'm basically collecting the data from the DHT22 sensor and passing it to another site to store it in a db. The sleep function used to be longer but I shortened it to reproduce the wrror quicker.
I believe the fault lies within urequests, since running 43 urequests.post in a row will cause the same error.
I'm running esp8266-20170108-v1.8.7.bin and I have the ESP-01s
import gc
gc.enable()
gc.collect()
import machine
gc.collect()
import urequests
gc.collect()
import dht
gc.collect()
import time
gc.collect()
d = dht.DHT22(machine.Pin(2))
url = 'http://192.168.1.3/homenas/ourapi.php'
o = {'Content-Type': 'application/x-www-form-urlencoded'}
while True:
d.measure()
t = str(d.temperature())
h = str(d.humidity())
p = "a=sdfsdf&t=" + t + "&h=" + h
ourrequest = urequests.post(url, headers = o, data = p)
time.sleep(5)
gc.collect()
Out of memory due to heap fragmentation?
- Mike Teachman
- Posts: 155
- Joined: Mon Jun 13, 2016 3:19 pm
- Location: Victoria, BC, Canada
Re: Out of memory due to heap fragmentation?
one minor suggestion is to dynamically concatenate strings in the loop with .format rather than "+". You garbage collect at the end of the loop so it's doubtful this will help, if at all...described here:
http://docs.micropython.org/en/latest/w ... ained.html
http://docs.micropython.org/en/latest/w ... ained.html
Re: Out of memory due to heap fragmentation?
Hello roygbiv,
do you find the problem ? I have the same problem, I'm using urequest library, gc is enabled and after 10 hours of running the esp8266-01 freeze.
Any idea ?
do you find the problem ? I have the same problem, I'm using urequest library, gc is enabled and after 10 hours of running the esp8266-01 freeze.
Any idea ?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Out of memory due to heap fragmentation?
You can display the heap with
as discussed in the document referenced by Mike Teachman.
Code: Select all
import micropython
micropython.mem_info(1)
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.