File: client_keepalive.py

package info (click to toggle)
amqtt 0.11.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,660 kB
  • sloc: python: 14,565; sh: 42; makefile: 34; javascript: 27
file content (39 lines) | stat: -rw-r--r-- 748 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import asyncio
from asyncio import CancelledError
import logging

from amqtt.client import MQTTClient

"""
This sample shows how to run an idle client
"""

logger = logging.getLogger(__name__)

config = {
    "keep_alive": 5,
    "ping_delay": 1,
}

async def main() -> None:
    client = MQTTClient(config=config)

    try:
        await client.connect("mqtt://localhost:1883/")
        logger.info("client connected")
        await asyncio.sleep(15)
    except CancelledError:
        pass

    await client.disconnect()


def __main__():

    formatter = "[%(asctime)s] :: %(levelname)s :: %(name)s :: %(message)s"
    logging.basicConfig(level=logging.INFO, format=formatter)
    asyncio.run(main())


if __name__ == "__main__":
    __main__()