I encounter OSError ENOMEM when working with an ESP32 board. I've flashed the latest repo state yesterday, to no avail:
Version info:
Code: Select all
MicroPython v1.9.4-410-g11a38d5dc on 2018-07-28; ESP32 module with ESP32
Any suggestions on how to debug this? I'm not scared of the actual uP-Implementation, but have not yet debugged memory errors on an embedded target.
Code: Select all
import gc
import array
import machine
import time
import network
import socket
PORT = 5000
KNOWN_NETWORKS = {
b'SSID': b'password',
}
def ip2bits(ip):
res = 0
for part in ip.split("."):
res <<= 8
res |= int(part)
return res
def bits2ip(bits):
res = []
for _ in range(4):
res.append(str(bits & 0xff))
bits >>= 8
return ".".join(reversed(res))
def setup_wifi():
nic = network.WLAN(network.STA_IF)
nic.active(True)
networks = nic.scan()
broadcast_address = None
for name, *_ in networks:
if name in KNOWN_NETWORKS:
nic.connect(name, KNOWN_NETWORKS[name])
print("Connected to {}".format(name.decode("ascii")))
ip, netmask, _, _ = nic.ifconfig()
bca_bits = ip2bits(ip)
netmask_bits = ip2bits(netmask)
bca_bits &= netmask_bits
bca_bits |= ~netmask_bits
broadcast_address = bits2ip(bca_bits)
return nic, broadcast_address
def setup_socket(nic):
sock = socket.socket(
socket.AF_INET,
socket.SOCK_DGRAM
)
while not nic.isconnected():
time.sleep(.1)
sock.settimeout(2.0)
ip, *_ = nic.ifconfig()
sock.bind((ip, PORT))
return sock
def main():
nic, broadcast_address = setup_wifi()
s = setup_socket(nic)
address = (broadcast_address, PORT)
message = "foobar"
then = time.time()
while True:
print(message, address)
s.sendto(message, address)
if time.time() - then > 1:
print(gc.mem_free())
gc.collect()
then += 1