Hi,
so the standard ESP8266 build offered on micropython.org doesn't include the thread library. Is there a reason for that? I would just go ahead and build it myself from the github tree. I guess a normal build would include the library, as far as I can see, right?
Thanks for your help
Carsten
Thread support ESP8266 build
Re: Thread support ESP8266 build
Nvm, just nobody implemented it for esp8266 yet, right?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Thread support ESP8266 build
By all means try it but it's possible that the ESP8266 is too resource-constrained for this. I assume you've considered and rejected uasyncio (which runs fine on the ESP8266).
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Thread support ESP8266 build
Well, I would if I could. I guess the implementation for another single-core MCU like the cc3200 could be quite similar, but I don't know much about the hardware yet and my skills in C are very limited.
No, I guess I'll try my luck with uasyncio, I was just figuring out all my options. Coming from desktop computers, a thread for a webserver was my obvious choice at first. As for the resources, I guess a threaded implementation wouldn't be much different, right?
No, I guess I'll try my luck with uasyncio, I was just figuring out all my options. Coming from desktop computers, a thread for a webserver was my obvious choice at first. As for the resources, I guess a threaded implementation wouldn't be much different, right?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Thread support ESP8266 build
Threading is indeed the choice on a PC. But the world of microcontrollers is very different. A small PC might have 4GB of RAM whereas 400K on a microcontroller would be pretty big. The ESP8266 is particularly small with about 26KB free. More than five orders of magnitude less than a small PC! So techniques which you would use freely on a PC may be unfeasible on a microcontroller.
Pre-emptive scheduling uses a lot of RAM because of the amount of context which has to be stored for each pending thread. It is supported on the larger MicroPython platforms but I have doubts whether the ESP8266 has sufficient RAM to support it. Cooperative scheduling, by contrast, is economical and the uasyncio implementation is particularly efficient. I have used it extensively on the ESP8266.
The bugbear tends to be blocking sockets. Using threading one thread can block without issue. With cooperative scheduling any task which blocks will prevent other tasks getting execution. So you need to write your code using nonblocking sockets.
If you're new to asyncio or unclear about the uasyncio subset, I wrote a tutorial here https://github.com/peterhinch/micropyth ... UTORIAL.md.
Pre-emptive scheduling uses a lot of RAM because of the amount of context which has to be stored for each pending thread. It is supported on the larger MicroPython platforms but I have doubts whether the ESP8266 has sufficient RAM to support it. Cooperative scheduling, by contrast, is economical and the uasyncio implementation is particularly efficient. I have used it extensively on the ESP8266.
The bugbear tends to be blocking sockets. Using threading one thread can block without issue. With cooperative scheduling any task which blocks will prevent other tasks getting execution. So you need to write your code using nonblocking sockets.
If you're new to asyncio or unclear about the uasyncio subset, I wrote a tutorial here https://github.com/peterhinch/micropyth ... UTORIAL.md.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Thread support ESP8266 build
Thanks for your comprehensive reply! I didn't have any experience yet, my ESP8266 arrived a week ago. You convinced me, uasyncio proved to be very convenient. I had some time to set up a captive portal to configure/manage wifi networks. Neither complete nor particularly nice yet, but maybe someone will find it useful:
https://github.com/carstenblt/micropython-configserver
Two things I noticed...
https://github.com/carstenblt/micropython-configserver
Two things I noticed...
- Btree proved to be way to memory hungry on the ESP8266. At first I wanted to store wifi passwords with it, but even just opening an empty database usually resulted in running out of memory.
- It would be awesome if you had numpy-style sphinx documentation in the source code. (Documentation right after the module/function/class definition, usually with a detailed explanation of arguments and return values.) It pushes developers to write docs right when they code, so it stays up to date and comprehensive. Also, exploring code gets much easier. But I guess you have reasons to not use it?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Thread support ESP8266 build
See viewtopic.php?f=16&t=3653&p=21216&hilit=btree#p21216 where people have done humungous database operations using the ESP8266.carsten wrote:...Btree proved to be way to memory hungry on the ESP8266...[/list]
tl;dr:
Code: Select all
db = btree.open(dbfile, pagesize=1024)
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.