Understanding callbacks

The previous code uses the recently installed paho-mqtt version 1.3.1 module to establish an encrypted connection with the MQTT server, subscribe to the vehicles/vehiclepi01/tests topic filter, and run code when we receive messages in the topic. We will use this code to understand the basics of paho-mqtt. The code is a very simple version of an MQTT client that subscribes to a topic filter and we will definitely improve it in the next sections.

The first line imports the variables we have declared in the previously coded config.py file. The second line imports paho.mqtt.client as mqtt. This way, whenever we use the mqtt alias, we will be referencing paho.mqtt.client.

When we declare a function, we pass this function ...

Get Hands-On MQTT Programming with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.