fix: 记录掉线日志
This commit is contained in:
parent
0dbecbc439
commit
7741928edc
6
mqttc.py
6
mqttc.py
|
@ -92,13 +92,17 @@ def on_message(mqttc: mqtt.Client, userdata, msg: mqtt.MQTTMessage):
|
||||||
if topic == conf.MQTT_TOPIC:
|
if topic == conf.MQTT_TOPIC:
|
||||||
save_items(msg.payload)
|
save_items(msg.payload)
|
||||||
|
|
||||||
|
def on_disconnect(mqttc: mqtt.Client, userdata, rc):
|
||||||
|
logger.error("Disconnected from MQTT broker")
|
||||||
|
|
||||||
|
|
||||||
def start_mqtt():
|
def start_mqtt():
|
||||||
client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2, client_id='hfnf_105')
|
client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2, client_id='hfnf_105')
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
client.on_message = on_message
|
client.on_message = on_message
|
||||||
|
client.on_disconnect = on_disconnect
|
||||||
client.connect(host=conf.MQTT_HOST, port=conf.MQTT_PORT)
|
client.connect(host=conf.MQTT_HOST, port=conf.MQTT_PORT)
|
||||||
client.loop_forever()
|
client.loop_start()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue