int IOT_Linkkit_Report(int devid, iotx_linkkit_msg_type_t msg_type, unsigned char *payload, int payload_len)
属性上报
上层app层封装组包
/**
* @brief 上报属性LightSwitch到云端
* @param devid 由调用IOT_Linkkit_Open返回的设备标示符
* @param value 属性LightSwitch的值,数据类型uint8_t
* @return 消息id:(>=1), 上报失败: <0
*/
int32_t app_post_property_LightSwitch(uint32_t devid, uint8_t value)
{
int32_t res = -0x100;
char property_payload[64] = {0};
res = HAL_Snprintf(property_payload, sizeof(property_payload), "{\"LightSwitch\": %d}", value);
if (res < 0) {
return -0x10E;
}
res = IOT_Linkkit_Report(devid, ITM_MSG_POST_PROPERTY, (uint8_t *)property_payload, strlen(property_payload));
return res;
}
/**
* @brief 上报属性LightSwitch到云端
* @param devid 由调用IOT_Linkkit_Open返回的设备标示符
* @param value 属性LightSwitch的值,数据类型uint8_t
* @return 消息id:(>=1), 上报失败: <0
*/
int iotx_dm_post_property(_IN_ int devid, _IN_ char *payload, _IN_ int payload_len)
{
int res = 0;
_dm_api_lock();
res = dm_mgr_upstream_thing_property_post(devid, payload, payload_len);
if (res < SUCCESS_RETURN) {
_dm_api_unlock();
return FAIL_RETURN;
}
_dm_api_unlock();
return res;
}
int dm_mgr_upstream_thing_property_post(_IN_ int devid, _IN_ char *payload, _IN_ int payload_len)
{
int res = 0;
dm_msg_request_t request;
if (devid < 0 || payload == NULL || payload_len <= 0) {
return DM_INVALID_PARAMETER;
}
memset(&request, 0, sizeof(dm_msg_request_t));
res = _dm_mgr_upstream_request_assemble(iotx_report_id(), devid, DM_URI_SYS_PREFIX, DM_URI_THING_EVENT_PROPERTY_POST,
payload, payload_len, "thing.event.property.post", &request);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
/* Callback */
request.callback = dm_client_thing_event_post_reply;
/* Send Message To Cloud */
res = dm_msg_request(DM_MSG_DEST_ALL, &request);
#if !defined(DM_MESSAGE_CACHE_DISABLED)
if (res == SUCCESS_RETURN) {
int prop_post_reply = 0;
res = dm_opt_get(DM_OPT_DOWNSTREAM_EVENT_POST_REPLY, &prop_post_reply);
if (res == SUCCESS_RETURN && prop_post_reply) {
dm_msg_cache_insert(request.msgid, request.devid, IOTX_DM_EVENT_EVENT_PROPERTY_POST_REPLY, NULL);
}
res = request.msgid;
}
#endif
return res;
}