全部产品
云市场

标签

更新时间:2019-02-21 20:49:36

支持设备端上报标签到云端,以及删除设备标签。

说明 设备标签相关接口参见设备 IDeviceLabel

上报标签

  1. // 标签是 key,value的形式 可以替换 attrKey 和 attrValue
  2. String update_label = "{" + " \"id\": \"123\"," + " \"version\": \"1.0\"," +
  3. " \"params\": [" + " {" + " \"attrKey\": \"Temperature\"," +
  4. " \"attrValue\": \"36.8\"" + " }" + " ]," +
  5. " \"method\": \"thing.deviceinfo.update\"" + "}";
  6. RequestModel<List<Map>> requestModel = JSONObject.parseObject(update_label, new TypeReference<RequestModel<List<Map>>>() {
  7. }.getType());
  8. LinkKit.getInstance().getDeviceLabel().labelUpdate(requestModel, new IConnectSendListener() {
  9. @Override
  10. public void onResponse(ARequest aRequest, AResponse aResponse) {
  11. // 更新标签成功
  12. }
  13. @Override
  14. public void onFailure(ARequest aRequest, AError aError) {
  15. // 更新标签失败
  16. }
  17. });

删除标签

  1. // 标签是 key,value的形式 可以替换 attrKey 和 attrValue
  2. String deleteLabel = "{" + " \"id\": \"123\"," + " \"version\": \"1.0\"," +
  3. " \"params\": [" + " {" + " \"attrKey\": \"Temperature\"" +
  4. " }" + " ]," + " \"method\": \"thing.deviceinfo.delete\"" + "}";
  5. RequestModel<List<Map>> requestModel = JSONObject.parseObject(deleteLabel, new TypeReference<RequestModel<List<Map>>>() {
  6. }.getType());
  7. LinkKit.getInstance().getDeviceLabel().labelDelete(requestModel, new IConnectSendListener() {
  8. @Override
  9. public void onResponse(ARequest aRequest, AResponse aResponse) {
  10. // 删除标签成功
  11. }
  12. @Override
  13. public void onFailure(ARequest aRequest, AError aError) {
  14. // 删除标签失败
  15. }
  16. });