Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tve/mpy-mqttrepl
MQTT Repl for MicroPython
https://github.com/tve/mpy-mqttrepl
micropython micropython-esp32 mqtt
Last synced: 3 days ago
JSON representation
MQTT Repl for MicroPython
- Host: GitHub
- URL: https://github.com/tve/mpy-mqttrepl
- Owner: tve
- License: other
- Created: 2020-01-17T06:59:40.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-20T00:11:57.000Z (almost 5 years ago)
- Last Synced: 2024-11-04T11:47:49.728Z (about 2 months ago)
- Topics: micropython, micropython-esp32, mqtt
- Language: Python
- Size: 25.4 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
MicroPython experiments with an MQTT-based Repl
===============================================This repo contains work in progress, it may or may not be useful to you...
Prerequisites
-------------
- ESP32 with MicroPython v1.12 or newer, based on ESP-IDF 4.x
- An MQTT server, configured for MQTTS using PSK cipher suites if desired
- cli tools to publish messages and subscribe to topics, e.g. `mosquitto_pub`/`..._sub``mqtt_as` (asyncio) based repl in callbacks
-------------------------------------------The `src` directory contains a proof of concept repl that uses *the awesome mqtt_as* by
Peter Hinch from https://github.com/peterhinch/micropython-mqtt/blob/master/mqtt_as/mqtt_as.py.
It has been modified a bit and uses a slightly altered version of uasyncio (from the
micropython-lib) to allow for one-shot running of coroutines instead of `run_forever`.The `src/mqrepl.py` "main" starts the MQTT connection and registers some callbacks such that
the MQTT client and the associated subscription keep running in the background, very similar to
the webrepl. When everything is set-up, mqrepl drops back into the repl prompt.Commands can be sent to the repl using the topic defined by `REPL_IN`, for example:
```
> mosquitto_pub -h 192.168.0.14 --debug -p 8883 -u core --psk-identity core --psk bb000000000000000000000000000030 -t esp32/mqtest/repl/in -m "print('hello')
"
Client mosq-QcEKHJzNtxQEMWtzzk sending CONNECT
Client mosq-QcEKHJzNtxQEMWtzzk received CONNACK (0)
Client mosq-QcEKHJzNtxQEMWtzzk sending PUBLISH (d0, q0, r0, m1, 'esp32/mqtest/repl/in', ... (15 bytes))
Client mosq-QcEKHJzNtxQEMWtzzk sending DISCONNECT
```The esp32 will `eval` or `exec` the python expression/statement and send the reply back on the
topic defined by `REPL_OUT` in json form, for example:```
> mosquitto_sub -h 192.168.0.14 --debug -p 8883 -u core --psk-identity c
ore --psk bb5ec51f995a1c995eeccbdc47898530 -t esp32/mqtest/repl/out
Client mosq-a32XHgSJkfXmVTLUkA sending CONNECT
Client mosq-a32XHgSJkfXmVTLUkA received CONNACK (0)
Client mosq-a32XHgSJkfXmVTLUkA sending SUBSCRIBE (Mid: 1, Topic: esp32/mqtest/repl/out, QoS: 0, Opti
ons: 0x00)
Client mosq-a32XHgSJkfXmVTLUkA received SUBACK
Subscribed (mid: 1): 0
Client mosq-a32XHgSJkfXmVTLUkA sending PINGREQ
Client mosq-a32XHgSJkfXmVTLUkA received PINGRESP
...
Client mosq-a32XHgSJkfXmVTLUkA received PUBLISH (d0, q0, r0, m0, 'esp32/mqtest/repl/out', ... (45 by
tes))
{"r":null,"o":"hello\r\n","e":null,"x":False}
```
Where `r` is the expression result, `o` is the output, and `e` is any exception printout.Note that the way the MQTT async loop is currently run is rather hackinsh and needs further work!
`mqtt_simple` based repl
------------------------The `mqtt-simple` directory contains a callback-based repl experiment that uses a slightly modified
version of `umqtt.simple` from the micropython-lib.asyncio repl experiment
-----------------------The asyncio directory contains a first repl experiment based on `mqtt_as`.