Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
IoT: Internet of Things
server :
# tool:
pip3 install hbmqtt # 0.9.5
hbmqtt_pub --url mqtt:// -t "/scratch3_sub" -m "hello from hbmqtt_pub"
hbmqtt_sub --url mqtt:// -t "/scratch3_pub"
import logging
import asyncio
from hbmqtt.client import MQTTClient, ClientException
from hbmqtt.mqtt.constants import QOS_0
username = "guest"
password = "test"
mqtt_url = "mqtt://{}:{}".format(username, password)
async def uptime_coro():
C = MQTTClient() # clientid?
await C.connect(mqtt_url)
# Subscribe to '$SYS/broker/uptime' with QOS=1
# Subscribe to '$SYS/broker/load/#' with QOS=2
await C.subscribe([
('/scratch3_pub', QOS_0),
while True:
message = await C.deliver_message()
topic = message.topic
payload =
print("%s => %s" % (topic, payload))
await C.unsubscribe(['/scratch3_sub'])
await C.disconnect()
except ClientException as ce:
logging.error("Client exception: %s" % ce)
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment