Working with the network loop with Python
Now, we will use the previously coded functions
to write a __main__
method that publishes many commands included in MQTT messages that the code controlling the drone will process. 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_essentials_gaston_hillar_03
folder, in the mqtt_essentials_example03_03.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, certfile=client_certificate, keyfile=client_key) client.connect(host=mqtt_server_host, port=mqtt_server_port, ...
Get MQTT Essentials - A Lightweight IoT Protocol 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.