是否可以将大 JSON 数据发送到 IoT 中心?
Is it possible to send large JSON data to IoT Hub?
我代表硬件开发人员问这个问题(我对设备方面的知识不多)。
现在 IoT 中心每 2 分钟从设备接收一次数据,由于某些原因计划将数据存储在设备本地并每 30 分钟发送一次。但问题是,数据没有保存到存储中。 2 分钟的数据正在保存到存储器中。但是30分钟的数据不是
正确保存到存储中。仅保存数组中的第一个对象。
我正在使用流分析处理来自 IoT 中心的数据并将数据存储到 table 存储。
当前消息 Json 数据(每 2 分钟)为:
{
"deviceid": "testdevice12",
"BatteryVoltage": "31.31",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.29",
"OutputCurrent": "4.94",
"RSSI": "13",
"FreeHeapSize": "86.884",
"timestamp": 1540470493
}
30 分钟后将如下所示:
[{
"deviceid": "testdevice12",
"BatteryVoltage": "31.31",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.29",
"OutputCurrent": "4.94",
"RSSI": "13",
"FreeHeapSize": "86.884",
"timestamp": 1540470493
}, {
"deviceid": "testdevice12",
"BatteryVoltage": "31.29",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.28",
"OutputCurrent": "4.93",
"RSSI": "0",
"FreeHeapSize": "86.884",
"timestamp": 1540470558
}, {
"deviceid": "testdevice12",
"BatteryVoltage": "31.30",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.29",
"OutputCurrent": "4.94",
"RSSI": "5",
"FreeHeapSize": "86.884",
"timestamp": 1540470621
}, {
"deviceid": "testdevice12",
"BatteryVoltage": "31.31",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.30",
"OutputCurrent": "4.94",
"RSSI": "5",
"FreeHeapSize": "86.884",
"timestamp": 1540470684
}, {
"deviceid": "testdevice12",
"BatteryVoltage": "31.30",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.28",
"OutputCurrent": "4.94",
"RSSI": "7",
"FreeHeapSize": "86.884",
"timestamp": 1540470760
}]
这是我正在使用的 ASA 查询:
WITH [StreamData] AS ( SELECT * FROM [IoTHubStream] WHERE [ObjectType] IS NULL -- Filter out device info and command responses )
SELECT IoTHub.ConnectionDeviceId AS DeviceId, PanelVoltage, PanelCurrent, BatteryVoltage, BatteryCurrent, OutputVoltage, OutputCurrent, Temperature, Humidity, EventProcessedUtcTime, PartitionId, EventEnqueuedUtcTime, * INTO [DeviceDataHistory] FROM [StreamData]
终于明白了。
有几点:
1. JSON 具有缓存数据结构的有效负载应具有如下结构:
{
"topic": "cachedData",
"deviceId": "testdevice12",
"data":
[{
"BatteryVoltage": "31.31",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.29",
"OutputCurrent": "4.94",
"RSSI": "13",
"FreeHeapSize": "86.884",
"timestamp": 1540470493
}, {
"BatteryVoltage": "31.29",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.28",
"OutputCurrent": "4.93",
"RSSI": "0",
"FreeHeapSize": "86.884",
"timestamp": 1540470558
}, {
"BatteryVoltage": "31.30",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.29",
"OutputCurrent": "4.94",
"RSSI": "5",
"FreeHeapSize": "86.884",
"timestamp": 1540470621
}, {
"BatteryVoltage": "31.31",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.30",
"OutputCurrent": "4.94",
"RSSI": "5",
"FreeHeapSize": "86.884",
"timestamp": 1540470684
}, {
"BatteryVoltage": "31.30",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.28",
"OutputCurrent": "4.94",
"RSSI": "7",
"FreeHeapSize": "86.884",
"timestamp": 1540470760
}]
}
Azure 流分析应如下所示:
SELECT
iothubAlias.deviceId,
arrayElement.ArrayValue.BatteryVoltage,
arrayElement.ArrayValue.PanelVoltage,
arrayElement.ArrayValue.PanelCurrent,
arrayElement.ArrayValue.OutputVoltage,
arrayElement.ArrayValue.OutputCurrent,
arrayElement.ArrayValue.RSSI,
arrayElement.ArrayValue.FreeHeapSize,
arrayElement.ArrayValue.timestamp
INTO [DeviceDataHistory]
FROM [IoTHubStream] as iothubAlias
CROSS APPLY GetArrayElements(iothubAlias.data) AS arrayElement
要从输入中检索多行,您必须使用 "GetArrayElements" - 您可以在此处阅读更多内容:
https://docs.microsoft.com/en-us/azure/stream-analytics/stream-analytics-parsing-json
- 记得为 Azure Table 设置 PartitionKey 和 RowKey 设置为 Azure 流分析的输出:
最终结果如下所示:
尝试告诉我是否有帮助。
我代表硬件开发人员问这个问题(我对设备方面的知识不多)。
现在 IoT 中心每 2 分钟从设备接收一次数据,由于某些原因计划将数据存储在设备本地并每 30 分钟发送一次。但问题是,数据没有保存到存储中。 2 分钟的数据正在保存到存储器中。但是30分钟的数据不是 正确保存到存储中。仅保存数组中的第一个对象。
我正在使用流分析处理来自 IoT 中心的数据并将数据存储到 table 存储。
当前消息 Json 数据(每 2 分钟)为:
{
"deviceid": "testdevice12",
"BatteryVoltage": "31.31",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.29",
"OutputCurrent": "4.94",
"RSSI": "13",
"FreeHeapSize": "86.884",
"timestamp": 1540470493
}
30 分钟后将如下所示:
[{
"deviceid": "testdevice12",
"BatteryVoltage": "31.31",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.29",
"OutputCurrent": "4.94",
"RSSI": "13",
"FreeHeapSize": "86.884",
"timestamp": 1540470493
}, {
"deviceid": "testdevice12",
"BatteryVoltage": "31.29",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.28",
"OutputCurrent": "4.93",
"RSSI": "0",
"FreeHeapSize": "86.884",
"timestamp": 1540470558
}, {
"deviceid": "testdevice12",
"BatteryVoltage": "31.30",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.29",
"OutputCurrent": "4.94",
"RSSI": "5",
"FreeHeapSize": "86.884",
"timestamp": 1540470621
}, {
"deviceid": "testdevice12",
"BatteryVoltage": "31.31",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.30",
"OutputCurrent": "4.94",
"RSSI": "5",
"FreeHeapSize": "86.884",
"timestamp": 1540470684
}, {
"deviceid": "testdevice12",
"BatteryVoltage": "31.30",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.28",
"OutputCurrent": "4.94",
"RSSI": "7",
"FreeHeapSize": "86.884",
"timestamp": 1540470760
}]
这是我正在使用的 ASA 查询:
WITH [StreamData] AS ( SELECT * FROM [IoTHubStream] WHERE [ObjectType] IS NULL -- Filter out device info and command responses )
SELECT IoTHub.ConnectionDeviceId AS DeviceId, PanelVoltage, PanelCurrent, BatteryVoltage, BatteryCurrent, OutputVoltage, OutputCurrent, Temperature, Humidity, EventProcessedUtcTime, PartitionId, EventEnqueuedUtcTime, * INTO [DeviceDataHistory] FROM [StreamData]
终于明白了。 有几点: 1. JSON 具有缓存数据结构的有效负载应具有如下结构:
{
"topic": "cachedData",
"deviceId": "testdevice12",
"data":
[{
"BatteryVoltage": "31.31",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.29",
"OutputCurrent": "4.94",
"RSSI": "13",
"FreeHeapSize": "86.884",
"timestamp": 1540470493
}, {
"BatteryVoltage": "31.29",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.28",
"OutputCurrent": "4.93",
"RSSI": "0",
"FreeHeapSize": "86.884",
"timestamp": 1540470558
}, {
"BatteryVoltage": "31.30",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.29",
"OutputCurrent": "4.94",
"RSSI": "5",
"FreeHeapSize": "86.884",
"timestamp": 1540470621
}, {
"BatteryVoltage": "31.31",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.30",
"OutputCurrent": "4.94",
"RSSI": "5",
"FreeHeapSize": "86.884",
"timestamp": 1540470684
}, {
"BatteryVoltage": "31.30",
"PanelVoltage": "0.00",
"PanelCurrent": "0.00",
"OutputVoltage": "31.28",
"OutputCurrent": "4.94",
"RSSI": "7",
"FreeHeapSize": "86.884",
"timestamp": 1540470760
}]
}
Azure 流分析应如下所示:
SELECT iothubAlias.deviceId, arrayElement.ArrayValue.BatteryVoltage, arrayElement.ArrayValue.PanelVoltage, arrayElement.ArrayValue.PanelCurrent, arrayElement.ArrayValue.OutputVoltage, arrayElement.ArrayValue.OutputCurrent, arrayElement.ArrayValue.RSSI, arrayElement.ArrayValue.FreeHeapSize, arrayElement.ArrayValue.timestamp INTO [DeviceDataHistory] FROM [IoTHubStream] as iothubAlias CROSS APPLY GetArrayElements(iothubAlias.data) AS arrayElement
要从输入中检索多行,您必须使用 "GetArrayElements" - 您可以在此处阅读更多内容:
https://docs.microsoft.com/en-us/azure/stream-analytics/stream-analytics-parsing-json
- 记得为 Azure Table 设置 PartitionKey 和 RowKey 设置为 Azure 流分析的输出:
最终结果如下所示:
尝试告诉我是否有帮助。