Next stretch goal - uasyncio on esp8266 (general availability)

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Locked
pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Next stretch goal - uasyncio on esp8266 (general availability)

Post by pfalcon » Sun Jan 29, 2017 11:39 am

The work to optimize uasyncio for ESP8266 has been ongoing for few months. The uasyncio.core module (core scheduler, no (networking) I/O) support by now has been optimized pretty well and was available for use. However, in my list there're many optimizations yet to do for the main uasyncio module before it can be proclaimed a supported option for developing non-trivial applications. However, community seems to be anxious to get it running ASAP, we get contributions to make it work and they were merged ahead of planned optimizations, and recently I was shown a screenshot with a simple webapp running using Picoweb pico-framework: https://github.com/pfalcon/picoweb/pull ... -274184519 .

So, while the plan remains the same - work nice and slow thru the optimizations, I looked thru the code to see what pieces may be problematic for ESP8266, or missing, and fixed/added them. These were released in uasyncio package v.1.1 on PyPI.

So, I'd like to announce a softlaunch of uasyncio for ESP8266 for the interested parties. There's a thread on uasyncio at http://forum.micropython.org/viewtopic.php?f=15&t=85 . You can see examples at:
All the links above lead to git repositories, and there're more examples, information, and source code around.

As most of other things in MicroPython, uasyncio implements a subset of big Python functionality, with mainline asyncio library described at https://docs.python.org/3/library/asyncio.html . It's huge read though, and MicroPython's uasyncio implements only small and sane subset of it, with few discrepancies which should be described in the forum thread above. So, if you're completely new to asyncio, feel free to run the examples above, then just look up some asyncio tutorial to get familiar with the concepts. Hopefully, this thread and forum will be also helpful with getting started and questions.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

homebrew79
Posts: 1
Joined: Mon Jan 30, 2017 8:25 pm

Re: Next stretch goal - uasyncio on esp8266 (soft launch)

Post by homebrew79 » Mon Jan 30, 2017 8:54 pm

I am so excited about this news! I wanted to try it out as an http client and ran into an error. I hope this is the right place to post my question about this. If not, please point me to the right place. This is my first post here.

I used upip to pull v1.1 of uasyncio. I used ampy to copy my lib directory to my board (Amica NodeMCU). From there I got a REPL and used ctrl+e to paste in the example http client referenced, and immediately got the following exception.

Traceback (most recent call last):
File "<stdin>", line 18, in <module>
File "/lib/uasyncio/core.py", line 131, in run_until_complete
File "/lib/uasyncio/core.py", line 123, in run_forever
File "/lib/uasyncio/core.py", line 81, in run_forever
File "/lib/uasyncio/core.py", line 128, in _run_and_stop
File "<stdin>", line 5, in print_http_headers
File "/lib/uasyncio/__init__.py", line 187, in open_connection
File "/lib/uasyncio/__init__.py", line 187, in open_connection
File "/lib/uasyncio/__init__.py", line 184, in open_connection
OSError: [Errno 110] ETIMEDOUT

Thanks! -Brian

User avatar
pythoncoder
Posts: 4485
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Next stretch goal - uasyncio on esp8266 (soft launch)

Post by pythoncoder » Tue Jan 31, 2017 8:28 am

I wrote some notes on using uasyncio for hardware interfacing here https://github.com/peterhinch/micropyth ... UTORIAL.md which some may find useful.

Myself and @robert-hh developed a touch GUI interface for the Pyboard and a TFT display https://github.com/peterhinch/micropython-tft-gui.git. As written this used a different scheduler, but we successfully ported it to uasyncio. The uasyncio library has really come of age in terms of supporting physical devices :D
Peter Hinch

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Next stretch goal - uasyncio on esp8266 (soft launch)

Post by pfalcon » Sat May 06, 2017 9:24 am

There were a lot of optimizations for uasyncio to work better on ESP8266. It is going to be included as a frozen bytecode in MicroPython 1.9, facilitating its usage with minimal memory overhead.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

User avatar
pythoncoder
Posts: 4485
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Next stretch goal - uasyncio on esp8266 (soft launch)

Post by pythoncoder » Sun May 07, 2017 5:50 am

pfalcon wrote:There were a lot of optimizations for uasyncio to work better on ESP8266. It is going to be included as a frozen bytecode in MicroPython 1.9, facilitating its usage with minimal memory overhead.
Will it be frozen on the Pyboard?
Peter Hinch

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Next stretch goal - uasyncio on esp8266 (soft launch)

Post by pfalcon » Mon Jun 05, 2017 3:10 pm

Unfortunately, 1.9 went into release with some socket module (modlwip) incompatibilities which affect basic uasyncio operation. However, the basic issues are fixed by now (i.e. available in daily builds), so examples from https://github.com/micropython/micropyt ... r/uasyncio now work.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Next stretch goal - uasyncio on esp8266 (soft launch)

Post by pfalcon » Sat Jun 10, 2017 4:04 pm

The important milestone has been achieved - with a number of optimizations, a reference Picoweb application, https://github.com/pfalcon/notes-pico, is now able to run on ESP8266. Doing so requires freezing it as bytecode, which means MicroPython should be built from source (which is the whole idea of Open Source and the reason we ran Kickstarter campaign, so if you don't build MicroPython from source, you miss a lot).

Instructions on deploying Notes Pico for ESP8266 port can be found in README, e.g. https://pypi.python.org/pypi/notes-pico.

This is an important milestone, because it finally answers question whether uasyncio approach would be viable to write non-trivial apps ESP8266. Notes Pico, a simple, but full-stack application proves that yes.

That also means that uasyncio on ESP8266 is out of "soft launch" and suitable for general use.

And to set the expectations right - with this initial success, there's still a lot to be done to make writing reliable, robust full-stack apps possible. So, there will be a lot more optimizations and refactors going forward. In particular, API of Picoweb is expected to change to accommodate that.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Next stretch goal - uasyncio on esp8266 (general availability)

Post by pfalcon » Sun Jun 11, 2017 12:48 pm

Updated version of uasyncio will be shipped with MicroPython 1.9.1, to be released shortly.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

bitninja
Posts: 131
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Interested In PicoWeb

Post by bitninja » Tue Aug 01, 2017 8:07 am

This is great news. Once again I am thoroughly impressed with the power and versatility you guys are squeezing from such meager resources. I'm especially interested in PicoWeb and love that you already have a real app running on the ESP8266. I will be digging through the code in short order... but I did have a couple of initial questions since I am new to Python...

- Do I need to understand how to use uasyncio to use the framework?
- You mention templates used in generating responses, but can you serve static content (js,imgs,html...) from the flash file system as well?

Thanks!

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Next stretch goal - uasyncio on esp8266 (general availability)

Post by pfalcon » Sat Jan 06, 2018 11:24 am

Cross-posted from: viewtopic.php?f=15&t=85&p=24415#p24415

Note that the latest uasyncio packages on PyPI require the latest MicroPython, built from source. I no longer a comaintainer of the (official) MicroPython, and don't influence when upstream releases are made.

I also test uasyncio with my fork, https://github.com/pfalcon/micropython , and in the future may imagine that it may work only with my fork.

In my fork, I continue development and optimization of uasyncio and other MicroPython-related components, which I no longer can perform in the upstream.

Note that in the future, viewtopic.php?f=15&t=85&start=80 topic will be updated with any news.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Locked