创建设备
功能介绍
创建设备。
调试
您可以在API Explorer中调试该接口,支持自动认证鉴权。API Explorer可以自动生成SDK代码示例,并提供SDK代码示例调试功能。
URI
POST /v2/{project_id}/link/instances/{instance_id}/devices
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID。兼容20.0场景默认为default。项目ID,获取方式请参见API参考的“附录 > 获取项目ID”章节。 |
instance_id |
是 |
String |
实例的ID。兼容20.0场景默认为default。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
parent_device_id |
否 |
Integer |
父设备ID,无父设备时不填写,自动向下取整。 |
product |
是 |
ProductReferer object |
产品。 |
password |
否 |
String |
设备密码,输入要求:至少1数字,1大写字母,1小写字母,1特殊字符(~!@#$%^&*()-_=+|[{}];:<>/?),长度8-32个字符。 |
user_name |
否 |
String |
设备用户名,支持英文大小写、英文符号(-)及数字,长度10-50。 |
device_name |
是 |
String |
设备名称,支持中文、中文标点符号()。;,:“”、?《》及英文大小写、数字及英文符号()_,#.?'-@%&!, 长度2-64。 |
node_id |
是 |
String |
设备物理编号,通常使用MAC或者IMEI号,支持英文大小写、数字、下划线和中划线,长度2-64。 |
app_id |
是 |
String |
应用ID。 |
status |
否 |
Integer |
设备状态,0-启用 1-禁用,不填时默认为0启用。 |
description |
否 |
String |
备注。 |
tags |
否 |
Array of strings |
标签。 |
groups |
否 |
Array of integers |
设备所属设备分组的ID |
fingerprint |
否 |
String |
证书指纹 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
product_id |
否 |
Integer |
产品ID,未填写厂商ID+型号时产品ID必填。 |
product_name |
否 |
String |
产品名称。 |
manufacturer_id |
否 |
String |
厂商ID,未填写产品ID时厂商ID和型号必填。 |
model |
否 |
String |
型号,未填写产品ID时厂商ID和型号必填。 |
protocol_type |
否 |
Integer |
产品的协议类型:0-mqtt,1-CoAP,2-modbus,4-opcua,5-扩展协议。 |
product_type |
否 |
Integer |
产品类型:0-普通产品,1-网关产品。 |
extend_protocol_name |
否 |
String |
扩展协议名称。 |
响应参数
状态码: 201
参数 |
参数类型 |
描述 |
---|---|---|
permissions |
Array of strings |
权限。 |
id |
Integer |
设备ID |
device_id |
Integer |
设备ID(兼容20.0)。 |
product |
ProductReferer object |
产品。 |
device_name |
String |
设备名称,支持中文、中文标点符号()。;,:“”、?《》及英文大小写、数字及英文符号()_,#.?'-@%&!, 长度2-64。 |
instance_id |
String |
实例ID。 |
client_id |
String |
设备客户端ID,平台生成的设备唯一标识。 |
node_id |
String |
设备物理编号,通常使用MAC或者IMEI号,支持英文大小写,数字,下划线和中划线,长度2-64。 |
app_name |
String |
应用名称。 |
status |
Integer |
设备状态,0-启用,1-禁用。 |
online_status |
Integer |
是否在线,0-未连接,1-在线,2-离线。 |
description |
String |
备注。 |
authentication |
Authentication object |
鉴权。 |
created_user |
CreatedUser object |
创建时的用户。 |
last_updated_user |
LastUpdatedUser object |
最后更新时的用户。 |
tags |
Array of strings |
标签。 |
created_datetime |
Long |
创建时间,timestamp(ms),使用UTC时区。 |
last_updated_datetime |
Long |
最后修改时间,timestamp(ms),使用UTC时区。 |
connect_address |
String |
设备接入地址。 |
ssl_connect_address |
String |
设备接入SSL地址。 |
ipv6_connect_address |
String |
设备接入IPv6地址,在开启IPv6时生效。 |
ipv6_ssl_connect_address |
String |
设备接入IPv6 SSL地址,在开启IPv6时生效。 |
node_type |
Integer |
节点类型,0-直连,1-网关,2-子设备。 |
device_type |
Integer |
设备类型。
|
app_id |
String |
应用ID。 |
groups |
Array of integers |
设备所属设备分组的ID |
group_names |
Array of strings |
设备所属设备分组的名称 |
fingerprint |
String |
证书指纹 |
参数 |
参数类型 |
描述 |
---|---|---|
product_id |
Integer |
产品ID,未填写厂商ID+型号时产品ID必填。 |
product_name |
String |
产品名称。 |
manufacturer_id |
String |
厂商ID,未填写产品ID时厂商ID和型号必填。 |
model |
String |
型号,未填写产品ID时厂商ID和型号必填。 |
protocol_type |
Integer |
产品的协议类型:0-mqtt,1-CoAP,2-modbus,4-opcua,5-扩展协议。 |
product_type |
Integer |
产品类型:0-普通产品,1-网关产品。 |
extend_protocol_name |
String |
扩展协议名称。 |
参数 |
参数类型 |
描述 |
---|---|---|
user_name |
String |
一型一密/一机一密的用户名。 |
password |
String |
一型一密/一机一密的密码,输入要求:至少1个数字,1个大写字母,1个小写字母,1个特殊字符(~!@#$%^&*()-_=+|[{}];:<>/?),长度8-32个字符 |
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
系统错误码,针对4xx和5xx类HTTP错误码的详细错误码。 |
error_msg |
String |
错误描述。 |
request_id |
String |
消息ID。 |
状态码: 404
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
系统错误码,针对4xx和5xx类HTTP错误码的详细错误码。 |
error_msg |
String |
错误描述。 |
request_id |
String |
消息ID。 |
状态码: 500
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
系统错误码,针对4xx和5xx类HTTP错误码的详细错误码。 |
error_msg |
String |
错误描述。 |
request_id |
String |
消息ID。 |
请求示例
创建一个设备,协议类型为MQTT,产品类型为普通产品,设备状态为启用。
{
"parent_device_id" : 10001,
"product" : {
"product_id" : 10001,
"product_name" : "testproduct",
"manufacturer_id" : "test",
"model" : "mate30pro",
"protocol_type" : 0,
"product_type" : 0
},
"password" : "**********",
"device_name" : "device",
"node_id" : "D32145A100FF",
"app_id" : "ef3845be-091a-4ab5-869a-9de0025e2165",
"status" : 0,
"description" : "device",
"tags" : [ "tag1", "tag2" ]
}
响应示例
状态码: 201
Created
{
"permissions" : [ "read", "access", "delete", "modify" ],
"id" : 711537,
"device_id" : 711537,
"parent_device_id" : 711536,
"parent_device_name" : "parent-device",
"product" : {
"product_id" : 116303,
"product_name" : "p1",
"manufacturer_id" : "p1",
"model" : "p1",
"product_type" : 0,
"protocol_type" : 0
},
"device_name" : "device",
"instance_id" : "8993a690-cf61-46af-880d-587d823d14e5",
"client_id" : "D116303711537sGDtK",
"node_id" : "string",
"app_name" : "app",
"status" : 0,
"online_status" : 2,
"description" : "device",
"authentication" : {
"user_name" : "F01A8D25FE6E4CF5A286B711B31888AE",
"password" : "************************"
},
"created_user" : {
"user_id" : "",
"user_name" : "user"
},
"last_updated_user" : {
"user_id" : "",
"user_name" : "user"
},
"tags" : [ ],
"created_datetime" : 1607408244841,
"last_updated_datetime" : 1607422571094,
"connect_address" : "xx.xx.xx.xx",
"ssl_connect_address" : "xx.xx.xx.xx",
"ipv6_connect_address" : "xx.xx.xx.xx",
"ipv6_ssl_connect_address" : "xx.xx.xx.xx",
"node_type" : 0,
"device_type" : 0,
"app_id" : "cb4b3ec0-8f7f-432f-b05e-fc149d05da5d"
}
状态码: 400
Bad Request
{
"error_code" : "SCB.00000000",
"error_msg" : "Parameter is not valid for operation [romalink.link-device.save]. Parameter is [parent_device_id]. Processor is [body].",
"request_id" : "cb39e78a-afd3-4e04-901d-70468b1c23dc-1619602712496-cnnorth7a-P-romalink-service01"
}
状态码: 404
Not Found
{
"error_code" : "ROMA.00110006",
"error_msg" : "The resource does not exist. Check whether the resource ID ff38023c-0854-4779-847d-72528e1f5da1 is correct.",
"request_id" : "624c8be1-39b6-47b7-941d-c159aced368a-1619602544650-cnnorth7a-P-romalink-service01"
}
状态码: 500
Internal Server Error
{
"error_code" : "ROMA.00110002",
"error_msg" : "The instance does not exist. project_id: 397cd10b30544c588b2f4a56d83856c4, instance_id: f3bb386a-23ec-47aa-9943-4c60ac658611",
"request_id" : "c8c06d0a-be92-4fdf-9d10-bc20131ab158-1619593104919-cnnorth7a-P-romalink-service01"
}
状态码
状态码 |
描述 |
---|---|
201 |
Created |
400 |
Bad Request |
404 |
Not Found |
500 |
Internal Server Error |
错误码
请参见错误码。