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
0815616d
Commit
0815616d
authored
Sep 28, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改了阻塞等待事件,可以让mqtt服务器增多
parent
47699a2f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
3 additions
and
33 deletions
+3
-33
.Deviceld.txt.swp
.Deviceld.txt.swp
+0
-0
CMakeLists.txt
CMakeLists.txt
+1
-1
version.h
build/include/version.h
+1
-1
main
build/main
+0
-0
mqtt_init.c
modules/mqtt/mqtt_init.c
+1
-31
No files found.
.Deviceld.txt.swp
0 → 100644
View file @
0815616d
File added
CMakeLists.txt
View file @
0815616d
cmake_minimum_required
(
VERSION 3.10
)
project
(
car
VERSION 1.2.1
3
VERSION 1.2.1
4
LANGUAGES C
)
...
...
build/include/version.h
View file @
0815616d
#define PROJECT_VERSION_MAJOR 1
#define PROJECT_VERSION_MINOR 2
#define PROJECT_VERSION_PATCH 1
3
#define PROJECT_VERSION_PATCH 1
4
#define GIT_HASH ""
#define BUILD_TIMESTAMP ""
#define BUILD_USER ""
build/main
View file @
0815616d
No preview for this file type
modules/mqtt/mqtt_init.c
View file @
0815616d
...
...
@@ -30,9 +30,6 @@ int mqtt_init() {
my_zlog_error
(
"Failed to create Mosquitto client"
);
return
-
1
;
}
//mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
//mosquitto_int_option(mosq1, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
//mosquitto_int_option(mosq2, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
return
0
;
}
...
...
@@ -87,22 +84,6 @@ void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_messag
}
}
// 返回连接结果,0成功,非0失败,单个使用函数
// int mqtt_create(struct mosquitto *mosq) {
// mosquitto_reconnect_delay_set(mosq, 2, 10, true);
// mosquitto_connect_callback_set(mosq, on_connect);
// mosquitto_message_callback_set(mosq, on_message);
// mosquitto_username_pw_set(mosq, USERNAME, PASSWORD);
// int rc = mosquitto_connect(mosq, BROKER_ADDRESS, BROKER_PORT, 60);
// if (rc != MOSQ_ERR_SUCCESS) {
// my_zlog_warn("Failed to connect to broker: %s", mosquitto_strerror(rc));
// // 不销毁 mosq,等待调用者处理重连
// return rc;
// }
// return 0; // 成功
// }
int
add_mqtt_create
(
const
char
*
host
,
int
port
,
int
clients_count
){
static
int
uuid_index
=
0
;
...
...
@@ -152,16 +133,6 @@ int add_mqtt_create(const char *host, int port, int clients_count){
return
0
;
}
//阻塞型
// int mqtt_cycle(struct mosquitto *mosq) {
// // 这个函数会阻塞直到连接断开或错误返回
// int rc = mosquitto_loop_forever(mosq, -1, 1);
// if (rc != MOSQ_ERR_SUCCESS) {
// my_zlog_warn("mqtt loop error: %s", mosquitto_strerror(rc));
// return rc;
// }
// }
//mqtt清理
void
mqtt_clean
(){
// 清理
...
...
@@ -177,7 +148,7 @@ void mqtt_clean(){
int
mqtt_cycle
()
{
//非阻塞型
while
(
1
)
{
for
(
int
i
=
0
;
i
<
g_mqtt_cam_config_t
->
mqtt_count
;
i
++
){
int
rc
=
mosquitto_loop
(
g_clients_t
[
i
].
mosq
,
1
00
,
1
);
// 每秒检查一次
int
rc
=
mosquitto_loop
(
g_clients_t
[
i
].
mosq
,
1
7
,
1
);
// 每秒检查一次
if
(
rc
!=
MOSQ_ERR_SUCCESS
){
my_zlog_warn
(
"服务器 %s:%d 断开,尝试重连..."
,
g_clients_t
[
i
].
host
,
g_clients_t
[
i
].
port
);
...
...
@@ -185,7 +156,6 @@ int mqtt_cycle() {//非阻塞型
}
}
delay_ms
(
300
);
// 防止空转
}
return
0
;
...
...
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