2015-07-05 13:53:02 +00:00
|
|
|
import asyncio
|
2024-12-19 19:34:09 +00:00
|
|
|
import logging
|
2015-07-05 13:53:02 +00:00
|
|
|
|
2021-03-27 12:59:48 +00:00
|
|
|
from amqtt.client import MQTTClient
|
2015-07-07 19:55:17 +00:00
|
|
|
|
2015-07-06 20:20:05 +00:00
|
|
|
#
|
|
|
|
# This sample shows a client running idle.
|
|
|
|
# Meanwhile, keepalive is managed through PING messages sent every 5 seconds
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2015-07-05 13:53:02 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
config = {
|
2021-03-14 21:16:51 +00:00
|
|
|
"keep_alive": 5,
|
|
|
|
"ping_delay": 1,
|
2015-07-05 13:53:02 +00:00
|
|
|
}
|
|
|
|
C = MQTTClient(config=config)
|
|
|
|
|
2017-08-06 22:06:57 +00:00
|
|
|
|
2024-12-19 19:34:09 +00:00
|
|
|
async def test_coro() -> None:
|
2021-03-14 21:16:51 +00:00
|
|
|
await C.connect("mqtt://test.mosquitto.org:1883/")
|
2020-12-31 00:16:45 +00:00
|
|
|
await asyncio.sleep(18)
|
2015-07-05 13:53:02 +00:00
|
|
|
|
2020-12-31 00:16:45 +00:00
|
|
|
await C.disconnect()
|
2015-07-05 13:53:02 +00:00
|
|
|
|
|
|
|
|
2021-03-14 21:16:51 +00:00
|
|
|
if __name__ == "__main__":
|
2015-07-05 13:53:02 +00:00
|
|
|
formatter = "[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s"
|
|
|
|
logging.basicConfig(level=logging.DEBUG, format=formatter)
|
2017-08-06 22:06:57 +00:00
|
|
|
asyncio.get_event_loop().run_until_complete(test_coro())
|