更新时间:2023-02-06 GMT+08:00
示例三:在指定资源空间下创建设备
场景描述
本章节指导用户通过API在指定资源空间下创建设备。API的调用方法参见如何调用API。
物联网平台默认为用户创建了一个资源空间,创建设备时默认将设备归属于默认资源空间,如果用户需要对设备分资源空间管理,可以指定资源空间创建设备。
操作步骤
- 创建非系统默认的资源空间。
- 创建资源空间
- 接口信息
URL:POST /v5/iot/{project_id}/apps
详情参见创建资源空间
- 请求示例
POST https://{Endpoint}/v5/iot/{project_id}/apps Content-Type: application/json X-Auth-Token: ******** Instance-Id: ******** { "app_name" : "testApp" }
- 响应示例
Content-Type: application/json { "applications" : [ { "app_id" : "0ab87ceecbfc49acbcc8d5acdef3c68c", "app_name" : "testApp", "create_time" : "20151212T121212Z", "default_app" : true } ] }
- 接口信息
- 记录返回结果中资源空间id,即“app_id”。
- 创建资源空间
- 在指定资源空间下创建产品。
- 使用这里记录的app_id创建产品。
- 接口信息
URL:POST /v5/iot/{project_id}/products
详情参见创建产品
- 请求示例
POST https://{Endpoint}/v5/iot/{project_id}/products Content-Type: application/json X-Auth-Token: ******** Instance-Id: ******** { "product_id" : "5ba24f5ebbe8f56f5a14f605", "name" : "Thermometer", "device_type" : "Thermometer", "protocol_type" : "CoAP", "data_format" : "binary", "manufacturer_name" : "ABC", "industry" : "smartCity", "description" : "this is a thermometer produced by Huawei", "service_capabilities" : [ { "service_type" : "temperature", "service_id" : "temperature", "description" : "temperature", "properties" : [ { "unit" : "centigrade", "min" : "1", "method" : "R", "max" : "100", "data_type" : "decimal", "description" : "force", "step" : 0.1, "default_value" : { "color" : "red", "size" : 1 }, "enum_list" : [ "string" ], "required" : true, "property_name" : "temperature", "max_length" : 100 } ], "commands" : [ { "command_name" : "reboot", "responses" : [ { "response_name" : "ACK", "paras" : [ { "unit" : "km/h", "min" : "1", "max" : "100", "para_name" : "force", "data_type" : "string", "description" : "force", "step" : 0.1, "enum_list" : [ "string" ], "required" : false, "max_length" : 100 } ] } ], "paras" : [ { "unit" : "km/h", "min" : "1", "max" : "100", "para_name" : "force", "data_type" : "string", "description" : "force", "step" : 0.1, "enum_list" : [ "string" ], "required" : false, "max_length" : 100 } ] } ], "events" : [ { "event_type" : "reboot", "paras" : [ { "unit" : "km/h", "min" : "1", "max" : "100", "para_name" : "force", "data_type" : "string", "description" : "force", "step" : 0.1, "enum_list" : [ "string" ], "required" : false, "max_length" : 100 } ] } ], "option" : "Mandatory" } ], "app_id" : "jeQDJQZltU8iKgFFoW060F5SGZka" }
- 响应示例
Content-Type: application/json { "app_id" : "jeQDJQZltU8iKgFFoW060F5SGZka", "app_name" : "testAPP01", "product_id" : "5ba24f5ebbe8f56f5a14f605", "name" : "Thermometer", "device_type" : "Thermometer", "protocol_type" : "CoAP", "data_format" : "binary", "manufacturer_name" : "ABC", "industry" : "smartCity", "description" : "this is a thermometer produced by Huawei", "service_capabilities" : [ { "service_id" : "temperature", "service_type" : "temperature", "properties" : [ { "property_name" : "temperature", "required" : true, "data_type" : "decimal", "min" : 1, "max" : 100, "max_length" : 100, "step" : 0.1, "unit" : "centigrade", "method" : "R", "description" : "force", "default_value" : { "color" : "red", "size" : 1 } } ], "commands" : [ { "command_name" : "reboot", "paras" : [ { "para_name" : "force", "required" : false, "data_type" : "string", "min" : 1, "max" : 100, "max_length" : 100, "step" : 0.1, "unit" : "km/h", "description" : "force" } ], "responses" : [ { "paras" : [ { "para_name" : "force", "required" : false, "data_type" : "string", "min" : 1, "max" : 100, "max_length" : 100, "step" : 0.1, "unit" : "km/h", "description" : "force" } ], "response_name" : "ACK" } ] } ], "events" : [ { "event_type" : "reboot", "paras" : [ { "para_name" : "force", "required" : false, "data_type" : "string", "min" : 1, "max" : 100, "max_length" : 100, "step" : 0.1, "unit" : "km/h", "description" : "force" } ] } ], "description" : "temperature", "option" : "Mandatory" } ], "create_time" : "20190303T081011Z" }
- 接口信息
- 记录返回结果中产品id,即“product_id”。
- 使用这里记录的app_id创建产品。
- 在指定资源空间下创建设备。
- 使用这里记录的“app_id”和这里记录的“product_id”创建设备。
- 接口信息
URL:POST /v5/iot/{project_id}/devices
详情参见创建设备
- 请求示例
POST https://{Endpoint}/v5/iot/{project_id}/devices Content-Type: application/json X-Auth-Token: ******** Instance-Id: ******** { "device_id" : "d4922d8a-6c8e-4396-852c-164aefa6638f", "node_id" : "ABC123456789", "device_name" : "dianadevice", "product_id" : "b640f4c203b7910fc3cbd446ed437cbd", "auth_info" : { "auth_type" : "SECRET", "secure_access" : true, "fingerprint" : "dc0f1016f495157344ac5f1296335cff725ef22f", "secret" : "3b935a250c50dc2c6d481d048cefdc3c", "timeout" : 300 }, "description" : "watermeter device", "gateway_id" : "d4922d8a-6c8e-4396-852c-164aefa6638f", "app_id" : "jeQDJQZltU8iKgFFoW060F5SGZka", "extension_info" : { "aaa" : "xxx", "bbb" : 0 }, "shadow" : [ { "desired" : { "temperature" : "60" }, "service_id" : "WaterMeter" } ] }
- 响应示例
Content-Type: application/json { "app_id" : "jeQDJQZltU8iKgFFoW060F5SGZka", "app_name" : "testAPP01", "device_id" : "d4922d8a-6c8e-4396-852c-164aefa6638f", "node_id" : "ABC123456789", "gateway_id" : "d4922d8a-6c8e-4396-852c-164aefa6638f", "device_name" : "dianadevice", "node_type" : "ENDPOINT", "description" : "watermeter device", "fw_version" : "1.1.0", "sw_version" : "1.1.0", "auth_info" : { "auth_type" : "SECRET", "secure_access" : true, "fingerprint" : "dc0f1016f495157344ac5f1296335cff725ef22f", "secret" : "3b935a250c50dc2c6d481d048cefdc3c", "timeout" : 300 }, "product_id" : "b640f4c203b7910fc3cbd446ed437cbd", "product_name" : "Thermometer", "status" : "INACTIVE", "create_time" : "20190303T081011Z", "tags" : [ { "tag_value" : "testTagValue", "tag_key" : "testTagName" } ], "extension_info" : { "aaa" : "xxx", "bbb" : 0 } }
- 接口信息
- 根据响应确认设备创建结果。
- 使用这里记录的“app_id”和这里记录的“product_id”创建设备。
父主题: 应用示例