kopia lustrzana https://github.com/Yakifo/amqtt
HBMQTT-5
rodzic
1692141375
commit
c513da75e9
|
@ -2,6 +2,12 @@ import logging
|
|||
from hbmqtt.client._client import MQTTClient
|
||||
import asyncio
|
||||
|
||||
#
|
||||
# This sample shows a client running idle.
|
||||
# Meanwhile, keepalive is managed through PING messages sent every 5 seconds
|
||||
#
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
config = {
|
||||
|
|
|
@ -2,6 +2,13 @@ import logging
|
|||
from hbmqtt.client._client import MQTTClient
|
||||
import asyncio
|
||||
|
||||
|
||||
#
|
||||
# This sample shows how to subscbribe a topic and receive data from incoming messages
|
||||
# It subscribes to '$SYS/broker/uptime' topic and displays the first ten values returned
|
||||
# by the broker.
|
||||
#
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
C = MQTTClient()
|
||||
|
@ -9,12 +16,15 @@ C = MQTTClient()
|
|||
@asyncio.coroutine
|
||||
def test_coro():
|
||||
yield from C.connect(uri='mqtt://iot.eclipse.org:1883/', username=None, password=None)
|
||||
ret = yield from C.subscribe([
|
||||
# Subscribe to '$SYS/broker/uptime' with QOS=1
|
||||
yield from C.subscribe([
|
||||
{'filter': '$SYS/broker/uptime', 'qos': 0x01},
|
||||
])
|
||||
logger.info("Subscribed")
|
||||
logger.info(repr(ret))
|
||||
yield from asyncio.sleep(10)
|
||||
for i in range (1,10):
|
||||
ret = yield from C.deliver_message()
|
||||
data = ret.packet.payload.data
|
||||
logger.info(str(data))
|
||||
yield from C.unsubscribe(['$SYS/broker/uptime'])
|
||||
logger.info("UnSubscribed")
|
||||
yield from C.disconnect()
|
||||
|
@ -22,5 +32,5 @@ def test_coro():
|
|||
|
||||
if __name__ == '__main__':
|
||||
formatter = "[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s"
|
||||
logging.basicConfig(level=logging.DEBUG, format=formatter)
|
||||
logging.basicConfig(level=logging.INFO, format=formatter)
|
||||
asyncio.get_event_loop().run_until_complete(test_coro())
|
Ładowanie…
Reference in New Issue