chrysn/aiocoap

Micropython Example

Opened this issue · 7 comments

Hello! Has anyone successfully used aiocoap with Micropython? It seems feasible in theory but I could imagine there could be gotchas with asyncio, DTLS, etc.

The ESP32, as it's the most accessible and comes in a wide array of variants that are supported by uPy.

I started to play around with the new uPy package manager mip here. It's far from working but would be the best path forward.

chrysn commented

Any update on this?

In the meantime, aiocoap has gained support for running on pyodide (eg. in Jupyter notebooks), which while still being the regular CPython, shows that there are no weird dependencies on OS level stuff (even though one may need a custom transport).

chrysn commented

IIUC micropython has no full asyncio, and thus won't support the async UDP sockets aiocoap creates; it may be necessary to build an own transport on micropython's socket, possibly based on or inspired by https://github.com/perbu/dgram/blob/master/dgram.py.

That does sound well feasible, but there's some devious details around (such as: how will the system know to which IP address the packet went, if recvmsg is not supported?), but that should suffice to get something running.

From the resource usage perspective, I think it'd be preferable to run an embedded CoAP library and only expose requests and responses -- but that'll be more effort in total, and the building blocks I'm trying to establish on the path there are not quite there yet.

Unfortunately no updates on my side. I didn't get too far in my MicroPython experiments. I did notice that the mip package manager is now officially released, which would be good to target. Most of the community seems to hang out in their Discord server, so if there's interest, that might be the best place to ask questions.

chrysn commented

I won't be using Discord, but it's possibly a suitable tool for others exploring this issue further.

I'll leave it open, both to indicate that there are not yet good examples of how (or whether) aiocoap can be used on micropython, and to have a place where others interested in trying it can exchange experiences.