Commit c2d3e63e by 郭峰

Merge branch 'feature/mqtt-feature' into 'release'

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

See merge request !16
parents 3410b843 8a850c09
...@@ -44,7 +44,7 @@ MqttSubscriber::~MqttSubscriber() { ...@@ -44,7 +44,7 @@ MqttSubscriber::~MqttSubscriber() {
MQTTAsync_destroy(&client); MQTTAsync_destroy(&client);
instance = nullptr; instance = nullptr;
} }
s
void MqttSubscriber::start() { void MqttSubscriber::start() {
retryTimer->stop(); // 确保每次开始连接前停止定时器 retryTimer->stop(); // 确保每次开始连接前停止定时器
MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer; MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;
...@@ -95,7 +95,6 @@ void MqttSubscriber::onConnect(MQTTAsync_successData* response) { ...@@ -95,7 +95,6 @@ void MqttSubscriber::onConnect(MQTTAsync_successData* response) {
void MqttSubscriber::reconnectAndFetchConfig() { void MqttSubscriber::reconnectAndFetchConfig() {
Common & instace= Common::getInstance(); Common & instace= Common::getInstance();
vides_data::responseConfig re_config; vides_data::responseConfig re_config;
// 使用 HttpService 从远程云端拉取配置 // 使用 HttpService 从远程云端拉取配置
HttpService httpService(httpUrl); // 替换为实际的远程URL HttpService httpService(httpUrl); // 替换为实际的远程URL
...@@ -106,7 +105,7 @@ void MqttSubscriber::reconnectAndFetchConfig() { ...@@ -106,7 +105,7 @@ void MqttSubscriber::reconnectAndFetchConfig() {
QString topic = QStringLiteral("/thingshub/%1/device/reply").arg(serialNumber); QString topic = QStringLiteral("/thingshub/%1/device/reply").arg(serialNumber);
re_config.mqttConfig.topic=topic; re_config.mqttConfig.topic=topic;
this->config=re_config.mqttConfig; this->config=re_config.mqttConfig;
init(re_config.mqttConfig,httpUrl,serialNumber); this->init(re_config.mqttConfig,httpUrl,serialNumber);
start(); start();
} else { } else {
qInfo() << "配置拉取失败,等待10秒后重试"; qInfo() << "配置拉取失败,等待10秒后重试";
......
...@@ -129,6 +129,7 @@ MainWindow::MainWindow() ...@@ -129,6 +129,7 @@ MainWindow::MainWindow()
config.mqttConfig.clientId=serialNumber; config.mqttConfig.clientId=serialNumber;
QString topic = QStringLiteral("/thingshub/%1/device/reply").arg(serialNumber); QString topic = QStringLiteral("/thingshub/%1/device/reply").arg(serialNumber);
config.mqttConfig.topic=topic; config.mqttConfig.topic=topic;
this->mqttConfig= config.mqttConfig; this->mqttConfig= config.mqttConfig;
runOrRebootMqtt(mqttConfig,httpurl,serialNumber); 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