首页 > 解决方案 > 如何在 Microsoft Azure 流分析上从多个设备中分离数据

问题描述

我目前正在尝试将 2 个不同的设备连接到 IoT 中心,我需要将数据与每个设备分开。为此,我尝试像这样配置我的流分析查询:

SELECT
    deviceId, temperature, humidity, CAST(iothub.EnqueuedTime AS datetime) AS event_date
INTO
    NodeMCUOutput
FROM
    iothubevents
WHERE
    deviceId = "NodeMCU1"

但是,由于某种原因,如果 WHERE 语句在代码中,则不会显示输出(没有显示输出,但未过滤数据)。我需要 WHERE 语句才能按照我想要的方式对数据进行排序。我错过了什么吗?有什么解决办法吗?非常感谢。干杯!

标签: azurepowerbiazure-functionsazure-iot-hubazure-stream-analytics

解决方案


消息本身中不包含的设备 ID 和其他属性作为元数据包含在消息中。GetMetadataPropertyValue()您可以使用该函数读取该元数据。这应该适合你:

SELECT
    GetMetadataPropertyValue(iothubevents, 'IoTHub.ConnectionDeviceId') as deviceId, 
    temperature, 
    humidity, 
    CAST(GetMetadataPropertyValue(iothubevents, 'IoTHub.EnqueuedTime') AS datetime) AS event_date
INTO
    NodeMCUOutput
FROM
    iothubevents
WHERE 
    GetMetadataPropertyValue(iothubevents, 'IoTHub.ConnectionDeviceId') = 'NodeMCU1'

推荐阅读