Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gamera_videos_no_ui
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liusq
gamera_videos_no_ui
Commits
2e9ea28b
Commit
2e9ea28b
authored
Sep 09, 2024
by
郭峰
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/mqtt-feature' into 'release'
mqtt断线重连,配置修改重新创建连接02 See merge request
!17
parents
c2d3e63e
a9aefd69
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
MqttSubscriber.cpp
+4
-3
No files found.
MqttSubscriber.cpp
View file @
2e9ea28b
...
@@ -30,21 +30,21 @@ void MqttSubscriber::init(vides_data::MqttConfig &config,QString &httpUrl,QStrin
...
@@ -30,21 +30,21 @@ void MqttSubscriber::init(vides_data::MqttConfig &config,QString &httpUrl,QStrin
},
nullptr
);
},
nullptr
);
// 连接信号和槽
// 连接信号和槽
connect
(
this
,
&
MqttSubscriber
::
connectionLostSignal
,
this
,
&
MqttSubscriber
::
reconnectAndFetchConfig
);
connect
(
this
,
&
MqttSubscriber
::
connectionLostSignal
,
this
,
&
MqttSubscriber
::
reconnectAndFetchConfig
,
Qt
::
QueuedConnection
);
}
}
MqttSubscriber
::
MqttSubscriber
(
QObject
*
parent
)
MqttSubscriber
::
MqttSubscriber
(
QObject
*
parent
)
:
QObject
(
parent
),
retryTimer
(
new
QTimer
(
this
))
{
:
QObject
(
parent
),
retryTimer
(
new
QTimer
(
this
))
{
retryTimer
->
setInterval
(
10000
);
// 设置重试间隔为10秒
retryTimer
->
setInterval
(
10000
);
// 设置重试间隔为10秒
retryTimer
->
setSingleShot
(
true
);
// 单次触发
retryTimer
->
setSingleShot
(
true
);
// 单次触发
connect
(
retryTimer
,
&
QTimer
::
timeout
,
this
,
&
MqttSubscriber
::
reconnectAndFetchConfig
);
connect
(
retryTimer
,
&
QTimer
::
timeout
,
this
,
&
MqttSubscriber
::
reconnectAndFetchConfig
,
Qt
::
QueuedConnection
);
}
}
MqttSubscriber
::~
MqttSubscriber
()
{
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
;
...
@@ -94,6 +94,7 @@ void MqttSubscriber::onConnect(MQTTAsync_successData* response) {
...
@@ -94,6 +94,7 @@ void MqttSubscriber::onConnect(MQTTAsync_successData* response) {
}
}
void
MqttSubscriber
::
reconnectAndFetchConfig
()
{
void
MqttSubscriber
::
reconnectAndFetchConfig
()
{
qInfo
()
<<
"重新连接并获取配置 "
;
Common
&
instace
=
Common
::
getInstance
();
Common
&
instace
=
Common
::
getInstance
();
vides_data
::
responseConfig
re_config
;
vides_data
::
responseConfig
re_config
;
// 使用 HttpService 从远程云端拉取配置
// 使用 HttpService 从远程云端拉取配置
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment