Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k-sdk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈伟灿
k-sdk
Commits
b049cedc
Commit
b049cedc
authored
Aug 06, 2020
by
whmaizmy
Committed by
黄振令
Aug 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】子设备login成功后,发送mqtt 订阅主题
【提交人】黄振令
parent
c21ebf96
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
707 additions
and
500 deletions
+707
-500
application/kcloud/kcloud_data_handle.c
application/kcloud/kcloud_data_handle.c
+97
-84
gateway.json
gateway.json
+552
-0
midware/midware/dm/kk_dm_api.c
midware/midware/dm/kk_dm_api.c
+44
-1
midware/midware/dm/kk_linkkit.c
midware/midware/dm/kk_linkkit.c
+14
-14
midware/midware/klist.h
midware/midware/klist.h
+0
-401
No files found.
application/kcloud/kcloud_data_handle.c
View file @
b049cedc
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include "mqtt_api.h"
#include "mqtt_api.h"
#include "com_api.h"
#include "com_api.h"
#include "cJSON.h"
#include "cJSON.h"
static
char
*
_kk_data_create
(
const
char
*
topic
,
const
char
*
data
)
static
char
*
_kk_data_create
(
const
char
*
topic
,
const
char
*
data
)
{
{
cJSON
*
root
;
cJSON
*
root
;
char
*
out
;
char
*
out
;
root
=
cJSON_CreateObject
();
root
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
root
,
"topic"
,
topic
);
cJSON_AddStringToObject
(
root
,
"topic"
,
topic
);
cJSON_AddStringToObject
(
root
,
"payload"
,
data
);
cJSON_AddStringToObject
(
root
,
"payload"
,
data
);
out
=
cJSON_Print
(
root
);
out
=
cJSON_Print
(
root
);
cJSON_Delete
(
root
);
cJSON_Delete
(
root
);
printf
(
"[%s][%d]%s
\n
"
,
__FUNCTION__
,
__LINE__
,
out
);
printf
(
"[%s][%d]%s
\n
"
,
__FUNCTION__
,
__LINE__
,
out
);
return
out
;
return
out
;
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */
}
}
void
KK_Sendto_CloudData
(
void
*
data
,
int
len
)
void
KK_Sendto_CloudData
(
void
*
data
,
int
len
)
{
{
cJSON
*
root
,
*
pTopic
,
*
pData
;
cJSON
*
root
,
*
pTopic
,
*
pData
;
char
*
topic
=
NULL
;
char
*
topic
=
NULL
;
char
*
payload
=
NULL
;
char
*
payload
=
NULL
;
root
=
cJSON_Parse
((
char
*
)
data
);
root
=
cJSON_Parse
((
char
*
)
data
);
if
(
root
==
NULL
)
if
(
root
==
NULL
)
{
{
return
;
return
;
}
}
pTopic
=
cJSON_GetObjectItem
(
root
,
"topic"
);
pTopic
=
cJSON_GetObjectItem
(
root
,
"topic"
);
if
(
pTopic
==
NULL
)
if
(
pTopic
==
NULL
)
{
{
return
;
return
;
}
}
pData
=
cJSON_GetObjectItem
(
root
,
"payload"
);
pData
=
cJSON_GetObjectItem
(
root
,
"payload"
);
if
(
pData
==
NULL
)
if
(
pData
==
NULL
)
{
{
return
;
return
;
}
}
printf
(
"[%s][%d] topic:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pTopic
->
valuestring
);
printf
(
"[%s][%d] topic:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pTopic
->
valuestring
);
printf
(
"[%s][%d] payload:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pData
->
valuestring
);
printf
(
"[%s][%d] payload:%s
\n
"
,
__FUNCTION__
,
__LINE__
,
pData
->
valuestring
);
KK_MQTT_SendMsg
(
pTopic
->
valuestring
,(
const
char
*
)
pData
->
valuestring
);
KK_MQTT_SendMsg
(
pTopic
->
valuestring
,(
const
char
*
)
pData
->
valuestring
);
}
}
#define KK_FILTER_ADD_TOPIC "/thing/topo/add"
#define KK_FILTER_ADD_TOPIC "/thing/topo/add"
#define KK_FILTER_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_FILTER_ADD_TOPIC_REPLY "/thing/topo/add_reply"
#define KK_FILTER_DELETE_TOPIC "/thing/topo/delete"
#define KK_FILTER_DELETE_TOPIC "/thing/topo/delete"
#define KK_FILTER_DELETE_TOPIC_REPLY "/thing/topo/delete_reply"
#define KK_FILTER_DELETE_TOPIC_REPLY "/thing/topo/delete_reply"
#define KK_FILTER_REGISTER_TOPIC "/thing/sub/register"
#define KK_FILTER_REGISTER_TOPIC "/thing/sub/register"
#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"
static
int
_check_invalid_topic
(
char
*
topic
)
#define KK_FILTER_SET_TOPIC_REPLY "/thing/service/property/set_reply"
{
#define KK_FILTER_EVENT_POST_TOPIC "/thing/event/property/post"
if
(
strstr
(
topic
,
KK_FILTER_ADD_TOPIC
)
!=
NULL
&&
\
#define KK_FILTER_EVENT_POST_REPLY "/thing/event/property/post_reply"
strstr
(
topic
,
KK_FILTER_ADD_TOPIC_REPLY
)
==
NULL
){
return
1
;
}
else
if
(
strstr
(
topic
,
KK_FILTER_DELETE_TOPIC
)
!=
NULL
&&
\
static
int
_check_invalid_topic
(
char
*
topic
)
strstr
(
topic
,
KK_FILTER_DELETE_TOPIC_REPLY
)
==
NULL
){
{
return
1
;
if
(
strstr
(
topic
,
KK_FILTER_ADD_TOPIC
)
!=
NULL
&&
\
}
strstr
(
topic
,
KK_FILTER_ADD_TOPIC_REPLY
)
==
NULL
){
else
if
(
strstr
(
topic
,
KK_FILTER_REGISTER_TOPIC
)
!=
NULL
&&
\
return
1
;
strstr
(
topic
,
KK_FILTER_REGISTER_TOPIC_REPLY
)
==
NULL
){
}
return
1
;
else
if
(
strstr
(
topic
,
KK_FILTER_DELETE_TOPIC
)
!=
NULL
&&
\
}
strstr
(
topic
,
KK_FILTER_DELETE_TOPIC_REPLY
)
==
NULL
){
else
if
(
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC
)
!=
NULL
&&
\
return
1
;
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC_REPLY
)
==
NULL
){
}
return
1
;
else
if
(
strstr
(
topic
,
KK_FILTER_REGISTER_TOPIC
)
!=
NULL
&&
\
}
strstr
(
topic
,
KK_FILTER_REGISTER_TOPIC_REPLY
)
==
NULL
){
return
0
;
return
1
;
}
}
void
KK_Sendto_DevData
(
const
char
*
topic
,
const
char
*
data
)
else
if
(
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC
)
!=
NULL
&&
\
{
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC_REPLY
)
==
NULL
){
if
(
_check_invalid_topic
(
topic
))
return
1
;
{
}
return
;
//ingore the message
else
if
(
strstr
(
topic
,
KK_FILTER_SET_TOPIC_REPLY
)
!=
NULL
){
}
return
1
;
char
*
send_data
=
_kk_data_create
(
topic
,
data
);
}
else
if
(
strstr
(
topic
,
KK_FILTER_EVENT_POST_TOPIC
)
!=
NULL
&&
\
kk_ipc_send
(
IPC_APP2MID
,
send_data
,
strlen
(
send_data
)
+
1
);
strstr
(
topic
,
KK_FILTER_LOGIN_TOPIC_REPLY
)
==
NULL
){
}
return
1
;
}
return
0
;
}
void
KK_Sendto_DevData
(
const
char
*
topic
,
const
char
*
data
)
{
if
(
_check_invalid_topic
(
topic
))
{
return
;
//ingore the message
}
char
*
send_data
=
_kk_data_create
(
topic
,
data
);
kk_ipc_send
(
IPC_APP2MID
,
send_data
,
strlen
(
send_data
)
+
1
);
}
...
...
gateway.json
0 → 100644
View file @
b049cedc
This diff is collapsed.
Click to expand it.
midware/midware/dm/kk_dm_api.c
View file @
b049cedc
...
@@ -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
;
}
midware/midware/dm/kk_linkkit.c
View file @
b049cedc
...
@@ -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
(
str
pbrk
(
topic
,
"add_reply"
)
!=
NULL
){
}
else
if
(
str
str
(
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
(
str
pbrk
(
topic
,
"login_reply"
)
!=
NULL
){
}
else
if
(
str
str
(
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
[]
=
res
=
iotx_dm_subscribe
(
devid
);
"{
\"
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);
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);
...
...
midware/midware/klist.h
deleted
100644 → 0
View file @
c21ebf96
This diff is collapsed.
Click to expand it.
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