你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
该库提供对 IoT 中心设备更新服务的访问权限,使客户能够将 IoT 设备的更新发布到云中,然后将这些更新部署到其设备(批准 IoT 中心中托管和预配的设备组的更新)。
请严重依赖 服务的文档 和 REST 客户端文档 使用此库
关键链接:
开始
当前支持的环境
先决条件
- Microsoft Azure 订阅:若要调用 Azure 服务Microsoft,需要创建 Azure 订阅
- IoT 中心实例的设备更新
- Azure IoT 中心实例
安装 @azure-rest/iot-device-update
包
使用 npm
安装适用于 JavaScript 的 Azure Iot 设备更新客户端库:
npm install @azure-rest/iot-device-update
创建和验证 DeviceUpdate
若要使用 Azure Active Directory (AAD) 令牌凭据,请提供从 @azure/标识 库获取的所需凭据类型的实例。
若要使用 AAD 进行身份验证,必须先 npm
安装 @azure/identity
。
安装后,可以从 @azure/identity
中选择要使用的 凭据 类型。
例如,DefaultAzureCredential 可用于对客户端进行身份验证:
将 AAD 应用程序的客户端 ID、租户 ID 和客户端机密的值设置为环境变量:AZURE_CLIENT_ID、AZURE_TENANT_ID、AZURE_CLIENT_SECRET
使用返回的令牌凭据对客户端进行身份验证:
import DeviceUpdate from "@azure-rest/iot-device-update";
import { DefaultAzureCredential } from "@azure/identity";
const endpoint = "https://<my-instance-id>.api.adu.microsoft.com";
const client = DeviceUpdate(endpoint, new DefaultAzureCredential());
关键概念
REST 客户端
此客户端是我们 REST 客户端之一。 强烈建议你在此处阅读如何使用 REST 客户端 。
例子
以下部分演示如何初始化和验证客户端,然后获取所有设备。
import DeviceUpdate from "@azure-rest/iot-device-update";
import { DefaultAzureCredential } from "@azure/identity";
const endpoint = "https://<my-instance-id>.api.adu.microsoft.com";
const client = DeviceUpdate(endpoint, new DefaultAzureCredential());
const instanceId = "<my-instance-id>";
const result = await client.path("/deviceupdate/{instanceId}/management/devices", instanceId).get();
console.log(result);
故障 排除
伐木
启用日志记录可能有助于发现有关故障的有用信息。 若要查看 HTTP 请求和响应的日志,请将 AZURE_LOG_LEVEL
环境变量设置为 info
。 或者,可以通过在 @azure/logger
中调用 setLogLevel
在运行时启用日志记录:
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
有关如何启用日志的更详细说明,可以查看 @azure/记录器包文档。
后续步骤
贡献
若要参与此库,请阅读 贡献指南 了解有关如何生成和测试代码的详细信息。