使用 HTTP POST 请求将遥测消息发送到 Azure IoT Central 设备
我正在尝试使用 HTTP POST 请求将遥测数据发送到 Azure IoT Central 中的设备。
类似的 Rest API 可用于 Azure IoT 中心 - https://learn.microsoft.com/en-us/rest/api/iothub/device/send-device-event
我能够使用此网站提取 Azure IoT Central 背后的 IoT 中心资源 URL - <一href="https://dpsgen.z8.web.core.windows.net/" rel="nofollow noreferrer">https://dpsgen.z8.web.core.windows.net/
它需要范围我们从 Azure IoT Central 获取的 ID、设备 ID 和设备主键。它为您提供 IoT 中心连接字符串
HostName=iotc-<
使用上述 IoT 中心主机名,我尝试了 IoT 中心发送设备事件 Rest API。它因未经授权的错误而失败。
我正在使用从 Azure IoT Central 应用程序中的以下路径生成的 SAS 令牌
Azure IoT 中心 ->权限-> API 令牌 -> “应用程序管理员”角色
任何帮助都会有用。
I'm trying to send telemetry to a device in Azure IoT Central with an HTTP POST request.
Similar Rest API is available for Azure IoT Hub - https://learn.microsoft.com/en-us/rest/api/iothub/device/send-device-event
I was able to extract the IoT Hub resource URL behind the Azure IoT Central using this website - https://dpsgen.z8.web.core.windows.net/
It takes Scope Id, Device Id and Device Primary Key that we get from Azure IoT Central. It gives you the IoT Hub connection string,
HostName=iotc-<<unique-iot-hub-id>>.azure-devices.net;DeviceId=<<device-id>>;SharedAccessKey=<<device-primary-key>>
Using the above IoT Hub host-name, I tried IoT Hub send device event Rest API. It is failing with an Unauthorized error.
I am using SAS token generated from the below path within the Azure IoT Central application
Azure IoT Central -> Permissions -> API tokens -> "App Administrator" Role
Any help will be useful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看我的 answer 其中详细描述了如何生成连接信息以使用 REST Post 请求将遥测数据发送到 Azure IoT Central 应用程序。
以下是更新的 Azure 函数,用于生成请求的设备连接信息:
Have a look at my answer where is described in details how to generate a connection info for sending a telemetry data to the Azure IoT Central App using a REST Post request.
The following is an updated azure function to generate a requested device connection info:
IoT Central API 令牌用于管理应用程序功能,不能由设备使用。在 IoT Central 中选择设备,然后单击顶部的“连接”菜单,使用该设备显示的主键。
附带说明一下,尽管 https 支持设备,但由于其轮询性质,它不太适合 IoT,并且不支持设备孪生所需或报告的属性。 https://learn.microsoft。 com/en-us/azure/iot-hub/iot-hub-devguide-d2c-guidance
IoT Central 提供内置高可用性,底层 IoTHub 名称可以更改,因此需要手动获取不建议使用 IoTHub 名称。始终拨打 DPS 来检索 IoTHub 名称、第一次、定期或出现错误情况。
The IoT Central API token is to manage the application functionality and cannot be used by the device. Select the device in IoT Central and click on the "Connect" menu at the top, use the primary key shown for that device.
As a side note, https although supported for devices is not well suited for IoT due to its polling nature and does not support device twin desired or reported properties. https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-d2c-guidance
IoT Central provides built-in high availability, the underlying IoTHub name can change, so manually getting the IoTHub name is not recommended. Always make call DPS to retrieve IoTHub name, the first time and periodically or error conditions.