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.2.0.tar.gz
(6.9 kB
view hashes)
Built Distribution
Close
Hashes for mqttools-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88cf1a56dc6a3d74da5c45c79a839a0adc143de726c87173c592c4dc7483fdc5 |
|
MD5 | db2f2a543021402453f8664dc7ab821f |
|
BLAKE2b-256 | 7aac2460b19dbed0c243648f34a74d1356b0df770016bde84990db8c5b4079d9 |