Azure IoT中心-在2个主题上将消息(C2D)发送到一台设备,而不是设备绑定/# [英] Azure IoT Hub - Send message (C2D) to one device on 2 topics instead of devicebound/#

查看:87
本文介绍了Azure IoT中心-在2个主题上将消息(C2D)发送到一台设备,而不是设备绑定/#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为MQTT客户端(设备),我正在使用devices/{deviceid}/messages/devicebound/#主题来接收云到设备"消息.该设备是我的网关,并且已连接3台设备. 我想向3个不同主题的1个网关发送3个不同命令,例如

As a MQTT client (device), I am using devices/{deviceid}/messages/devicebound/# topic to receive Cloud to Device messages. This device is a gateway for me and there are 3 devices attached to it. I want to send 3 different commands to 1 gateway on 3 different topics, like

devices/{deviceid}/messages/devicebound/device1
devices/{deviceid}/messages/devicebound/device2
devices/{deviceid}/messages/devicebound/device3

我的网关已在iot-hub中注册,我在{deviceid}中使用它.

My gateway is registered in iot-hub and I use it at {deviceid}.

有可能吗?

推荐答案

基于官方文档"

Based on the official document "Communicate with your IoT hub using the MQTT protocol", it says:

由于IoT中心不是通用的发布订阅消息代理,因此它 仅支持记录的主题名称和主题过滤器.

Since IoT Hub is not a general purpose pub-sub messaging broker, it only supports the documented topic names and topic filters.

IoT Hub传递带有主题名称的消息 devices/{device_id}/messages/devicebound/,或 devices/{device_id}/messages/devicebound/{property_bag}(如果有) 任何邮件属性.

IoT Hub delivers messages with the Topic Name devices/{device_id}/messages/devicebound/, or devices/{device_id}/messages/devicebound/{property_bag} if there are any message properties.

以下是使用系统属性"messageId"作为过滤器的解决方案.因此,您的三个主题:

Here is a solution using system property "messageId" as the filter. So your three topics:

devices/{deviceid}/messages/devicebound/device1 
devices/{deviceid}/messages/devicebound/device2 
devices/{deviceid}/messages/devicebound/device3

看起来像这样:

devices/{deviceid}/messages/devicebound/%24.mid=device1&%24.to=%2Fdevices%2Ftest1%2Fmessages%2FdeviceBound&iothub-ack=full
devices/{deviceid}/messages/devicebound/%24.mid=device2&%24.to=%2Fdevices%2Ftest1%2Fmessages%2FdeviceBound&iothub-ack=full
devices/{deviceid}/messages/devicebound/%24.mid=device3&%24.to=%2Fdevices%2Ftest1%2Fmessages%2FdeviceBound&iothub-ack=full

这是测试:

从azure设备浏览器发送C2D消息:

Send C2D message from azure device explorer:

从MQTTBox接收C2D消息:

Receive C2D message from MQTTBox:

这篇关于Azure IoT中心-在2个主题上将消息(C2D)发送到一台设备,而不是设备绑定/#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆