mqtt_app.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:sdk-samples 作者: cradlepoint 项目源码 文件源码
def on_connect(client, userdata, flags, rc):
    log.debug("MQTT Client connection results: {}".format(mqtt.connack_string(rc)))

    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    # QOS 0: The broker will deliver the message once, with no confirmation.
    # QOS 1: The broker will deliver the message at least once, with confirmation required.
    # QOS 2: The broker will deliver the message exactly once by using a four step handshake.
    #
    # A list of tuples (i.e. topic, qos). Both topic and qos must be present in the tuple.
    topics = [(settings.GPS_TOPIC, 2),
              (settings.MODEM_TEMP_TOPIC, 1),
              (settings.WAN_CONNECTION_STATE_TOPIC, 0)]
    try:
        client.subscribe(topics)
    except Exception as ex:
        log.error('Client Subscribe exception. ex={}'.format(ex))


# Called when a message has been received on a topic that the client subscribes
# to and the message does not match an existing topic filter callback. Use
# message_callback_add() to define a callback that will be called for specific
# topic filters. on_message will serve as fallback when none matched.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号