0

I am using an ESP8266 board with micropython.

I tried to use asyncio, but it doesn't work and says me that :

Traceback (most recent call last):
  File "<stdin>", line 10, in <module>
  File "<stdin>", line 7, in main
AttributeError: 'module' object has no attribute 'run'

I took a look about what does uasyncio contains and I got this :

>>> import uasyncio as asyncio
>>> asyncio.
__class__       __name__        __path__        DEBUG
log             select          sleep           sleep_ms
time            ucollections    uerrno          utimeq
type_gen        set_debug       CancelledError  TimeoutError
EventLoop       SysCall         SysCall1        StopLoop
IORead          IOWrite         IOReadDone      IOWriteDone
get_event_loop  SleepMs         cancel          TimeoutObj
wait_for_ms     wait_for        coroutine       ensure_future
Task            _socket         PollEventLoop   StreamReader
StreamWriter    open_connection                 start_server
uasyncio        core

After some researches, I have found in this documentation that uasyncio is supposed to get functions like new_event_loop(), run, etc... that I absolutely don't have there...

There is my script :

from robot import *
import uasyncio as asyncio

def main(args):
    robot = MicroportalRobot("robotName", "serverAddr", 8266)
    asyncio.run(robot.main())

if __name__ == "__main__":
    main([])

Why?

6
  • What is your micropython version? Commented Aug 3, 2023 at 19:23
  • MicroPython v1.11-8-g48dcbbe60 on 2019-05-29; ESP module with ESP8266 Commented Aug 3, 2023 at 19:30
  • 1
    You're on uasyncio v2, then. uasyncio v3 was released in micropython 1.13. You're looking at the docs for a newer uasyncio version than what you have. Commented Aug 3, 2023 at 19:32
  • I think it resolves my issue, thanks! I am supposed to close my question manually? Commented Aug 3, 2023 at 19:37
  • 1
    Consider if someone else has the same problem. Should they be able to find this question and an answer or not? Commented Aug 3, 2023 at 19:58

1 Answer 1

1

The features you're looking for are part of uasyncio v3, released as part of micropython 1.13. You need a micropython version at least as recent as 1.13 to use them. Your comments indicate you're on micropython 1.11, meaning you have the old v2 uasyncio implementation, which does not have these features.

You will need to install a more recent micropython build, or stick to the uasyncio v2 API.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.