MQTT tools.
Project description
MQTT Tools
Requires Python 3.7 or later!
Features:
asyncio MQTT client.
Examples
Command line
Subscribe
An example connecting to an MQTT broker, subscribing to the topic /test/#, and printing all published messaged.
$ mqttools subscribe /test/#
Topic: b'/test'
Message: b'11'
Topic: b'/test/mqttools/foo'
Message: b'bar'
Publish
An example connecting to an MQTT broker and publishing the message bar to the topic /test/mqttools/foo.
$ mqttools publish /test/mqttools/foo bar
Topic: b'/test/mqttools/foo'
Message: b'bar'
QoS: 0
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('test.mosquitto.org', 1883, b'mqttools-subscribe')
await client.start()
await client.subscribe(b'/test/#', 0)
while True:
topic, message = await client.messages.get()
print(f'Topic: {topic}')
print(f'Message: {message}')
print()
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('test.mosquitto.org', 1883, b'mqttools-publish')
await client.start()
await client.publish(b'/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
mqttools-0.3.0.tar.gz
(6.9 kB
view hashes)
Built Distribution
Close
Hashes for mqttools-0.3.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa7287a0ebd606bcf2de8f67aa5169b92577326bece65692e8a17f9bbbcecaab |
|
MD5 | fad6b84b7e9ee4724592610f1b3d2809 |
|
BLAKE2b-256 | 8f7069d0c45f51b4708affe9851531ef8513e01667c3baebf0dc012aa9c1ffa7 |