- Python 3 with
pipandpaho-mqttpreinstalled - Docker
-
Generate the code
ag https://raw.githubusercontent.com/asyncapi/python-paho-template/master/samples/temperature.yaml @asyncapi/python-paho-template -o ./generated_code -
Patch main.py to send some data An example of code:
# Example of how to publish a message. You will have to add arguments to the constructor on the next line: payload = SensorReading("SensorId3",12,SensorReading.BaseUnit.CELSIUS) -
Create Mosquitto broker configuration
Get the example configuration from here
In
mosquitto.confwe enabled anonymous logging. This SHOULD NOT be the case in production. -
Install and run mosquitto MQTT broker
docker run -it -p 0.0.0.0:1883:1883 -p 0.0.0.0:9001:9001 -v $PWD/../samples/mosquitto.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto -
Configure .ini file Rename
config-template.inìintoconfig.iniand paste:[DEFAULT] host=127.0.0.1 password= port=1883 username= -
Run your code
python main.py