0

我有一个 Azure IOT 解决方案,其中来自 2 个设备的数据进入同一个 IOT 集线器。在我的计算机上,我只需要从其中一个设备中读取消息。我在https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-node-node-getstarted中实现了 ReadDeviceToCloudMessages.js

var client = EventHubClient.fromConnectionString(connectionString);
client.open()
.then(client.getPartitionIds.bind(client))
.then(function (partitionIds) {
    return partitionIds.map(function (partitionId) {
        return client.createReceiver('todevice', partitionId, { 'startAfterTime' : Date.now()}).then(function(receiver) {
            console.log('Created partition receiver: ' + partitionId)
            receiver.on('errorReceived', printError);
            receiver.on('message', printMessage);
        });
    });
})
.catch(printError);

但我收到了 IOThub 中的所有消息。如何仅从一台设备获取消息。

4

1 回答 1

0

您可以将预期的设备消息路由到内置端点:事件。然后您只能从上述代码中接收选定的设备消息。

创建路线

在此处输入图像描述

打开“不匹配任何规则的设备消息将被写入'事件(消息/事件)'端点。” 关闭并确保路由已启用。

在此处输入图像描述

于 2018-02-21T04:13:36.857 回答