Robo's esp'ecial ESP8266 fork

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
mianos
Posts: 84
Joined: Sat Aug 22, 2015 6:42 am

Re: Robo's esp'ecial ESP8266 fork

Post by mianos » Sun Jan 03, 2016 9:23 pm

I am blocked again. I have written a simple TCP web server
https://github.com/mianos/micropython/b ... pts/srv.py
and it leaks ram on each connection. :(
I'll be trying to debug the issue. (I suspect it is a case of the esp socket data or objects being orphaned or tied to the callback and the gc does not think is free).
I'm open to suggestions or any help as to how to fix it.
Every time I start to look at the gc I don't get far. It's starting to be the only area I don't totally grok.
Maybe write a simple module that reflects the strategy in the socket code with the single static instance and isolate it a bit.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Robo's esp'ecial ESP8266 fork

Post by Damien » Mon Jan 04, 2016 2:27 pm

I think there are some issues with how the GC works on the esp8266 port, since it seems to use much more memory than it should. We will get to fixing it soon!

mianos
Posts: 84
Joined: Sat Aug 22, 2015 6:42 am

Re: Robo's esp'ecial ESP8266 fork

Post by mianos » Mon Jan 04, 2016 8:58 pm

I'll try to get into it myself in the meantime. The rest of the system is top notch. I've had some sensors running for months now and no trouble at all. This is the last problem I have. :(

User avatar
jgriessen
Posts: 191
Joined: Mon Sep 29, 2014 4:20 pm
Contact:

Re: Robo's esp'ecial ESP8266 fork

Post by jgriessen » Mon Jan 25, 2016 1:18 am

To achieve 100% reliability I have integrated the ESP wifi events callbacks.
Now, I can connect to to an access point and be informed when the board receives a DHCP address.
Once I receive this I can proceed to get temperatures etc., and send them to the server.
Congrats on this! What is it like to call C code from micropython? Seems like you've done that a lot, and being new to this I want to look up How C code is called ( to see how much work it will be to pull in parts of contiki radio networking).

Does micropython using 32kb of RAM leave half available when running in the ESP's 64kb of RAM?
John Griessen blog.kitmatic.com

mianos
Posts: 84
Joined: Sat Aug 22, 2015 6:42 am

Re: Robo's esp'ecial ESP8266 fork

Post by mianos » Mon Jan 25, 2016 2:17 am

jgriessen wrote: What is it like to call C code from micropython? Seems like you've done that a lot, and being new to this I want to look up How C code is called ( to see how much work it will be to pull in parts of contiki radio networking).
It's trivial. Micropython is built for this. You just put the calls into a table and use some macros that set up the binding and the end of the function. Pretty much every file (mod_esp*) in my project calls C.

It's easy the other way too. I am currently implementing a C web server that calls python on GET/POST. You just do this "import esp; aa = esp.ws(callback=lambda aa: print(aa.body())); aa.listen()"

The simplest example of calling and and then python back is probably in esp8266/os_timer.c
Does micropython using 32kb of RAM leave half available when running in the ESP's 64kb of RAM?
There is way less ram free but you can store a lot more stuff in ROM. In the case of code (.text), you can store it in ROM, if you are not calling it in real interrupt handlers, and the CPU will move the it into ram for you. I store all python modules in the ROM but I have to do some byte fidlling before passing it to the interpreter as you can only read from ROM on 4 byte boundaries.

The lack of RAM is a constant challenge but with some care and thoughtfully placed garbage collections I can run continuous code without any leaking. I have an app polling one of my ESPs right now, doing 10 per second and it's been running all night.
If you don't make any mistakes with pointers you can achieve the same stability as much larger boards with simpler problems that need less ram.

User avatar
jgriessen
Posts: 191
Joined: Mon Sep 29, 2014 4:20 pm
Contact:

Re: Robo's esp'ecial ESP8266 fork

Post by jgriessen » Tue Jan 26, 2016 6:40 pm

The lack of RAM is a constant challenge
Did you get one of the beta ESP32's?

If you are developing a product, I'd like to talk about ideas to better promote my stalled kickstarter for outdoor chip radio sensor molded plastic enclosures.
https://www.kickstarter.com/projects/16 ... tdoor-radi
John Griessen blog.kitmatic.com

mianos
Posts: 84
Joined: Sat Aug 22, 2015 6:42 am

Re: Robo's esp'ecial ESP8266 fork

Post by mianos » Tue Jan 26, 2016 8:52 pm

jgriessen wrote:
The lack of RAM is a constant challenge
Did you get one of the beta ESP32's?

If you are developing a product, I'd like to talk about ideas to better promote my stalled kickstarter for outdoor chip radio sensor molded plastic enclosures.
https://www.kickstarter.com/projects/16 ... tdoor-radi
No I didn't get the new ESP. I do have a pyboard. I also have a CC3300 dev kit and quite a few other dev kits about.
I rather like the challenge of the ESP8266. It is quite constrained. I think the ridiculously low price point makes it a very different product. I am just finishing up a micro embedded web server (and client that uses mostly the same code) that integrates into micropython in a pythonic way. This makes sensors trivial to manage in either direction.

Code: Select all

import esp
import ujson

def cb(aws):
    print(aws.headers())
    print(aws.uri())
    print(aws.method())
    js = ujson.loads(aws.body())
    return '{"status": %d}' % counter

# web server, calls cb with the incoming web request
aa = esp.ws(callback=cb, local_port=80)
aa.listen()
# web client, calls cb with result from the remote reply
bb = esp.ws(callback=cb, remote=('131.84.1.118', 8000))
bb.async_send('/status')

mianos
Posts: 84
Joined: Sat Aug 22, 2015 6:42 am

Re: Robo's esp'ecial ESP8266 fork

Post by mianos » Sun Feb 07, 2016 8:53 pm

Everything working on my web server and client abstraction and boom, now I have written much more python I'm out of RAM for compilation of the python (even reading the python source code from the external ROM with my frozen from irom module).
I'm going to have to have a try of the pre-compiled python pull. :)

Does anyone know of an example of a C property example? For example, if I wanted to use request.headers and not request.headers() to make it more like django from a C function that provides the tuple.

User avatar
jgriessen
Posts: 191
Joined: Mon Sep 29, 2014 4:20 pm
Contact:

Re: Robo's esp'ecial ESP8266 fork

Post by jgriessen » Mon Feb 08, 2016 11:19 pm

Hi, Is your fork merged into the main micropython yet? (I don't know about the pre-compiled python pull.)

I'm going to try loading your micropython fork into a node.it esp8266 board from sweetpeas.se (a kickstarter that recently completed and delivered)
John Griessen blog.kitmatic.com

User avatar
jgriessen
Posts: 191
Joined: Mon Sep 29, 2014 4:20 pm
Contact:

Re: Robo's esp'ecial ESP8266 fork

Post by jgriessen » Tue Feb 09, 2016 1:55 am

I just tried compiling the ESP8266 fork on debian with the toolchain from https://github.com/pfalcon/esp-open-sdk and got this error message:

Code: Select all

xtensa-lx106-elf-gcc -I../lib/netutils -I. -I.. -I../stmhal -I../lib/mp-readline -I../lib/netutils -I../lib/timeutils -Ibuild -I/opt/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/sysroot/usr/include -Idevices -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -nostdlib -DUART_OS=1 -fsingle-precision-constant -Wdouble-promotion -D__ets__ -DICACHE_FLASH -fno-inline-functions -Wl,-EL -mlongcalls -mtext-section-literals  -Os -DNDEBUG  -fdata-sections -ffunction-sections -c -MD -o build/main.o main.c
main.c:40:28: fatal error: user_interface.h: No such file or directory
 #include "user_interface.h"
Ideas what went wrong?
John Griessen blog.kitmatic.com

Post Reply