mqtt开启监控消息,根据消息内容退出监控

场景:mqtt开启监控消息,根据消息内容退出监控

问题描述:mqtt的loop函数是整个on_message完全执行完成,才会真正on_pulish

二话不说,直接上代码

 

=========================================================
# 主程 thread_xxx = threading.Thread(target=run) thread_xxx.start() def run(self): while 1: self.client.loop() if STOP or client.flag == "xxx": break # client类 def on_message(self, client, userdata, msg): on_publish(topic, tmp, 1) msg_payload = "" # 当finish时,上一条不会执行, 假动作 ============================================================ client.loop_start() thread_xxx = threading.Thread(target=run) thread_xxx.start()
def run(self): while 1: if STOP or client.flag == "xxx": client.disconnect() break

  

posted @ 2021-10-09 14:18  fly_pig  阅读(177)  评论(0编辑  收藏  举报