Commit 3cb8ced4 authored by 黄振令's avatar 黄振令

【修改要点】冲突解决

【提交人】黄振令
parent b951d6a6
......@@ -4,7 +4,7 @@
#define ADDRESS "tcp://172.25.240.31:1983"
#define CLIENTID "1234"
#define TOPIC "/sys/a1OYuSBt23u/aIqEbWno8yDdsjCX15iq/#"
#define TOPIC "/sys/a1OYuSBt23u/aIqEbWno8yDdsjCX15iq/thing/service/property/set"
#define PAYLOAD "Hello cwc World!"
#define QOS 2
......
......@@ -67,7 +67,7 @@ int main(int argc, char* argv[])
/*set the callback to get the device date to cloud*/
HAL_SetProduct_Type(PRODUCT_TPYE);
HAL_SetProduct_Code(PRODUCT_CODE);
kk_ipc_init(IPC_APP2MID,KK_Sendto_CloudData);
kk_ipc_init(IPC_APP2MID,KK_Data_FromDev);
rc = mqtt_start();
return rc;
......
......@@ -3,11 +3,46 @@
#include <stdlib.h>
#include <string.h>
#include "kk_product.h"
#include "cJSON.h"
const char KK_URI_SYS_PREFIX[] = "/sys/%s/%s/#";
int KK_Subdev_Subscribe(const cJSON *root)
{
int res = 0;
cJSON *productType = NULL;
cJSON *productCode = NULL;
cJSON *data = NULL;
cJSON *cmd = NULL;
int url_len = 0;
data = cJSON_GetObjectItem(root, "data");
if(data == NULL){
return -1;
}
productType = cJSON_GetObjectItem(data,"productType");
if(productType == NULL){
return -1;
}
productCode = cJSON_GetObjectItem(data,"productCode");
if(productCode == NULL){
return -1;
}
url_len = strlen(KK_URI_SYS_PREFIX) + strlen(productType->valuestring) + strlen(productCode->valuestring) + 1;
char *url = malloc(url_len);
if (url == NULL) {
return -1;
}
memset(url, 0, url_len);
snprintf(url, url_len, KK_URI_SYS_PREFIX, productType->valuestring, productCode->valuestring);
printf("[%s][%d] URL:%s\n",__FUNCTION__,__LINE__,url);
res = KK_MQTT_SubTopic(url);
free(url);
return res;
}
int _kk_client_subscribe(char productType[PRODUCT_TYPE_LEN], char productCode[PRODUCT_CODE_LEN])
static int _kk_client_subscribe(char productType[PRODUCT_TYPE_LEN], char productCode[PRODUCT_CODE_LEN])
{
int res = 0, index = 0, fail_count = 0;
......@@ -26,7 +61,7 @@ int _kk_client_subscribe(char productType[PRODUCT_TYPE_LEN], char productCode[PR
res = KK_MQTT_SubTopic(url);
free(url);
return 0;
return res;
}
int KK_Client_Gateway_Subscribe(void)
......
......@@ -4,7 +4,7 @@
#include "kcloud_log.h"
#include "kcloud_config.h"
extern void KK_Sendto_CloudData(void *data,int len);
extern void KK_Data_FromDev(void* str,int len);
extern int KK_MQTT_SubTopic(char *topicName);
......
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