简体   繁体   English

云到设备的Azure IoT REST API

[英]Cloud-to-device Azure IoT REST API

I explored on sending data from Device to Cloud using Azure REST Apis. 我探索了使用Azure REST Apis将数据从设备发送到云的过程。 It is working seamlessly without any issues. 它正在无缝运行,没有任何问题。 I'm not finding good articles on sending Cloud-to-Device messages to Arduino board using "Azure IoT Hub REST Apis". 我找不到有关使用“ Azure IoT中心REST Apis”将云到设备消息发送到Arduino板的好文章。 Could some one provide suggestions on this 有人可以对此提供建议吗

As Peter Pan said, there isn't a RESTful API for send C2D messages currently . 正如Peter Pan所说, 目前没有用于发送C2D消息的RESTful API However, you still have some other chooses. 但是,您还有其他选择。

  1. Use Azure Function App . 使用Azure Function应用 You can create a HTTP trigger Azure Function App to use as RESTful proxy, and run IoT Hub SDK on Azure Function App to send C2D messages. 您可以创建HTTP触发器Azure Function App用作RESTful代理,并在Azure Function App上运行IoT中心SDK发送C2D消息。

  2. Use AMQP over WebSockets with 443 port if you cannot use 5671 port for AMQP to connect to IoT Hub on your service side. 如果您不能使用5671端口将AMQP连接到服务端的IoT中心,请具有443端口的WebSocket使用AMQP We have developed a web based IoT Hub devtool based on Rhea , and you can reference our code. 我们已经开发了基于 Rhea的基于Web的IoT中心devtool ,您可以参考我们的代码。

You could also send the request as the azure portal does it. 您也可以在Azure门户执行请求时发送请求。 All C2D from AZ Portal are sent through this Endpoint https://main.iothub.ext.azure.com/api/Service/SendMessage/ and the payload is a json that look like this: AZ Portal的所有C2D都通过此端点https://main.iothub.ext.azure.com/api/Service/SendMessage/发送,并且有效负载是一个类似于以下内容的json:

{
  "hostName": "iothub-hostname",
  "owner": "twinUpdate",
  "key": "key for the iothub",
  "deviceID": "your device on that hub",
  "body": "{\"test\": \"This is a test over postman\"}",
  "properties": "[]"
}

Keep in mind that you need to add an Authorization Header with valid Bearer token. 请记住,您需要添加带有有效Bearer令牌的授权标头。 You can get this when you log in to AZ Portal. 登录到AZ Portal时可以获得此信息。

According to the offical document Send and receive messages with IoT Hub , and after I reviewed the source codes of Azure IoT Hub for sending cloud-to-device message using different languages, there is no REST API to support on sending Cloud-to-Device messages. 根据官方文档`` 使用IoT中心发送和接收消息'' ,并且在查看了Azure IoT中心用于使用不同语言发送云到设备消息的源代码之后,没有REST API支持发送云到设备消息。 To send c2d message from application to Azure IoT Hub, the recommended protocol is AMQP and the simple way is using Azure IoT Hub SDK. 要将c2d消息从应用程序发送到Azure IoT中心,推荐的协议是AMQP,简单的方法是使用Azure IoT中心SDK。 That you can refer to the section Communication protocol , as below. 您可以参考下面的“ Communication protocol ”部分。

在此处输入图片说明

However, if you want to receive the c2d message from Arduino, you can refer to the section Cloud-to-device messages and use the REST API Receive Device Bound Notification on Arduino. 但是,如果要从Arduino接收c2d消息,则可以参考“ Cloud-to-device messages并在Arduino上使用REST API Receive Device Bound Notification

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM