A simple python 3 script to generate sensor data from a config file and send it to an MQTT broker.
Download mqttgen.py and config.json files (click on the Raw button at the top right and then save the content), edit config.json to fit your needs, if you are using it to run the Event Fabric sensors dashboard then don't change the topic in config.json unless you want to change it in the dashboard too.
The script uses the python paho-mqtt library you can install it with something like sudo pip3 install paho-mqtt.
python3 mqttgen.py config.json
Edit config.json, you can add as many sensors in the "sensors" object as you wish.
Change the values in "mqtt" section to match your MQTT broker settings.
- password is optional if you don't need password
- if username is missing, no authentication will be used.
Mariano Guerra from Event Fabric
Public Domain
Thank you, that saved me a lot of time!
However, when I ran the script, I noticed that after ~20 messages the client disconnected (or at least the sent messages never arrived at the broker).
Inserting an
mqttc.loop_start()
after themqttc.connect(host, port)
fixed that issue.