sbtinstruments / aiomqtt

The idiomatic asyncio MQTT client, wrapped around paho-mqtt
https://sbtinstruments.github.io/aiomqtt
BSD 3-Clause "New" or "Revised" License
393 stars 71 forks source link

How can I set the value of session_expiry_interval for a client? #233

Closed YraganTron closed 11 months ago

frederikaalund commented 11 months ago

Hi Arseny, and thank you for opening this issue. :)

You can use the properties argument for Client.__init__ like so:

from aiomqtt import Client
from paho.mqtt.properties import Properties
from paho.mqtt.packettypes import PacketTypes

properties = Properties(PacketTypes.CONNECT)
properties.SessionExpiryInterval = 1234
client = aiomqtt.Client(..., properties=properties)

Note that I did not run the code above. There may be typos or the like.

The current API for MQTTv5 properties is admittedly pretty awkward to use. It's a great place to make a PR and improve this situation. :+1:

I hope this helps!