-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove QoS 1 and 2 support as they didn't work. Client persistent sta…
…te is needed. Added session resume functionality.
- Loading branch information
Showing
15 changed files
with
138 additions
and
675 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import asyncio | ||
import mqttools | ||
from uuid import uuid1 | ||
|
||
|
||
async def resume_session(): | ||
client = mqttools.Client('broker.hivemq.com', | ||
1883, | ||
client_id='mqttools-{}'.format(uuid1().node), | ||
session_expiry_interval=15) | ||
|
||
try: | ||
await client.start(resume_session=True) | ||
print('Session resumed.') | ||
except mqttools.SessionResumeError: | ||
print('No session to resume. Subscribing to topics.') | ||
|
||
# Subscribe to three topics in parallel. | ||
print('Subscribing to topics.') | ||
await asyncio.gather( | ||
client.subscribe('$SYS/#'), | ||
client.subscribe('/test/mqttools/foo') | ||
) | ||
|
||
print('Waiting for messages.') | ||
|
||
while True: | ||
topic, message = await client.messages.get() | ||
|
||
if topic is None: | ||
print('Broker connection lost!') | ||
break | ||
|
||
print(f'Topic: {topic}') | ||
print(f'Message: {message}') | ||
|
||
import logging | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
asyncio.run(resume_session()) |
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
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
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
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
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
Oops, something went wrong.