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
2507539a
Commit
2507539a
authored
Dec 25, 2024
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update mqtt
parent
b8278eba
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
4 deletions
+6
-4
main
main
+0
-0
mqtt.c
mqtt.c
+3
-2
mqtt.h
mqtt.h
+3
-2
No files found.
main
View file @
2507539a
No preview for this file type
mqtt.c
View file @
2507539a
...
@@ -19,6 +19,7 @@ unsigned char gvalt[4];
...
@@ -19,6 +19,7 @@ unsigned char gvalt[4];
void
on_connect
(
struct
mosquitto
*
mosq
,
void
*
obj
,
int
rc
)
//回调函数
void
on_connect
(
struct
mosquitto
*
mosq
,
void
*
obj
,
int
rc
)
//回调函数
{
{
if
(
rc
==
0
)
if
(
rc
==
0
)
{
{
printf
(
"Connected to broker
\n
"
);
printf
(
"Connected to broker
\n
"
);
...
@@ -84,7 +85,7 @@ void mqtt_wirte()
...
@@ -84,7 +85,7 @@ void mqtt_wirte()
printf
(
"%s
\n
"
,
payload
);
printf
(
"%s
\n
"
,
payload
);
mosquitto_publish
(
mosq
,
NULL
,
TOPIC2
,
strlen
(
payload
),
payload
,
0
,
false
);
mosquitto_publish
(
mosq
,
NULL
,
TOPIC2
,
strlen
(
payload
),
payload
,
0
,
false
);
mosquitto_publish
(
mosq
,
NULL
,
TOPIC3
,
strlen
(
payload
),
payload
,
0
,
false
);
}
}
...
@@ -282,7 +283,7 @@ void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_messag
...
@@ -282,7 +283,7 @@ void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_messag
int
mqtt_create
(
struct
mosquitto
*
mosq
)
//创建mqtt客服端
int
mqtt_create
(
struct
mosquitto
*
mosq
)
//创建mqtt客服端
{
{
mosquitto_reconnect_delay_set
(
mosq
,
2
,
10
,
true
);
// 设置连接和消息回调
// 设置连接和消息回调
mosquitto_connect_callback_set
(
mosq
,
on_connect
);
mosquitto_connect_callback_set
(
mosq
,
on_connect
);
mosquitto_message_callback_set
(
mosq
,
on_message
);
mosquitto_message_callback_set
(
mosq
,
on_message
);
...
...
mqtt.h
View file @
2507539a
...
@@ -13,8 +13,9 @@
...
@@ -13,8 +13,9 @@
#define BROKER_ADDRESS "119.45.167.177"
#define BROKER_ADDRESS "119.45.167.177"
#define BROKER_PORT 1883
#define BROKER_PORT 1883
#define TOPIC "IEP/controlcar0001"
#define TOPIC "app2dev/controlcar0001"
#define TOPIC2 "IEQ/controlcar0001"
#define TOPIC2 "dev2app/controlcar0001"
#define TOPIC3 "dev2ser"
#define USERNAME "admin" // 替换为你的用户名
#define USERNAME "admin" // 替换为你的用户名
#define PASSWORD "admin" // 替换为你的密码
#define PASSWORD "admin" // 替换为你的密码
...
...
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