Thank you for your advice! I just have a question if it is also possible to use the Stream class from the asyncio? With this i was able to receive and send data to a http server in different Coroutines but not to a HTTPS Server. i used "await asyncio.open_connection(host, 443, ssl=True)". I am receiving OSERROR -202.pythoncoder wrote: ↑Tue Jan 22, 2019 4:38 pmYou need a Python MQTT client which communicates with the broker. It would subscribe to the topic(s) to which your board published, and it would publish to the topic(s) to which your board subscribed. This Python client would talk to the webserver.
If your webserver is written in Python and you have access to the source you could adapt it to also perform the role of MQTT client.
I suggest you look at paho-mqtt for a CPython MQTT library.
Thanks in advance!
I tried out this code :
Code: Select all
import uasyncio as asyncio async def print_http_headers(): scheme = 'https' hostname = 'www.google.de' path = '/' if scheme == 'https': reader, writer = await asyncio.open_connection( hostname, 443, ssl=True) else: reader, writer = await asyncio.open_connection( hostname, 80) query = ("HEAD %s HTTP/1.0\r\nHost: %s \r\n\r\n" % (path, hostname)) print(query) writer.awrite(query.encode('latin-1')) while True: line = await reader.readline() if not line: break line = line.decode('latin1').rstrip() if line: print("HTTP header> ", line) # Ignore the body, close the socket writer.aclose() loop = asyncio.get_event_loop() loop.create_task(print_http_headers()) loop.run_forever()
Code: Select all
Traceback (most recent call last): File "<stdin>", line 34, in <module> File "/flash/lib/uasyncio/core.py", line 155, in run_forever File "/flash/lib/uasyncio/core.py", line 110, in run_forever File "<stdin>", line 20, in print_http_headers File "/flash/lib/uasyncio/__init__.py", line 131, in readline OSError: -28928
thanks in advance!