Commit b049cedc authored by whmaizmy's avatar whmaizmy Committed by 黄振令

【修改内容】子设备login成功后,发送mqtt 订阅主题

【提交人】黄振令
parent c21ebf96
...@@ -51,6 +51,12 @@ void KK_Sendto_CloudData(void *data,int len) ...@@ -51,6 +51,12 @@ void KK_Sendto_CloudData(void *data,int len)
#define KK_FILTER_REGISTER_TOPIC_REPLY "/thing/sub/register_reply" #define KK_FILTER_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
#define KK_FILTER_LOGIN_TOPIC "/thing/combine/login" #define KK_FILTER_LOGIN_TOPIC "/thing/combine/login"
#define KK_FILTER_LOGIN_TOPIC_REPLY "/thing/combine/login_reply" #define KK_FILTER_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
#define KK_FILTER_SET_TOPIC "/thing/service/property/set"
#define KK_FILTER_SET_TOPIC_REPLY "/thing/service/property/set_reply"
#define KK_FILTER_EVENT_POST_TOPIC "/thing/event/property/post"
#define KK_FILTER_EVENT_POST_REPLY "/thing/event/property/post_reply"
static int _check_invalid_topic(char* topic) static int _check_invalid_topic(char* topic)
{ {
...@@ -70,6 +76,13 @@ static int _check_invalid_topic(char* topic) ...@@ -70,6 +76,13 @@ static int _check_invalid_topic(char* topic)
strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){ strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){
return 1; return 1;
} }
else if(strstr(topic, KK_FILTER_SET_TOPIC_REPLY) != NULL){
return 1;
}
else if(strstr(topic, KK_FILTER_EVENT_POST_TOPIC) != NULL && \
strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){
return 1;
}
return 0; return 0;
} }
void KK_Sendto_DevData(const char *topic,const char *data) void KK_Sendto_DevData(const char *topic,const char *data)
......
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "kk_dm_api.h" #include "kk_dm_api.h"
#include "kk_tsl_common.h" #include "kk_tsl_common.h"
#include "kk_dm_mng.h" #include "kk_dm_mng.h"
#include "com_api.h"
static dm_api_ctx_t g_dm_api_ctx; static dm_api_ctx_t g_dm_api_ctx;
...@@ -244,4 +244,47 @@ int iotx_dm_connect(_IN_ iotx_dm_event_callback cb) ...@@ -244,4 +244,47 @@ int iotx_dm_connect(_IN_ iotx_dm_event_callback cb)
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int iotx_dm_subscribe(_IN_ int devid)
{
int res = 0, dev_type = 0;
char product_key[PRODUCT_KEY_MAXLEN] = {0};
char device_name[DEVICE_NAME_MAXLEN] = {0};
char device_secret[DEVICE_SECRET_MAXLEN] = {0};
if (devid < 0) {
return INVALID_PARAMETER;
}
dm_mgr_dev_node_t *node = NULL;
_dm_api_lock();
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
_dm_api_unlock();
return FAIL_RETURN;
}
_dm_api_unlock();
//send app to subscribe mqtt
const char subscribe_cmd[] =
"{\"cmd\":\"subscribe\",\"data\":{\"productType\":\"%s\",\"productCode\":\"%s\"}}";
int len = strlen(subscribe_cmd) + strlen(node->product_key) + strlen(node->device_name) + 1;
void* buf = malloc(len);
if (buf){
HAL_Snprintf(buf, len, subscribe_cmd, node->product_key, node->device_name);
kk_ipc_send(IPC_MID2APP, buf, len);
free(buf);
}else{
printf("\n [%d][%s] malloc faild kk_ipc_send \n", __LINE__, __FUNCTION__);
return FAIL_RETURN;
}
printf("\n [%d][%s] [%d] send app to subscribe mqtt \n", __LINE__, __FUNCTION__, HAL_UptimeMs());
return SUCCESS_RETURN;
}
...@@ -244,9 +244,11 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -244,9 +244,11 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq",""); kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","");
}else{ }else{
printf("rrr topic: [%s] ,payload= %s \n",topic->valuestring,payload->valuestring ); printf("rrr topic: [%s] ,payload= %s \n",topic->valuestring,payload->valuestring );
if (strpbrk(payload->valuestring, "register_reply") != NULL){
if (strstr(topic->valuestring, "register_reply") != NULL){
//====todo====== //====todo======
//get devicececret and save it //get devicececret and save it
printf(" topic:register_reply \n");
dm_msg_response_payload_t response; dm_msg_response_payload_t response;
res = dm_msg_response_parse((char *)payload->valuestring, strlen(payload->valuestring)+1, &response); res = dm_msg_response_parse((char *)payload->valuestring, strlen(payload->valuestring)+1, &response);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
...@@ -257,9 +259,10 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -257,9 +259,10 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int); _iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int);
_iotx_linkkit_upstream_mutex_unlock(); _iotx_linkkit_upstream_mutex_unlock();
}else if (strpbrk(topic, "add_reply") != NULL){ }else if (strstr(topic->valuestring, "add_reply") != NULL){
//====todo====== //====todo======
// //
printf(" topic:add_reply \n");
dm_msg_response_payload_t response; dm_msg_response_payload_t response;
res = dm_msg_response_parse((char *)payload->valuestring, strlen(payload->valuestring)+1, &response); res = dm_msg_response_parse((char *)payload->valuestring, strlen(payload->valuestring)+1, &response);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
...@@ -270,9 +273,10 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -270,9 +273,10 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int); _iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int);
_iotx_linkkit_upstream_mutex_unlock(); _iotx_linkkit_upstream_mutex_unlock();
}else if (strpbrk(topic, "login_reply") != NULL){ }else if (strstr(topic->valuestring, "login_reply") != NULL){
//====todo====== //====todo======
// //
printf(" topic:login_reply \n");
dm_msg_response_payload_t response; dm_msg_response_payload_t response;
res = dm_msg_response_parse((char *)payload->valuestring, strlen(payload->valuestring)+1, &response); res = dm_msg_response_parse((char *)payload->valuestring, strlen(payload->valuestring)+1, &response);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
...@@ -282,9 +286,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data) ...@@ -282,9 +286,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
_iotx_linkkit_upstream_mutex_lock(); _iotx_linkkit_upstream_mutex_lock();
_iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int); _iotx_linkkit_upstream_callback_remove(atoi(response.id.value), response.code.value_int);
_iotx_linkkit_upstream_mutex_unlock(); _iotx_linkkit_upstream_mutex_unlock();
}else if (strstr(topic->valuestring, "thing/service/property/set") != NULL){
printf("set property 222222222222222 \n");
kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
}else{ }else{
printf("Error 222222222222222 \n"); printf("Error 222222222222222 \n");
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
} }
} }
...@@ -1442,20 +1449,13 @@ static int _iotx_linkkit_subdev_login(int devid) ...@@ -1442,20 +1449,13 @@ static int _iotx_linkkit_subdev_login(int devid)
} }
_iotx_linkkit_upstream_mutex_unlock(); _iotx_linkkit_upstream_mutex_unlock();
//send app to subscribe mqtt
const char subscribe_cmd[] =
"{\"cmd\":\"subscribe\",\"productKey\":\"%s\",\"deviceName\":\"%s\",\"clientId\":\"%s\",\"timestamp\":\"%s\",\"signMethod\":\"%s\",\"sign\":\"%s\",\"cleanSession\":\"%s\"}";
kk_ipc_send(IPC_MID2APP, subscribe_cmd, strlen(subscribe_cmd) + 1);
printf("\n [%d][%s] [%d] allan kk_ipc_send \n", __LINE__, __FUNCTION__, HAL_UptimeMs());
/*res = iotx_dm_subscribe(devid); res = iotx_dm_subscribe(devid);
if (res != SUCCESS_RETURN) { if (res != SUCCESS_RETURN) {
return FAIL_RETURN; return FAIL_RETURN;
} }
iotx_dm_send_aos_active(devid); /*iotx_dm_send_aos_active(devid);
callback = iotx_event_callback(ITE_INITIALIZE_COMPLETED); callback = iotx_event_callback(ITE_INITIALIZE_COMPLETED);
if (callback) { if (callback) {
((int (*)(const int))callback)(devid); ((int (*)(const int))callback)(devid);
......
This diff is collapsed.
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