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 vehicle_mqtt_remote_control.py 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 vehicle_mqtt_remote_control.py 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 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.