MQTT的paho.mqtt.python如何设置会话过去间隔,代码如下:
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id=hostname, clean_session=False)
mqttc.username_pw_set(mqtt_username, mqtt_password)
mqttc.on_connect = on_connect
mqttc.on_message = on_message
mqttc.on_subscribe = on_subscribe
mqttc.on_publish = on_publish
#用于客户端掉线再次连接客户端
mqttc.on_disconnect = on_disconnect
mqttc.connect(host=mqtt_server, port=mqtt_port, keepalive=60)
已经搞定
MQTT V3.1.1 Version:
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2,
client_id=hostname, protocol=mqtt.MQTTv311, clean_session=clean_session)
mqttc.connect(host=mqtt_server, port=mqtt_port, keepalive=60)
MQTT V5.0 Version:
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2,
client_id=hostname, protocol=mqtt.MQTTv5)
properties = Properties(PacketTypes.CONNECT)
properties.SessionExpiryInterval = session_expiry_interval
mqttc.connect(host=mqtt_server, port=mqtt_port, keepalive=60,
clean_start=clean_start, properties=properties)