asyncio.websockets ?

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.
Post Reply
pidou46
Posts: 101
Joined: Sat May 28, 2016 7:01 pm

asyncio.websockets ?

Post by pidou46 » Fri Mar 09, 2018 9:03 pm

Hi,

I would like to try uasyncio websockets api but something goes wrong.
My attempt is to make the server side running on the esp8862 together with some other code in parallel.

Here is the context:

Code: Select all

esp8862 firmware : http://micropython.org/resources/firmware/esp8266-20171101-v1.9.3.bin
micropython-lib/uasyncio.websocket.server
Client code run from CPython:

Code: Select all

#!/usr/bin/env pytho
import asyncio
import websockets
     async def hello(uri):
          async with websockets.connect(uri) as websocket:
               await websocket.send("Hello world!")
               
asyncio.get_event_loop().run_until_complete( hello('ws://192.168.4.1:8765'))
As for now the sample code from uansycio.websocket git run but I'm not able to connect from the client.
I get the following error message from the CPython (Android but I have also try with linux an windows7: same error):

Code: Select all

Traceback (most recent call last):
  File "/data/data/ru.iiec.pydroid3/files/accomp_files/iiec_hackrun/iiec_hackrun.py", line 29, in <module>                                                                                                  start(fakepyfile,mainpyfile)                                                                      File "/data/data/ru.iiec.pydroid3/files/accomp_files/iiec_hackrun/iiec_hackrun.py", line 28, in start                                                                                                     exec(open(mainpyfile).read(),  __main__.__dict__)                                                 File "<string>", line 9, in <module>                                                                File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete                                                                      return future.result()                                                                            File "<string>", line 6, in hello                                                                   File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.6/site-packages/websockets/client.py", line 386, in __aenter__                                                                  return (yield from self)
  File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.6/site-packages/websockets/client.py", line 393, in __await__
    transport, protocol = yield from self._creating_connection
  File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.6/asyncio/base_events.py", line 777, in create_connection
    raise exceptions[0]
  File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.6/asyncio/base_events.py", line 764, in create_connection
    yield from self.sock_connect(sock, address)
  File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.6/asyncio/selector_events.py", line 451, in sock_connect
    return (yield from fut)
  File "/data/data/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.6/asyncio/selector_events.py", line 481, in _sock_connect_cb
    raise OSError(err, 'Connect call failed %s' % (address,))
ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.4.1', 8765)

[Program finished]

An idea ?

Thanks
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: asyncio.websockets ?

Post by OutoftheBOTS_ » Fri Mar 09, 2018 9:42 pm

If it helps I have used this https://github.com/jczic/MicroWebSrv to run a webserver that had websockets on my ESP32 but not sure if it works on a ESP8266 because of the limited RAM on the ESP8266.

Post Reply