We will use the recently installed paho-mqtt version 1.3.1 module to subscribe to a specific topic and run code when we receive messages in the topic. We will create a VehicleCommandProcessor class in the same Python file, named vehicle_mqtt_client.py, in the main virtual environment folder. This class will represent a command processor associated to an instance of the previously coded Vehicle class, configure the MQTT client and the subscription to the client, and declare the code for the callbacks that are going to be executed when certain events related to MQTT are fired.
We will split the code for the VehicleCommandProcessor class into many code snippets to make it easier to understand each code section. You have to add the next lines to the existing vehicle_mqtt_client.py Python file. The following lines declare the VehicleCommandProcessor class...