我代表硬件开发人员问这个问题(我对设备方面的了解不多)。
由于某些原因,由于计划将数据本地存储在设备中并每30分钟发送一次,目前IoT中心每2分钟从设备接收一次数据。但是问题是,数据没有保存到存储中。 2分钟的数据将保存到存储中。但是30分钟的数据不是 正确保存到存储中。仅保存数组中的第一个对象。
我正在使用流分析来处理来自IoT中心的数据,并将数据存储到表存储中。
当前消息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]
答案 0 :(得分:1)
最终得到它。 有几点: 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
最终结果如下:
尝试并让我知道是否有帮助。