MQTT Subscriber, a simpel python MQTT client that subscribe to a topic and print the oput to a local file. You can use this client as test subscriber to check if other ocmponents make publish as expected over an MQTT broker.
docker run --rm \
--name mqtt-sub \
-e SERVER_ADDR="remote_host" \
-e PORT="1883" \
-e USERNAME="user" \
-e PASSWORD="password" \
-e TOPIC="#" \
massimocallisto/mqtt_subscriber:1.0
The subscriber will print the otput on the default file /opt/mqtt_client.dump You can map this file locally in order to persist changes and track changes outside the container.
Docker image available at: https://hub.docker.com/r/massimocallisto/mqtt_subscriber
The repo includes a helper script to run the subscriber locally without Docker.
- Create and activate a virtual environment (first time only):
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
- (Optional) Configure environment via
.envfile. The script will load values from.envif present and override defaults:
SERVER_ADDR=localhost
PORT=1883
#USERNAME=
#PASSWORD=
TOPIC=#
- Run the script:
./starter.sh
Notes:
starter.shactivates thevenvatvenv/bin/activateand then runsapp.py.- You can also export variables in your shell instead of using
.env. - Leave
USERNAME/PASSWORDunset if your broker does not require auth.