Working with the network loop with Python

Now, we will use the previously coded functions in a __main__ method that will publish many commands included in the MQTT messages that the code that controls the vehicle will process. You have to add the next lines to the existing Python file. The following lines show the code for the __main__ method, that is, the main block of code. The code file for the sample is included in the mqtt_python_gaston_hillar_05_01 folder, in the file:

if __name__ == "__main__": client = mqtt.Client(protocol=mqtt.MQTTv311) client.on_connect = on_connect client.on_subscribe = on_subscribe client.on_message = on_message client.tls_set(ca_certs = ca_certificate, ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.