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
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'))
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