MQTT client#


For Python, we use the client library paho-mqtt. It is pretty easy to use and provides several examples to start with on their github repo.

A basic example that subscribes to /in and publishes to /out:

import paho.mqtt.client as mqtt

# connection callback
def on_connect(client, userdata, flags, rc):
   print("Connected with result code " + str(rc))

# message received callback
def on_message(client, userdata, msg):
   print(msg.topic + " " + str(msg.payload))
   client.publish("/out", "received an input...")

# set up the client
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("", 1883, 60) # address ip, port number, keep alive

# subscribe

# process the MQTT business


The documentation of the paho-mqtt library can be found here.

The repo with our own clients can be used as a base to start.

Python MQTT