Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-controlserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenzhongjian
car-controlserver
Commits
6d50e9e8
Commit
6d50e9e8
authored
Oct 11, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化了mqtt的问题,使用了异步检查重连机制,并且添加了重连10次将不会重连
parent
05e5f38d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
3 deletions
+19
-3
pthread_open.c
app/main/pthread_open.c
+11
-3
main
build/main
+0
-0
mqtt_init.c
modules/mqtt/mqtt_init.c
+0
-0
mqtt_init.h
modules/mqtt/mqtt_init.h
+8
-0
No files found.
app/main/pthread_open.c
View file @
6d50e9e8
...
...
@@ -116,12 +116,20 @@ void *thread_open_browser(void *arg) {
void
*
thread_mqtt_reconnect
(
void
*
arg
)
{
while
(
1
){
if
(
mqtt_init
()
==
0
){
my_zlog_warn
(
"mqtt success"
);
static
int
reconnect_count
=
0
;
static
int
remqtt_index
;
remqtt_index
=
mqtt_init
();
if
(
remqtt_index
==
0
){
my_zlog_warn
(
"mqtt success"
,
remqtt_index
);
break
;
}
else
{
my_zlog_warn
(
"wait... mqtt reconect
"
);
my_zlog_warn
(
"wait... mqtt reconect
,error:%d"
,
remqtt_index
);
delay_ms
(
300
);
reconnect_count
++
;
if
(
reconnect_count
>
MAX_RECONNECT_ATTEMPTS
){
send_fail_mqtt_conect
();
break
;
}
continue
;
}
}
...
...
build/main
View file @
6d50e9e8
No preview for this file type
modules/mqtt/mqtt_init.c
View file @
6d50e9e8
This diff is collapsed.
Click to expand it.
modules/mqtt/mqtt_init.h
View file @
6d50e9e8
...
...
@@ -8,11 +8,15 @@
#define MAX_SERVERS 10
#define MAX_RECONNECT_ATTEMPTS 10
typedef
struct
{
struct
mosquitto
*
mosq
;
char
host
[
128
];
int
port
;
char
client_id
[
64
];
int
reconnect_attempts
;
// 新增:重连尝试次数
bool
permanently_failed
;
// 新增:标记是否永久失败
}
mqttclient
;
extern
mqttclient
g_clients_t
[
MAX_SERVERS
];
...
...
@@ -34,4 +38,7 @@ int mqtt_cycle();//循环
//mqtt清理
void
mqtt_clean
();
//莫一个服务器连接失败发送
void
send_fail_mqtt_conect
();
#endif
\ No newline at end of file
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