diff --git a/README.md b/README.md index c922a0ff..ebe19d64 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,6 @@ There is: * [`mqtt-messages`](./common/lib/mqtt-messages) - MQTT helper functions * [`rgb-led`](./common/lib/rgb-led) - Provides support for the RGB LED (WS2812) * [`wifi`](./common/lib/wifi) - Wifi helper functions -* Some extra bits: - * [`mqtt-python-client`](./extra/mqtt-python-client) A Python MQTT client, for testing ## Development diff --git a/extra/mqtt-python-client/.gitignore b/extra/mqtt-python-client/.gitignore deleted file mode 100644 index 08d13002..00000000 --- a/extra/mqtt-python-client/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/ve -/__pycache__ diff --git a/extra/mqtt-python-client/.vscode/settings.json b/extra/mqtt-python-client/.vscode/settings.json deleted file mode 100644 index ebdce3a5..00000000 --- a/extra/mqtt-python-client/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.pythonPath": "/Users/anatol.ulrich/work/espressif/espressif-trainings/common/extra/mqtt-python-client/ve/bin/python" -} \ No newline at end of file diff --git a/extra/mqtt-python-client/README.md b/extra/mqtt-python-client/README.md deleted file mode 100644 index faf60305..00000000 --- a/extra/mqtt-python-client/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Python MQTT client for MQTT exercise -- sends random RGB LED color commands -- sends random long garbage packets -- logs temperature values sent by MCU - -## Setup -- Configure MQTT credentials in `../../intro/mqtt/exercise` according to instructions provided in the workshop -- set up a Python environment: - -```shell -# setup (once): -$ python3 -m venv ve -$ source ./ve/bin/activate -$ pip3 install paho-mqtt toml - -# setup (every time you open a new shell): -$ source ./ve/bin/activate -``` - -# Run -```shell -$ ./mqtt.py -``` diff --git a/extra/mqtt-python-client/mqtt.py b/extra/mqtt-python-client/mqtt.py deleted file mode 100755 index 33807e25..00000000 --- a/extra/mqtt-python-client/mqtt.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python - -from time import sleep -from random import randint -from struct import unpack - -import paho.mqtt.client as mqtt -import toml - -uuid = None - - -def get_uuid(): - d = toml.load(open("../../common/lib/get-uuid/uuid.toml", "r")) - return list(d.values())[0]["uuid"] - - -def get_config(): - d = toml.load(open("../../intro/mqtt/exercise/cfg.toml", "r")) - return list(d.values())[0] - - -def on_connect(client, userdata, flags, rc): - print("Connected with result code " + str(rc)) - - # Subscribing in on_connect() means that if we lose the connection and - # reconnect then subscriptions will be renewed. - client.subscribe(f"{uuid}/hello") - - data_topic = f"{uuid}/sensor_data/#" - client.subscribe(data_topic) - - # this would subscribe to a lot of system messages - interesting but noisy! - # client.subscribe("$SYS/#") - - -def on_message(client, userdata, msg): - if "sensor_data" in msg.topic: - [mcu_temp] = unpack(">f", msg.payload) - print(f"{msg.topic} {mcu_temp:.1f}") - else: - print(f"{msg.topic} {msg.payload}") - - -def msg(): - color = [randint(0, 255), randint(0, 255), randint(0, 255)] - return f"{uuid}/command/board_led", bytearray(color) - - -def connect(): - global uuid - uuid = get_uuid() - config = get_config() - client = mqtt.Client() - client.username_pw_set(config["mqtt_user"], config["mqtt_pass"]) - client.on_connect = on_connect - client.on_message = on_message - client.connect(config["mqtt_host"], 1883, 60) - client.loop_start() - garbage = "1234567890abcdef01234567890abcdef" * 190 + "ZZZ" - while True: - # client.publish(topic, data) - cmd_topic, data = msg() - print(f"set color {list(data)}") - client.publish(cmd_topic, data) - client.publish(f"{uuid}/cmd/garbage", garbage) - sleep(1) - - -if __name__ == "__main__": - connect()