Commit 7eae9e10 authored by 黄振令's avatar 黄振令

【修改内容】mqtt的clientid使用kk_mac地址组合,保证唯一性

parent 0d6f9397
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#define MQTT_CONF_H_ #define MQTT_CONF_H_
#define ADDRESS "tcp://172.25.240.31:1983" #define ADDRESS "tcp://172.25.240.31:1983"
#define CLIENTID "1234" #define CLIENTID "kk_%s"
#define TOPIC "/sys/a1OYuSBt23u/aIqEbWno8yDdsjCX15iq/thing/service/property/set" #define TOPIC "/sys/a1OYuSBt23u/aIqEbWno8yDdsjCX15iq/thing/service/property/set"
#define PAYLOAD "Hello cwc World!" #define PAYLOAD "Hello cwc World!"
......
...@@ -193,7 +193,11 @@ MQTTAsync KK_MQTT_Connect(void) ...@@ -193,7 +193,11 @@ MQTTAsync KK_MQTT_Connect(void)
MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer; MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;
MQTTAsync_setTraceCallback(mqttTraceCallback); MQTTAsync_setTraceCallback(mqttTraceCallback);
opts.MQTTVersion = MQTTVERSION_3_1_1; opts.MQTTVersion = MQTTVERSION_3_1_1;
if ((rc = MQTTAsync_createWithOptions(&s_Client, ADDRESS, CLIENTID, MQTTCLIENT_PERSISTENCE_NONE, NULL,&opts)) != MQTTASYNC_SUCCESS) char mac[16]={0};
char clientBuf[20] = {0};
HAL_Get_mac(mac);
sprintf(clientBuf, CLIENTID, mac);
if ((rc = MQTTAsync_createWithOptions(&s_Client, ADDRESS, clientBuf, MQTTCLIENT_PERSISTENCE_NONE, NULL,&opts)) != MQTTASYNC_SUCCESS)
{ {
ERROR_PRINT("Failed to create client object, return code %d\n", rc); ERROR_PRINT("Failed to create client object, return code %d\n", rc);
return NULL; return NULL;
......
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