我使用umqtt需要断开重连,按照官方的实例写的listen函数专门用来处理waitmsg,结果只要我断开重连,并且重启listen函数之后waitmsg就会收不到消息
def run(self):
if self.get_connect_state() == 0:
print("Mqtt connect server")
self.connect()
if self.thread_id == None:
print("Mqtt listen run")
self.listen()
def stop(self):
if self.thread_id != None:
print("stop listen")
_thread.stop_thread(self.thread_id)
self.thread_id = None
if self.get_connect_state() == 1:
try:
print("mqtt close connect")
self.connect_state = 0
self.cli.close()
return True
except Exception as e:
print("disconnect failed:", e)
return False
def listen_thread_worker(self):#这是waitmsg线程,线程栈按照文档建议给的16*1024
while True:
try:
if (self.connect_state != 0):
self.cli.wait_msg()
else:
utime.sleep_ms(10)
continue
except Exception as e:
self.put_error(error.ListenError())
if(self.connect_state != 0):
self.cli.close()
self.connect()
def recv(self):
return self.queue.get()
这是我的代码,望大佬指教
芯片型号EC600U