Created
March 14, 2022 19:19
-
-
Save econeale/8d993f99443ba2ba39196fbacf63d0cb to your computer and use it in GitHub Desktop.
Using persistent MQTT 5 connection with Paho MQTT Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import paho.mqtt.client as client | |
import paho.mqtt.properties as props | |
properties = props.Properties(props.PacketTypes.CONNECT) | |
properties.SessionExpiryInterval=3600 | |
mqtt_client = client.Client(client_id="test", userdata=None, protocol=mqtt.MQTTv5, transport="tcp") | |
mqtt_client.username_pw_set('mqtt_server_username', 'mqtt_server_password') | |
mqtt_client.connect('http://mqtt_server_address.com', 1234, clean_start=False, properties=properties) | |
mqtt_client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment