0

我有一个带有许多传感器的设备,需要不同类型的聚合,我的问题分为两部分。该设备通过 Azure IoT 中心进行通信,然后转到 Azure 流分析到 SQL DB 和 Power BI。

1) 传输数据的最佳方式是什么?每个传感器(sensor1、sensor2、.)和 DateTime 的列或 DeviceId、DateTime、SensorNumber 和 SensorValue 的列?传感器名称、触发值等更多信息通过参考表添加。这些方法的优点或缺点是什么?

2) ASA 中所需的某些聚合为 MAX,而其他聚合为 AVERAGE,这取决于通过参考表链接到设备每个通道的传感器类型而变化。例如,传感器类型“Switch”需要 MAX 聚合,而传感器类型“Temp”需要 AVERAGE 聚合。您能否根据通过 ref 表链接的不同 SensorType 字段将聚合类型从一个输入(IoTHub)更改为一个输出(SQL)?

任何帮助,将不胜感激。

4

1 回答 1

0
  1. 最好使用 SensorId、SensorValue,因为您可能不会一直拥有来自所有传感器的值。此外,当您拥有新的 sensorId 时,有效负载不会改变。
  2. 可以使用参考数据来做到这一点。但是,如果它只是一个不同的聚合,您也可以一直计算平均值和最大值,并根据 SQL 端或 power bi 端的传感器类型选择合适的。

如果它比聚合类型更复杂,参考数据更好。以下是使用参考数据的方法

create table iotInput
(
    SensorId nvarchar(max),
    SensorValue bigint,
    Measurementtime datetime
)

create table refData
(
    SensorId nvarchar(max),
    IsMaxAggregate bigint
)

select
    System.Timestamp [Aggregationtime],
    iotInput.SensorId,
    refData.IsMaxAggregate,
    case when refData.IsMaxAggregate = 1 
        then max(iotInput.SensorValue) 
     else 
        avg(iotInput.SensorValue) end [Aggregate]
from
    iotInput timestamp by [MeasurementTime]
join
    refData
on
    iotInput.SensorId = refData.SensorId
group by
    iotInput.SensorId,
    refData.IsMaxAggregate,
    tumblingwindow(second,5)
于 2016-06-18T20:03:21.550 回答