Commit 2507539a authored by 957dd's avatar 957dd

update mqtt

parent b8278eba
No preview for this file type
...@@ -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);
......
...@@ -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" // 替换为你的密码
......
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