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
|
from hbmqtt.client._client import MQTTClient
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
#
|
||||||
|
# This sample shows a client running idle.
|
||||||
|
# Meanwhile, keepalive is managed through PING messages sent every 5 seconds
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
|
@ -2,6 +2,13 @@ import logging
|
||||||
from hbmqtt.client._client import MQTTClient
|
from hbmqtt.client._client import MQTTClient
|
||||||
import asyncio
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
C = MQTTClient()
|
C = MQTTClient()
|
||||||
|
@ -9,12 +16,15 @@ C = MQTTClient()
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_coro():
|
def test_coro():
|
||||||
yield from C.connect(uri='mqtt://iot.eclipse.org:1883/', username=None, password=None)
|
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},
|
{'filter': '$SYS/broker/uptime', 'qos': 0x01},
|
||||||
])
|
])
|
||||||
logger.info("Subscribed")
|
logger.info("Subscribed")
|
||||||
logger.info(repr(ret))
|
for i in range (1,10):
|
||||||
yield from asyncio.sleep(10)
|
ret = yield from C.deliver_message()
|
||||||
|
data = ret.packet.payload.data
|
||||||
|
logger.info(str(data))
|
||||||
yield from C.unsubscribe(['$SYS/broker/uptime'])
|
yield from C.unsubscribe(['$SYS/broker/uptime'])
|
||||||
logger.info("UnSubscribed")
|
logger.info("UnSubscribed")
|
||||||
yield from C.disconnect()
|
yield from C.disconnect()
|
||||||
|
@ -22,5 +32,5 @@ def test_coro():
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
formatter = "[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s"
|
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())
|
asyncio.get_event_loop().run_until_complete(test_coro())
|
Ładowanie…
Reference in New Issue