Browse Source

优化mqtt断网重连无法订阅mqtt消息的问题

james 1 year ago
parent
commit
9289123834
1 changed files with 3 additions and 1 deletions
  1. 3 1
      ytDataWriteProcess/mqttdatathread.cpp

+ 3 - 1
ytDataWriteProcess/mqttdatathread.cpp

@@ -32,7 +32,9 @@ void MqttDataThread::mqtt_conf(QString ip,QString port,QString username,QString
     m_client = new QMQTT::Client(QHostAddress(mqtt_ip),static_cast<quint16>(mqtt_port.toInt()),this);
     m_client->setUsername(mqtt_username);
     m_client->setPassword(mqtt_passwd.toLatin1());
-    m_client->setCleanSession(true);
+    m_client->setCleanSession(false);
+    m_client->setAutoReconnect(true);
+    m_client->setAutoReconnectInterval(60000);
     connect(m_client,&QMQTT::Client::connected,this,&MqttDataThread::onConnected);
     connect(m_client,&QMQTT::Client::received,this,&MqttDataThread::onReceived);
     m_client->connectToHost();