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.
评论列表
文章目录