【发布时间】:2017-10-04 12:51:59
【问题描述】:
我在 Azure IOT Hub 中使用 Azure Device Twin,这个问题与 Device Twin 行为有关。
我有一个 DeviceTwin 结构如下,我使用纯 MQTT 协议向其中发布数据。
我用来发布孪生数据的主题是:$iothub/twin/PATCH/properties/reported/?$rid=c1a12cc8-4168-4e16-a1bb
我发送的有效载荷是:
{
"deviceId": "34aa078e",
"properties": {
"desired": {
},
"reported": {
"notifications": {
"notification1": {
"primaryCode": "crprim1",
"statusChangeTimestamp": 1507115005615
},
"notification2": {
"primaryCode": "crprim2",
"statusChangeTimestamp": 1507117507027
}
},
"location": {
}
}
}
}
所有功能都按照 DeviceTwin 文档中的说明正常工作,但是,关于此 DeviceTwin 的行为,我有一个澄清要澄清。
当我通过 MQTT 发送包含一个新通知(名为 notificaion3)的消息有效负载以在 DeviceTwin 上进行更新时,它只需将 notification3 添加到 notifications 对象中,而不是仅将整个 notifications 内容替换为 @ 987654326@.
我发送的 MQTT 负载:
{
"notifications": {
"notification3": {
"primaryCode": "crprim3",
"statusChangeTimestamp": 1607115005615
}
}
}
所以我最终会在 DeviceTwin 结构中得到关注,
{
"deviceId": "34aa078e",
"properties": {
"desired": {
},
"reported": {
"notifications": {
"notification1": {
"primaryCode": "crprim1",
"statusChangeTimestamp": 1507115005615
},
"notification2": {
"primaryCode": "crprim2",
"statusChangeTimestamp": 1507117507027
},
"notification3": {
"primaryCode": "crprim3",
"statusChangeTimestamp": 1607115005615
}
},
"location": {
}
}
}
}
而不是跟随,
{
"deviceId": "34aa078e",
"properties": {
"desired": {
},
"reported": {
"notifications": {
"notification3": {
"primaryCode": "crprim3",
"statusChangeTimestamp": 1607115005615
}
},
"location": {
}
}
}
}
但设备孪生应该包含给定设备的最新快照,并且不应该保留以前的数据(相对于对象级别)。 这是 Azure Device Twin 的常见行为吗?或者它是某种错误?
【问题讨论】:
标签: azure azure-iot-hub