mirror of
https://github.com/emqx/neuron.git
synced 2026-10-24 10:46:39 +08:00
Add command field to MQTT request response data
- Modify the test script of ft - Fix parameter error in setting command - Fix json_mqtt_t instance not released
This commit is contained in:
+29
-36
@@ -37,15 +37,7 @@ _Http Node Ctl
|
||||
POST /api/v2/node/ctl {"id": ${node_id}, "cmd": ${cmd}}
|
||||
Integer response status 200
|
||||
|
||||
|
||||
Recv Message
|
||||
${msg} = Listen ${MQTT_CONFIG_RES_TOPIC} timeout=10
|
||||
Should Not Be True $msg == None
|
||||
${res} = evaluate json.loads('''${msg}''') json
|
||||
Should Be Equal As Strings ${res}[uuid] ${MQTT_UUID}
|
||||
[RETURN] ${res}
|
||||
|
||||
Recv Message1
|
||||
[Arguments] ${topic_res}
|
||||
${msg} = Listen ${topic_res} timeout=10
|
||||
Should Not Be True $msg == None
|
||||
@@ -54,19 +46,20 @@ Recv Message1
|
||||
[RETURN] ${res}
|
||||
|
||||
Pub And Recv
|
||||
[Arguments] ${func} ${payload} ${topic_req} ${topic_res}
|
||||
[Arguments] ${func} ${cmd} ${payload} ${topic_req} ${topic_res}
|
||||
${payload} = evaluate json.loads('''${payload}''') json
|
||||
Set To Dictionary ${payload} function ${func} uuid ${MQTT_UUID}
|
||||
Set To Dictionary ${payload} function ${func} uuid ${MQTT_UUID} command ${cmd}
|
||||
${payload} = evaluate json.dumps(${payload}) json
|
||||
|
||||
Publish ${topic_req} ${payload} qos=0
|
||||
|
||||
# try to receive a message with a matching UUID
|
||||
${res} = Wait Until Keyword Succeeds 10s 0s Recv Message1 ${topic_res}
|
||||
Should Be Equal As Integers ${res}[function] ${func}
|
||||
${res} = Wait Until Keyword Succeeds 10s 0s Recv Message ${topic_res}
|
||||
# Should Be Equal As Integers ${res}[function] ${func}
|
||||
Should Be Equal As Strings ${res}[command] ${cmd}
|
||||
|
||||
# strip the `function` and `uuid` field
|
||||
Remove From Dictionary ${res} function uuid
|
||||
Remove From Dictionary ${res} function uuid command
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
@@ -110,7 +103,7 @@ LOGOUT
|
||||
Add Node
|
||||
[Arguments] &{args}
|
||||
${payload} = evaluate json.dumps(${args}) json
|
||||
${res} = Pub And Recv ${MQTT_FUNC_ADD_NODES} ${payload} ${TOPIC_NODE_REQ} ${TOPIC_NODE_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_ADD_NODES} ${MQTT_CMD_ADD} ${payload} ${TOPIC_NODE_REQ} ${TOPIC_NODE_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
@@ -126,19 +119,19 @@ Add Node And Return ID
|
||||
|
||||
Get Nodes
|
||||
[Arguments] ${node_type}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_GET_NODES} {"node_type": ${node_type} } ${TOPIC_NODE_REQ} ${TOPIC_NODE_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_GET_NODES} ${MQTT_CMD_GET} {"node_type": ${node_type} } ${TOPIC_NODE_REQ} ${TOPIC_NODE_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Update Node
|
||||
[Arguments] ${node_id} ${node_name}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_UPDATE_NODES} {"id": ${node_id}, "name": "${node_name}"} ${TOPIC_NODE_REQ} ${TOPIC_NODE_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_UPDATE_NODES} ${MQTT_CMD_UPDATE} {"id": ${node_id}, "name": "${node_name}"} ${TOPIC_NODE_REQ} ${TOPIC_NODE_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Del Node
|
||||
[Arguments] ${node_id}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_DELETE_NODES} {"id": ${node_id}} ${TOPIC_NODE_REQ} ${TOPIC_NODE_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_DELETE_NODES} ${MQTT_CMD_DELETE} {"id": ${node_id}} ${TOPIC_NODE_REQ} ${TOPIC_NODE_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
@@ -151,82 +144,82 @@ Get Node ID
|
||||
|
||||
Node Setting
|
||||
[Arguments] ${node_id} ${config}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_NODE_SETTING} {"node_id": ${node_id}, "params": ${config}} ${TOPIC_SETTING_REQ} ${TOPIC_SETTING_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_NODE_SETTING} ${MQTT_CMD_SET} {"node_id": ${node_id}, "params": ${config}} ${TOPIC_SETTING_REQ} ${TOPIC_SETTING_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Get Node Setting
|
||||
[Arguments] ${node_id}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_GET_NODE_SETTING} {"node_id": ${node_id}} ${TOPIC_SETTING_REQ} ${TOPIC_SETTING_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_GET_NODE_SETTING} ${MQTT_CMD_GET} {"node_id": ${node_id}} ${TOPIC_SETTING_REQ} ${TOPIC_SETTING_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Get Node State
|
||||
[Arguments] ${node_id}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_GET_NODE_STATE} {"node_id": ${node_id}} ${TOPIC_STATE_REQ} ${TOPIC_STATE_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_GET_NODE_STATE} ${MQTT_CMD_GET} {"node_id": ${node_id}} ${TOPIC_STATE_REQ} ${TOPIC_STATE_RES}
|
||||
|
||||
[RETURN] ${res}[running] ${res}[link]
|
||||
|
||||
Node Ctl
|
||||
[Arguments] ${node_id} ${cmd}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_NODE_CONTROL} {"id": ${node_id}, "cmd": ${cmd}} ${TOPIC_CTR_REQ} ${TOPIC_CTR_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_NODE_CONTROL} ${MQTT_CMD_NONE} {"id": ${node_id}, "cmd": ${cmd}} ${TOPIC_CTR_REQ} ${TOPIC_CTR_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Ping
|
||||
${res} = Pub And Recv ${MQTT_FUNC_PING} {} ${TOPIC_PING_REQ} ${TOPIC_STATUS_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_PING} ${MQTT_CMD_NONE} {} ${TOPIC_PING_REQ} ${TOPIC_STATUS_RES}
|
||||
|
||||
Add Group Config
|
||||
[Arguments] ${node_id} ${grp_config_name} ${interval}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_ADD_GROUP_CONFIG} {"name": "${grp_config_name}", "node_id": ${node_id}, "interval": ${interval}} ${TOPIC_GCONFIG_REQ} ${TOPIC_GCONFIG_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_ADD_GROUP_CONFIG} ${MQTT_CMD_ADD} {"name": "${grp_config_name}", "node_id": ${node_id}, "interval": ${interval}} ${TOPIC_GCONFIG_REQ} ${TOPIC_GCONFIG_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Get Group Config
|
||||
[Arguments] ${node_id}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_GET_GROUP_CONFIG} {"node_id": ${node_id}} ${TOPIC_GCONFIG_REQ} ${TOPIC_GCONFIG_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_GET_GROUP_CONFIG} ${MQTT_CMD_GET} {"node_id": ${node_id}} ${TOPIC_GCONFIG_REQ} ${TOPIC_GCONFIG_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Update Group Config
|
||||
[Arguments] ${node_id} ${grp_config_name} ${interval}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_UPDATE_GROUP_CONFIG} {"name": "${grp_config_name}", "node_id": ${node_id}, "interval": ${interval}} ${TOPIC_GCONFIG_REQ} ${TOPIC_GCONFIG_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_UPDATE_GROUP_CONFIG} ${MQTT_CMD_UPDATE} {"name": "${grp_config_name}", "node_id": ${node_id}, "interval": ${interval}} ${TOPIC_GCONFIG_REQ} ${TOPIC_GCONFIG_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Del Group Config
|
||||
[Arguments] ${node_id} ${grp_config_name}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_DELETE_GROUP_CONFIG} {"name": "${grp_config_name}", "node_id": ${node_id}} ${TOPIC_GCONFIG_REQ} ${TOPIC_GCONFIG_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_DELETE_GROUP_CONFIG} ${MQTT_CMD_DELETE} {"name": "${grp_config_name}", "node_id": ${node_id}} ${TOPIC_GCONFIG_REQ} ${TOPIC_GCONFIG_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Subscribe Group
|
||||
[Arguments] ${driver_node_id} ${app_node_id} ${group_config_name}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_SUBSCRIBE_GROUP_CONFIG} {"src_node_id": ${driver_node_id}, "dst_node_id": ${app_node_id}, "name": "${group_config_name}"} ${TOPIC_SUBSCRIBE_REQ} ${TOPIC_SUBSCRIBE_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_SUBSCRIBE_GROUP_CONFIG} ${MQTT_CMD_ADD} {"src_node_id": ${driver_node_id}, "dst_node_id": ${app_node_id}, "name": "${group_config_name}"} ${TOPIC_SUBSCRIBE_REQ} ${TOPIC_SUBSCRIBE_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Get Subscribe Group
|
||||
[Arguments] ${node_id}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_GET_SUBSCRIBE_GROUP_CONFIG} {"node_id": ${node_id}} ${TOPIC_SUBSCRIBE_REQ} ${TOPIC_SUBSCRIBE_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_GET_SUBSCRIBE_GROUP_CONFIG} ${MQTT_CMD_GET} {"node_id": ${node_id}} ${TOPIC_SUBSCRIBE_REQ} ${TOPIC_SUBSCRIBE_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Unsubscribe Group
|
||||
[Arguments] ${driver_node_id} ${app_node_id} ${group_config_name}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_UNSUBSCRIBE_GROUP_CONFIG} {"src_node_id": ${driver_node_id}, "dst_node_id": ${app_node_id}, "name": "${group_config_name}"} ${TOPIC_SUBSCRIBE_REQ} ${TOPIC_SUBSCRIBE_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_UNSUBSCRIBE_GROUP_CONFIG} ${MQTT_CMD_DELETE} {"src_node_id": ${driver_node_id}, "dst_node_id": ${app_node_id}, "name": "${group_config_name}"} ${TOPIC_SUBSCRIBE_REQ} ${TOPIC_SUBSCRIBE_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Add Tags
|
||||
[Arguments] ${node_id} ${group} ${tags}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_ADD_TAGS} {"node_id": ${node_id}, "group_config_name": "${group}", "tags": [${tags}]} ${TOPIC_TAGS_REQ} ${TOPIC_TAGS_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_ADD_TAGS} ${MQTT_CMD_ADD} {"node_id": ${node_id}, "group_config_name": "${group}", "tags": [${tags}]} ${TOPIC_TAGS_REQ} ${TOPIC_TAGS_RES}
|
||||
|
||||
[RETURN] ${res}
|
||||
|
||||
Add Tag And Return ID
|
||||
[Arguments] ${node_id} ${group} ${tag}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_ADD_TAGS} {"node_id": ${node_id}, "group_config_name": "${group}", "tags": [${tag}]} ${TOPIC_TAGS_REQ} ${TOPIC_TAGS_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_ADD_TAGS} ${MQTT_CMD_ADD} {"node_id": ${node_id}, "group_config_name": "${group}", "tags": [${tag}]} ${TOPIC_TAGS_REQ} ${TOPIC_TAGS_RES}
|
||||
|
||||
Check Error Code ${res} ${ERR_SUCCESS}
|
||||
${tmp} = evaluate json.loads('''${tag}''') json
|
||||
@@ -235,19 +228,19 @@ Add Tag And Return ID
|
||||
|
||||
Get Tags
|
||||
[Arguments] ${node_id} ${group}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_GET_TAGS} {"node_id": ${node_id}, "group_config_name": "${group}"} ${TOPIC_TAGS_REQ} ${TOPIC_TAGS_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_GET_TAGS} ${MQTT_CMD_GET} {"node_id": ${node_id}, "group_config_name": "${group}"} ${TOPIC_TAGS_REQ} ${TOPIC_TAGS_RES}
|
||||
|
||||
[Return] ${res}
|
||||
|
||||
Update Tags
|
||||
[Arguments] ${node_id} ${group} ${tags}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_UPDATE_TAGS} {"node_id": ${node_id}, "group_config_name": "${group}", "tags": [${tags}]} ${TOPIC_TAGS_REQ} ${TOPIC_TAGS_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_UPDATE_TAGS} ${MQTT_CMD_UPDATE} {"node_id": ${node_id}, "group_config_name": "${group}", "tags": [${tags}]} ${TOPIC_TAGS_REQ} ${TOPIC_TAGS_RES}
|
||||
|
||||
[Return] ${res}
|
||||
|
||||
Del Tags
|
||||
[Arguments] ${node_id} ${group} ${ids}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_DELETE_TAGS} {"node_id": ${node_id}, "group_config_name": "${group}", "ids": [${ids}]} ${TOPIC_TAGS_REQ} ${TOPIC_TAGS_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_DELETE_TAGS} ${MQTT_CMD_DELETE} {"node_id": ${node_id}, "group_config_name": "${group}", "ids": [${ids}]} ${TOPIC_TAGS_REQ} ${TOPIC_TAGS_RES}
|
||||
|
||||
[Return] ${res}
|
||||
|
||||
@@ -261,12 +254,12 @@ Get Tag ID
|
||||
|
||||
Read Tags
|
||||
[Arguments] ${node_id} ${group}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_READ} {"node_id": ${node_id}, "group_config_name": "${group}"} ${TOPIC_READ_REQ} ${TOPIC_READ_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_READ} ${MQTT_CMD_NONE} {"node_id": ${node_id}, "group_config_name": "${group}"} ${TOPIC_READ_REQ} ${TOPIC_READ_RES}
|
||||
|
||||
[Return] ${res}
|
||||
|
||||
Write Tags
|
||||
[Arguments] ${node_id} ${group} ${tags}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_WRITE} {"node_id": ${node_id}, "group_config_name": "${group}", "tags": [${tags}]} ${TOPIC_WRITE_REQ} ${TOPIC_WRITE_RES}
|
||||
${res} = Pub And Recv ${MQTT_FUNC_WRITE} ${MQTT_CMD_NONE} {"node_id": ${node_id}, "group_config_name": "${group}", "tags": [${tags}]} ${TOPIC_WRITE_REQ} ${TOPIC_WRITE_RES}
|
||||
|
||||
[Return] ${res}
|
||||
|
||||
@@ -88,6 +88,13 @@ ${MQTT_FUNC_DELETE_PLUGIN} ${27}
|
||||
${MQTT_FUNC_GET_PLUGIN} ${28}
|
||||
${MQTT_FUNC_PING} ${29}
|
||||
|
||||
${MQTT_CMD_GET} get
|
||||
${MQTT_CMD_SET} set
|
||||
${MQTT_CMD_ADD} add
|
||||
${MQTT_CMD_UPDATE} update
|
||||
${MQTT_CMD_DELETE} delete
|
||||
${MQTT_CMD_NONE}
|
||||
|
||||
${MQTT_CLIENTID} 123456
|
||||
${TOPIC_PING_REQ} neuron/${MQTT_CLIENTID}/ping
|
||||
${TOPIC_NODE_REQ} neuron/${MQTT_CLIENTID}/node/req
|
||||
|
||||
@@ -74,9 +74,17 @@ typedef enum neu_mqtt_function {
|
||||
|
||||
} neu_mqtt_function_e;
|
||||
|
||||
#define NEU_MQTT_CMD_GET "get"
|
||||
#define NEU_MQTT_CMD_SET "set"
|
||||
#define NEU_MQTT_CMD_ADD "add"
|
||||
#define NEU_MQTT_CMD_UPDATE "update"
|
||||
#define NEU_MQTT_CMD_DELETE "delete"
|
||||
#define NEU_MQTT_CMD_NONE ""
|
||||
|
||||
typedef struct {
|
||||
neu_mqtt_function_e function;
|
||||
char * uuid;
|
||||
char * command;
|
||||
} neu_json_mqtt_t;
|
||||
|
||||
int neu_json_decode_mqtt_req(char *buf, neu_json_mqtt_t **result);
|
||||
|
||||
@@ -389,13 +389,13 @@ void command_response_handle(mqtt_response_t *response)
|
||||
|
||||
case TOPIC_TYPE_NODE: {
|
||||
// Node GET/ADD/UPDATE/DELETE
|
||||
if (mqtt->function == NEU_MQTT_OP_GET_NODES) {
|
||||
if (0 == strcmp(NEU_MQTT_CMD_GET, mqtt->command)) {
|
||||
rc = node_response_get(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_ADD_NODES) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_ADD, mqtt->command)) {
|
||||
rc = node_response_add(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_UPDATE_NODES) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_UPDATE, mqtt->command)) {
|
||||
rc = node_response_update(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_DELETE_NODES) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_DELETE, mqtt->command)) {
|
||||
rc = node_response_delete(&ret_str, plugin, mqtt, json_str);
|
||||
}
|
||||
|
||||
@@ -404,13 +404,13 @@ void command_response_handle(mqtt_response_t *response)
|
||||
|
||||
case TOPIC_TYPE_GCONFIG: {
|
||||
// Group Config GET/ADD/UPDATE/DELETE
|
||||
if (mqtt->function == NEU_MQTT_OP_GET_GROUP_CONFIG) {
|
||||
if (0 == strcmp(NEU_MQTT_CMD_GET, mqtt->command)) {
|
||||
rc = group_config_response_get(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_ADD_GROUP_CONFIG) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_ADD, mqtt->command)) {
|
||||
rc = group_config_response_add(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_UPDATE_GROUP_CONFIG) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_UPDATE, mqtt->command)) {
|
||||
rc = group_config_response_update(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_DELETE_GROUP_CONFIG) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_DELETE, mqtt->command)) {
|
||||
rc = group_config_response_delete(&ret_str, plugin, mqtt, json_str);
|
||||
}
|
||||
|
||||
@@ -419,13 +419,13 @@ void command_response_handle(mqtt_response_t *response)
|
||||
|
||||
case TOPIC_TYPE_TAGS: {
|
||||
// Tag GET/ADD/UPDATE/DELETE
|
||||
if (mqtt->function == NEU_MQTT_OP_GET_TAGS) {
|
||||
if (0 == strcmp(NEU_MQTT_CMD_GET, mqtt->command)) {
|
||||
rc = datatag_response_get(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_ADD_TAGS) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_ADD, mqtt->command)) {
|
||||
rc = datatag_response_add(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_UPDATE_TAGS) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_UPDATE, mqtt->command)) {
|
||||
rc = datatag_response_update(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_DELETE_TAGS) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_DELETE, mqtt->command)) {
|
||||
rc = datatag_response_delete(&ret_str, plugin, mqtt, json_str);
|
||||
}
|
||||
|
||||
@@ -434,11 +434,11 @@ void command_response_handle(mqtt_response_t *response)
|
||||
|
||||
case TOPIC_TYPE_PLUGIN: {
|
||||
// Plugin GET/ADD/UPDATE/DELETE
|
||||
if (mqtt->function == NEU_MQTT_OP_GET_PLUGIN) {
|
||||
if (0 == strcmp(NEU_MQTT_CMD_GET, mqtt->command)) {
|
||||
rc = plugin_response_get(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_ADD_PLUGIN) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_ADD, mqtt->command)) {
|
||||
rc = plugin_response_add(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_DELETE_PLUGIN) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_DELETE, mqtt->command)) {
|
||||
rc = plugin_response_delete(&ret_str, plugin, mqtt, json_str);
|
||||
}
|
||||
|
||||
@@ -447,11 +447,11 @@ void command_response_handle(mqtt_response_t *response)
|
||||
|
||||
case TOPIC_TYPE_SUBSCRIBE: {
|
||||
// Subscribe GET/ADD/DELETE
|
||||
if (mqtt->function == NEU_MQTT_OP_SUBSCRIBE) {
|
||||
if (0 == strcmp(NEU_MQTT_CMD_ADD, mqtt->command)) {
|
||||
rc = subscribe_response_add(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_UNSUBSCRIBE) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_DELETE, mqtt->command)) {
|
||||
rc = subscribe_response_delete(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_GET_SUBSCRIBE_GRP_CONFIG) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_GET, mqtt->command)) {
|
||||
rc = subscribe_response_get(&ret_str, plugin, mqtt, json_str);
|
||||
}
|
||||
|
||||
@@ -480,9 +480,9 @@ void command_response_handle(mqtt_response_t *response)
|
||||
|
||||
case TOPIC_TYPE_SETTING: {
|
||||
// Setting SET/GET
|
||||
if (mqtt->function == NEU_MQTT_OP_NODE_SETTING) {
|
||||
if (0 == strcmp(NEU_MQTT_CMD_SET, mqtt->command)) {
|
||||
rc = setting_response_set(&ret_str, plugin, mqtt, json_str);
|
||||
} else if (mqtt->function == NEU_MQTT_OP_GET_NODE_SETTING) {
|
||||
} else if (0 == strcmp(NEU_MQTT_CMD_GET, mqtt->command)) {
|
||||
rc = setting_response_get(&ret_str, plugin, mqtt, json_str);
|
||||
}
|
||||
|
||||
@@ -514,4 +514,6 @@ void command_response_handle(mqtt_response_t *response)
|
||||
if (NULL != json_str) {
|
||||
free(json_str);
|
||||
}
|
||||
|
||||
neu_json_decode_mqtt_req_free(mqtt);
|
||||
}
|
||||
@@ -26,7 +26,8 @@ char *command_ping(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt)
|
||||
UNUSED(plugin);
|
||||
log_info("Node control uuid:%s", mqtt->uuid);
|
||||
char *result = calloc(100, sizeof(char));
|
||||
snprintf(result, 99, "{\"function\":%d, \"uuid\": \"%s\"}", mqtt->function,
|
||||
mqtt->uuid);
|
||||
snprintf(result, 99,
|
||||
"{\"function\":%d, \"uuid\": \"%s\", \"command\":\"%s\"}",
|
||||
mqtt->function, mqtt->uuid, "");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -233,7 +233,8 @@ char *command_read_cycle_response(neu_plugin_t * plugin,
|
||||
parse_header.function = NEU_MQTT_OP_READ;
|
||||
char uuid4_str[40] = { '\0' };
|
||||
neu_uuid_v4_gen(uuid4_str);
|
||||
parse_header.uuid = uuid4_str;
|
||||
parse_header.uuid = uuid4_str;
|
||||
parse_header.command = "";
|
||||
return command_read_once_response(plugin, &parse_header, resp_val);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,6 +114,10 @@ static void context_destroy(struct context *ctx)
|
||||
free(ctx->parse_header.uuid);
|
||||
}
|
||||
|
||||
if (NULL != ctx->parse_header.command) {
|
||||
free(ctx->parse_header.command);
|
||||
}
|
||||
|
||||
if (NULL != ctx->result) {
|
||||
free(ctx->result);
|
||||
}
|
||||
@@ -155,6 +159,7 @@ static void context_list_add(neu_plugin_t *plugin, int req_id,
|
||||
if (NULL != parse_header) {
|
||||
ctx->parse_header.function = parse_header->function;
|
||||
ctx->parse_header.uuid = strdup(parse_header->uuid);
|
||||
ctx->parse_header.command = strdup(parse_header->command);
|
||||
}
|
||||
|
||||
ctx->result = result;
|
||||
|
||||
@@ -121,18 +121,20 @@ int neu_json_encode_setting_with_mqtt(uint32_t node_id, char *setting,
|
||||
// the current implementation.
|
||||
|
||||
const char *fmt = "{\"node_id\": %u, \"function\": %d, \"uuid\": \"%s\", "
|
||||
"\"command\":\"%s\", "
|
||||
"%.*s, \"error\": 0}";
|
||||
// plus 1 for '\0'
|
||||
int size = 1 +
|
||||
snprintf(NULL, 0, fmt, node_id, mqtt->function, mqtt->uuid, i, params);
|
||||
snprintf(NULL, 0, fmt, node_id, mqtt->function, mqtt->uuid,
|
||||
mqtt->command, i, params);
|
||||
|
||||
*result = calloc(size, sizeof(char));
|
||||
if (NULL == *result) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
snprintf(*result, size, fmt, node_id, mqtt->function, mqtt->uuid, i,
|
||||
params);
|
||||
snprintf(*result, size, fmt, node_id, mqtt->function, mqtt->uuid,
|
||||
mqtt->command, i, params);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ int neu_json_decode_mqtt_req(char *buf, neu_json_mqtt_t **result)
|
||||
{
|
||||
.name = "function",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "command",
|
||||
.t = NEU_JSON_STR,
|
||||
} };
|
||||
ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(req_elems), req_elems);
|
||||
if (ret != 0) {
|
||||
@@ -49,6 +53,7 @@ int neu_json_decode_mqtt_req(char *buf, neu_json_mqtt_t **result)
|
||||
|
||||
req->uuid = req_elems[0].v.val_str;
|
||||
req->function = req_elems[1].v.val_int;
|
||||
req->command = req_elems[2].v.val_str;
|
||||
|
||||
*result = req;
|
||||
return ret;
|
||||
@@ -62,8 +67,17 @@ decode_fail:
|
||||
|
||||
void neu_json_decode_mqtt_req_free(neu_json_mqtt_t *req)
|
||||
{
|
||||
if (NULL == req) {
|
||||
return;
|
||||
}
|
||||
|
||||
free(req->uuid);
|
||||
if (NULL != req->uuid) {
|
||||
free(req->uuid);
|
||||
}
|
||||
|
||||
if (NULL != req->command) {
|
||||
free(req->command);
|
||||
}
|
||||
|
||||
free(req);
|
||||
}
|
||||
@@ -82,6 +96,11 @@ int neu_json_encode_mqtt_resp(void *json_object, void *param)
|
||||
.name = "function",
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = resp->function,
|
||||
},
|
||||
{
|
||||
.name = "command",
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = resp->command,
|
||||
} };
|
||||
ret = neu_json_encode_field(json_object, resp_elems,
|
||||
NEU_JSON_ELEM_SIZE(resp_elems));
|
||||
|
||||
Reference in New Issue
Block a user