Commit 8a850c09 by “liusq”

mqtt断线重连,配置修改重新创建连接01

parent 1716236d
......@@ -44,7 +44,7 @@ MqttSubscriber::~MqttSubscriber() {
MQTTAsync_destroy(&client);
instance = nullptr;
}
s
void MqttSubscriber::start() {
retryTimer->stop(); // 确保每次开始连接前停止定时器
MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;
......@@ -95,7 +95,6 @@ void MqttSubscriber::onConnect(MQTTAsync_successData* response) {
void MqttSubscriber::reconnectAndFetchConfig() {
Common & instace= Common::getInstance();
vides_data::responseConfig re_config;
// 使用 HttpService 从远程云端拉取配置
HttpService httpService(httpUrl); // 替换为实际的远程URL
......@@ -106,7 +105,7 @@ void MqttSubscriber::reconnectAndFetchConfig() {
QString topic = QStringLiteral("/thingshub/%1/device/reply").arg(serialNumber);
re_config.mqttConfig.topic=topic;
this->config=re_config.mqttConfig;
init(re_config.mqttConfig,httpUrl,serialNumber);
this->init(re_config.mqttConfig,httpUrl,serialNumber);
start();
} else {
qInfo() << "配置拉取失败,等待10秒后重试";
......
......@@ -129,6 +129,7 @@ MainWindow::MainWindow()
config.mqttConfig.clientId=serialNumber;
QString topic = QStringLiteral("/thingshub/%1/device/reply").arg(serialNumber);
config.mqttConfig.topic=topic;
this->mqttConfig= config.mqttConfig;
runOrRebootMqtt(mqttConfig,httpurl,serialNumber);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment