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, certfile=client_certificate, keyfile=client_key) client.connect(host=mqtt_server_host, port=mqtt_server_port, keepalive=mqtt_keepalive) publish_command(client, CMD_SET_MAX_SPEED,...