你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Twin class
设备孪生是描述 Azure IoT 中心存储的设备的状态的文档,即使设备处于脱机状态,也可用。 它大约构建了 3 个部分:
- 标记:键/值对仅可从服务端访问
- 所需属性:由服务更新并由设备接收
- 报告的属性:由设备更新,并由服务接收。
请注意,尽管这是一种可能性,但所需属性和报告属性不必匹配,并且需要将这两个集合同步的逻辑留给 SDK 的用户。
有关详细信息,请参阅 了解设备孪生。
获取特定设备的 Twin 的建议方法是使用 getTwin(string, HttpResponseCallback<Twin>) 方法。
构造函数
Twin(string | Device |
实例化新的 Twin。 获取新 Twin 对象的建议方法是使用 getTwin(string, HttpResponseCallback<Twin>) 方法。 |
属性
device |
与孪生关联的设备标识的唯一标识符,因为它存在于设备标识注册表中。 |
etag | 在乐观并发中使用的标记,以避免设备孪生的多个并行版本。 |
model |
与孪生关联的设备标识的模型 ID,因为它存在于设备标识注册表中。 |
module |
与孪生关联的模块的模块标识符,因为它存在于设备标识注册表中。 |
properties | 所需属性和报告的属性日记(分别在 |
tags | 键/值对的集合,这些键/值对仅在服务端可用,可用于查询来查找特定设备。 |
方法
get() | |
get(Incoming |
从 IoT 中心服务获取此设备孪生的最新版本。 |
toJSON() | |
update(any) | |
update(any, Incoming |
使用作为参数提供的修补程序更新设备孪生。 |
构造函数详细信息
Twin(string | DeviceIdentity, Registry)
实例化新的 Twin。 获取新 Twin 对象的建议方法是使用 getTwin(string, HttpResponseCallback<Twin>) 方法。
new Twin(device: string | DeviceIdentity, registryClient: Registry)
参数
- device
-
string | DeviceIdentity
描述设备的设备标识符字符串或对象。 如果对象,它必须包含 deviceId 属性。
- registryClient
- Registry
用于执行 REST API 调用的 HTTP 注册表客户端。
属性详细信息
deviceId
与孪生关联的设备标识的唯一标识符,因为它存在于设备标识注册表中。
deviceId: string
属性值
string
etag
在乐观并发中使用的标记,以避免设备孪生的多个并行版本。
etag: string
属性值
string
modelId
与孪生关联的设备标识的模型 ID,因为它存在于设备标识注册表中。
modelId?: string
属性值
string
moduleId
与孪生关联的模块的模块标识符,因为它存在于设备标识注册表中。
moduleId?: string
属性值
string
properties
所需属性和报告的属性日记(分别在 properties.desired
和 properties.reported
)。
properties: { desired: {[key: string]: any}, reported: {[key: string]: any} }
属性值
{ desired: {[key: string]: any}, reported: {[key: string]: any} }
tags
键/值对的集合,这些键/值对仅在服务端可用,可用于查询来查找特定设备。
tags: {[key: string]: string}
属性值
{[key: string]: string}
方法详细信息
get()
function get(): Promise<ResultWithIncomingMessage<Twin>>
返回
Promise<ResultWithIncomingMessage<Twin>>
get(IncomingMessageCallback<Twin>)
从 IoT 中心服务获取此设备孪生的最新版本。
function get(done?: IncomingMessageCallback<Twin>)
参数
toJSON()
function toJSON(): object
返回
object
update(any)
function update(patch: any): Promise<ResultWithIncomingMessage<Twin>>
参数
- patch
-
any
返回
Promise<ResultWithIncomingMessage<Twin>>