Skip to content

Commit 933b1cb

Browse files
committed
preserve sesion ID on reconnect
1 parent 8f4c421 commit 933b1cb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ def __init__( # noqa: PLR0915, PLR0913, Too many statements, Too many arguments
204204
if port:
205205
self.port = port
206206

207+
self.session_id = None
208+
207209
# define client identifier
208210
if client_id:
209211
# user-defined client_id MAY allow client_id's > 23 bytes or
@@ -528,6 +530,7 @@ def _connect( # noqa: PLR0912, PLR0913, PLR0915, Too many branches, Too many ar
528530
is_ssl=self._is_ssl,
529531
ssl_context=self._ssl_context,
530532
)
533+
self.session_id = session_id
531534
self._backwards_compatible_sock = not hasattr(self._sock, "recv_into")
532535

533536
fixed_header = bytearray([0x10])
@@ -946,7 +949,7 @@ def reconnect(self, resub_topics: bool = True) -> int:
946949
subscribed_topics = self._subscribed_topics.copy()
947950
self.disconnect()
948951

949-
ret = self.connect()
952+
ret = self.connect(session_id=self.session_id)
950953
self.logger.debug("Reconnected with broker")
951954

952955
if resub_topics and subscribed_topics:

0 commit comments

Comments
 (0)