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: b'11'
Topic: /test/mqttools/foo
Message: b'bar'
Publish
Connect to given MQTT broker and publish a message to a topic.
$ mqttools publish /test/mqttools/foo bar
Topic: /test/mqttools/foo
Message: b'bar'
QoS: 0
Monitor
Connect to given MQTT broker and monitor given topics in a text based user interface.
$ mqttools monitor --subscribe /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, 'mqttools-subscribe')
await client.start()
await client.subscribe('/test/#', 0)
while True:
topic, message = await client.messages.get()
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, 'mqttools-publish')
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
Hashes for mqttools-0.6.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c46350e1aec25276cbb351a6e9c12d8bcb016a861b20ec92e2d9720ca5021424 |
|
MD5 | 03f536b39ebf34da998dde6036934b0b |
|
BLAKE2b-256 | cfef00a51343f9acb601dd965ac0f8c54a6da2f0fe13af95aa2add8d762e30c4 |