O'Reilly logo

Hands-On MQTT Programming with Python by Gaston C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required