uasyncio - StreamReader not found ?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

uasyncio - StreamReader not found ?

Post by prem111 » Fri Mar 27, 2020 12:44 pm

after install uasyncio:

>>> upip.install('micropython-uasyncio')
Installing to: /lib/
Warning: micropython.org SSL certificate is not validated
Installing micropython-uasyncio 2.0 from https://micropython.org/pi/uasyncio/uasyncio-2.0.tar.gz
Installing micropython-uasyncio.core 2.0 from https://micropython.org/pi/uasyncio.cor ... 2.0.tar.gz

Code: Select all

uasyncio.StreamReader(uart)
AttributeError: StreamReader

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: uasyncio - StreamReader not found ?

Post by kevinkk525 » Fri Mar 27, 2020 2:11 pm

I suggest using the current daily build of micropython. This includes the new version of uasyncio that can also be found in the docs: https://docs.micropython.org/en/latest/ ... yncio.html
It is still young (got merged a few days ago) and might still contain some bugs, but so does the old version from pypi..

The version from pypi is now deprecated, but would still work.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

ltmerlin
Posts: 39
Joined: Fri Jun 28, 2019 12:34 pm

Re: uasyncio - StreamReader not found ?

Post by ltmerlin » Sat Mar 28, 2020 10:14 am

I built the latest Micropython with the new uasyncio.
Can we still use uasyncio.StreamReader(uart) or uasyncio.StreamWriter(uart, {}) ? Or what is the right way to do this with the new Stream class?

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: uasyncio - StreamReader not found ?

Post by kevinkk525 » Sat Mar 28, 2020 1:49 pm

To be honest, I am not using StreamReader at the moment, so I can't comment on that. But in this thread there is a similar question: viewtopic.php?f=15&t=7925
And Peter Hinch will probably answer that, he knows more about Streams and IO than I do.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

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

Re: uasyncio - StreamReader not found ?

Post by pythoncoder » Sun Mar 29, 2020 12:25 pm

[EDIT] The following is wrong. Please see later post.
StreamReader and StreamWriter do work, as does my uart example.

Code: Select all

>>> for x in sorted(dir(uasyncio)):
...     print(x)
... 
CancelledError
Event
IOQueue
Lock
Loop
Queue
Server
SingletonGenerator
Stream
StreamReader
StreamWriter
Task
TimeoutError
__class__
__file__
__name__
__path__
core
create_task
event
gather
get_event_loop
lock
open_connection
ph_delete
ph_meld
ph_pairing
run
run_until_complete
select
sleep
sleep_ms
start_server
stream_awrite
sys
ticks
ticks_add
ticks_diff
wait_for
>>> 
Peter Hinch
Index to my micropython libraries.

ltmerlin
Posts: 39
Joined: Fri Jun 28, 2019 12:34 pm

Re: uasyncio - StreamReader not found ?

Post by ltmerlin » Sun Mar 29, 2020 12:54 pm

Yes in the tagged release v1.12 StreamReader and StreamWriter are present, but I am talking about the latest Micropython commit where PR5332 (https://github.com/micropython/micropython/pull/5332) was merged. And there is no StreamReader nor StreamWriter. Is it the intention to leave it out in the future releases?

Code: Select all

MicroPython v1.12-317-g688323307-dirty on 2020-03-29; ESP32 module (spiram) with ESP32
>>>help("modules")
__main__          gc                uasyncio/lock     urandom
_boot             inisetup          uasyncio/stream   ure
_onewire          logging           ubinascii         urequests
_thread           machine           ubluetooth        uselect
_uasyncio         math              ucollections      usocket
_webrepl          micropython       ucryptolib        ussl
apa106            neopixel          uctypes           ustruct
btree             network           uerrno            utime
builtins          ntptime           uhashlib          utimeq
cmath             onewire           uhashlib          uwebsocket
dht               sys               uheapq            uzlib
ds18x20           uarray            uio               webrepl
esp               uasyncio/__init__ ujson             webrepl_setup
esp32             uasyncio/core     uos               websocket_helper
flashbdev         uasyncio/event    upip
framebuf          uasyncio/funcs    upip_utarfile
Plus any modules on the filesystem
>>>

Code: Select all

>>>import uasyncio
>>>for x in sorted(dir(uasyncio)):
>>>    print(x)
CancelledError
Event
IOQueue
Lock
Loop
SingletonGenerator
Task
TaskQueue
TimeoutError
__class__
__file__
__getattr__
__name__
__path__
__version__
_attrs
core
create_task
event
funcs
gather
get_event_loop
lock
open_connection
run
run_until_complete
select
sleep
sleep_ms
start_server
stream
sys
ticks
ticks_add
ticks_diff
wait_for

Code: Select all

>>>import uasyncio.core
>>>for x in sorted(dir(uasyncio.core)):
>>>    print(x)
CancelledError
IOQueue
Loop
SingletonGenerator
Task
TaskQueue
TimeoutError
__class__
__file__
__name__
_io_queue
_promote_to_task
_task_queue
create_task
get_event_loop
run
run_until_complete
select
sleep
sleep_ms
sys
ticks
ticks_add
ticks_diff

Code: Select all

>>>import uasyncio.event
>>>for x in sorted(dir(uasyncio.event)):
>>>    print(x)
Event
__class__
__file__
__name__
core

Code: Select all

>>>import uasyncio.funcs
>>>for x in sorted(dir(uasyncio.funcs)):
>>>    print(x)
__class__
__file__
__name__
core
gather
wait_for

Code: Select all

>>>import uasyncio.stream
>>>for x in sorted(dir(uasyncio.stream)):
>>>    print(x)
Server
Stream
__class__
__file__
__name__
core
open_connection
start_server
stream_awrite

Code: Select all

>>>import uasyncio.lock
>>>for x in sorted(dir(uasyncio.lock)):
>>>    print(x)
Lock
__class__
__file__
__name__
core

User avatar
tve
Posts: 216
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: uasyncio - StreamReader not found ?

Post by tve » Sun Mar 29, 2020 4:05 pm


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

Re: uasyncio - StreamReader not found ?

Post by pythoncoder » Mon Mar 30, 2020 4:29 am

In my earlier post I was inadvertently using an old version. StreamReader and StreamWriter are indeed missing. In my view this is unfortunate as they are present in CPython. Their loss will break code.
Peter Hinch
Index to my micropython libraries.

mshahbazi
Posts: 1
Joined: Wed Apr 01, 2020 7:53 am

Re: uasyncio - StreamReader not found ?

Post by mshahbazi » Wed Apr 01, 2020 7:58 am

StreamReader and StreamWriter are unified into uasyncio.stream.Stream

ltmerlin
Posts: 39
Joined: Fri Jun 28, 2019 12:34 pm

Re: uasyncio - StreamReader not found ?

Post by ltmerlin » Wed Apr 01, 2020 10:14 am

Nevermind, they were added back: see https://github.com/micropython/micropython/issues/5847.
Last edited by ltmerlin on Wed Apr 01, 2020 2:33 pm, edited 2 times in total.

Post Reply