MQTT tools.
Project description
MQTT Tools
Requires Python 3.7 or later!
NOTE: This project is far from complete. Lots of MQTT features are not implemented yet, and those implemented are probably buggy.
Features:
asyncio MQTT 5.0 client (under development).
MQTT 5.0 specification: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html
Examples
Command line
Subscribe
Connect to given MQTT broker and subscribe to a topic. All received messages are printed to standard output.
$ mqttools subscribe /test/#
Topic: /test
Message: 11
Topic: /test/mqttools/foo
Message: bar
Publish
Connect to given MQTT broker and publish a message to a topic.
$ mqttools publish /test/mqttools/foo bar
Published 1 message(s) in 0 seconds from 1 concurrent task(s).
Publish multiple messages as quickly as possible with --count to benchmark the client and the broker.
$ mqttools publish --count 100 --qos 1 /test/mqttools/foo
Published 100 message(s) in 0.39 seconds from 10 concurrent task(s).
Monitor
Connect to given MQTT broker and monitor given topics in a text based user interface.
$ mqttools monitor /test/#
The menu at the bottom of the monitor shows the available commands.
Quit: Quit the monitor. Ctrl-C can be used as well.
Play/Pause: Toggle between playing and paused (or running and freezed).
Scripting
Subscribe
An example connecting to an MQTT broker, subscribing to the topic /test/#, and printing all published messaged.
import asyncio
import mqttools
async def subscriber():
client = mqttools.Client('broker.hivemq.com', 1883)
await client.start()
await client.subscribe('/test/#', 0)
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}')
asyncio.run(subscriber())
Publish
An example connecting to an MQTT broker and publishing the message bar to the topic /test/mqttools/foo.
import asyncio
import mqttools
async def publisher():
client = mqttools.Client('broker.hivemq.com', 1883)
await client.start()
await client.publish('/test/mqttools/foo', b'bar', 0)
await client.stop()
asyncio.run(publisher())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mqttools-0.11.0.tar.gz
.
File metadata
- Download URL: mqttools-0.11.0.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ea9f6fd2d1206e6c6f2115ae740ad3ad0c1e982a1d15722dfa1e8e6a80ee802 |
|
MD5 | e2cd2d5b057c22ab53618d192a931878 |
|
BLAKE2b-256 | bf9c9e3f8db15d2be0d474f2f55875e9781185f1fc3995716d8087fee4b82946 |
Provenance
File details
Details for the file mqttools-0.11.0-py2.py3-none-any.whl
.
File metadata
- Download URL: mqttools-0.11.0-py2.py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fab743a8912c2602928ef94d63f31920d47eb9f59bd9e002e7efe3cd232cfbc |
|
MD5 | c9985fa6b44026e2bb16577df1a938e0 |
|
BLAKE2b-256 | a275c6c4ec9688df5318146123a9ccc70305aa3c80c5fa97940ce3740e31626b |