Azure IoT中心云到设备的消息(MQTT,自定义主题) [英] Azure IoT HUB. cloud-to-device messages (MQTT, custom topics)

查看:212
本文介绍了Azure IoT中心云到设备的消息(MQTT,自定义主题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure IoT中心.在这里,我创建了一个自定义设备.该设备已成功与Azure IoT中心连接.我还可以从该设备(从设备到-cloud)接收数据.

该设备使用"MQTT协议".我无法在此设备中更改订阅主题和发布主题,因此我必须能够设置此"customtopics"在Azure(功能应用程序)中.

公共静态异步void运行(EventData myIoTHubMessage,TraceWriter日志) { log.Info($" {myIoTHubMessage.SystemProperties ["iothub-connection-device-id"]}"); var deviceId = myIoTHubMessage.SystemProperties ["iothub-connection-device-id"].ToString(); var msg = JsonConvert.SerializeObject("{\" Values \:{\"从站8.Channel 1.Output \:false,"); var c2dmsg =新的Microsoft.Azure.Devices.Message(Encoding.ASCII.GetBytes(msg)); 等待client.SendAsync(deviceId,c2dmsg); }


解决方案

https://stackoverflow .com/questions/52112397/azure-iot-hub-cloud-to-device-messages-mqtt-custom-topics

谢谢!

如果此答案有帮助,请单击标记为答案"或投票.要提供有关您的论坛体验的其他反馈,请单击 /p>


Azure IoT HUB. cloud-to-device messages (MQTT, custom topic)

I have an Azure IoT Hub. Here I created a custom device. This device is connected successfully with the Azure IoT Hub. I can also receive the data from this device (device-to -cloud).

But I also want to send a message to this device.

This device uses the "MQTT protocol". I cannot change the subscribe topic and the publish topic in this device, so I have to be able to set this "customtopics" in Azure (Function App).

For this, I have created a function App (IoT Hub (Event Hub)), but I do not know how to implement the "publish and/or subscribe topic" here. All examples are about "messages/events".

run.csx

public static async void Run(EventData myIoTHubMessage, TraceWriter log) { log.Info($"{myIoTHubMessage.SystemProperties["iothub-connection-device-id"]}"); var deviceId = myIoTHubMessage.SystemProperties["iothub-connection-device-id"].ToString(); var msg = JsonConvert.SerializeObject("{\"Values\": {\"Slave 8.Channel 1.Output\": false,"); var c2dmsg = new Microsoft.Azure.Devices.Message(Encoding.ASCII.GetBytes(msg)); await client.SendAsync(deviceId, c2dmsg); }


解决方案

E75 thank you for your feedback!

I see that the same question was asked on Stack Overflow, and an answer already provided. Let's point this to the SO Thread. If you have further questions let us know?

Answered: https://stackoverflow.com/questions/52112397/azure-iot-hub-cloud-to-device-messages-mqtt-custom-topics

Thank you!

==========================================================

If this answer was helpful, click "Mark as Answer" or Up-Vote. To provide additional feedback on your forum experience, click here


这篇关于Azure IoT中心云到设备的消息(MQTT,自定义主题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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