gpt4 book ai didi

c - Azure IoT SDK - 检查设备是否已注册

转载 作者:行者123 更新时间:2023-12-03 05:36:02 26 4
gpt4 key购买 nike

我在我的设备上使用 Azure IoT C SDK。

我的应用程序按照示例代码 prov_dev_client_ll_sample.c 进行配置,但之后,还按照示例代码 iothub_client_device_twin_and_methods_sample 通过 MQTT 处理与其在云上的孪生体的通信。 c .

理想情况下,我想配置逻辑应该只在设备第一次启动并在门户上注册时执行,而不是每次启动时执行。

是否有一种方法/功能可以在执行配置逻辑之前检查设备是否已在门户上注册?

我想执行配置逻辑不会造成太大伤害,因为它发现设备已经在门户上注册了?

最佳答案

您可以使用REST API - Device Registration Status Lookup获取设备注册状态。

以下是 IoT Central 应用程序底层 IoT 中心 (iotcScopeId = 0ne11111111) 中 device10 注册状态的 POST 请求示例:

请求发布:

  https://global.azure-devices-provisioning.net/0ne11111111/registrations/device10?api-version=2019-03-31

标题:

  Authorization: sas

其中 sas token 可以通过以下函数生成(更多详细信息 here ):

 string sas = SharedAccessSignatureBuilder.GetSASToken($"{iotcScopeId}/registrations/{deviceId}", deviceKey, "registration");

有效负载:

 {
"registrationId":"device10"
}

回复:

{
"registrationId":"device10",
"createdDateTimeUtc":"2020-06-20T12:38:45.451863Z",
"assignedHub":"iotc-xxxxxxx.azure-devices.net",
"deviceId":"device10",
"status":"assigned",
"substatus":"initialAssignment",
"lastUpdatedDateTimeUtc":"2020-06-20T12:38:45.6268772Z",
"etag":"xxxxx"
}

如果设备不存在,则响应为:

 {
"errorCode": 404202,
"trackingId": "481a4060-37c1-40e2-8a23-d225e49781c6",
"message": "Registration not found.",
"timestampUtc": "2020-06-20T12:36:43.8782738Z"
}

关于c - Azure IoT SDK - 检查设备是否已注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62484063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com