Skip to content

Instantly share code, notes, and snippets.

@econeale
Created March 14, 2022 19:19
Show Gist options
  • Save econeale/8d993f99443ba2ba39196fbacf63d0cb to your computer and use it in GitHub Desktop.
Save econeale/8d993f99443ba2ba39196fbacf63d0cb to your computer and use it in GitHub Desktop.
Using persistent MQTT 5 connection with Paho MQTT Python
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