【问题标题】:Is there any REST API to programmatically link IoT hub when creating Azure DPS?创建 Azure DPS 时,是否有任何 REST API 以编程方式链接 IoT 中心?
【发布时间】:2020-11-25 09:35:46
【问题描述】:

寻找可创建 DPS 并链接到现有 IoT 中心的 REST Api。我看到我们可以通过 Azure CLI 进行操作,但要查找 REST Api 调用,因为我的 Web 应用程序(Azure 应用程序服务)需要首先创建 Iot 集线器,然后在创建 DPS 时将其用作链接。 目前使用这样的创建 DPS:

   var mydps = new {
                location = "East US", 
                type = "Microsoft.Devices/ProvisioningServices",
            };

   var content = new StringContent(JsonConvert.SerializeObject(mydps), Encoding.UTF8, "application/json");
   var requestUri = string.Format(webOptions.CreateDpsUri, someSubscriptionID, someRsourceGroupgName, somedpsName );  
   var result = await httpClient.PutAsync(requestUri, content);

看到这个未解决的问题Support for linking an IoT Hub to an existing DPS 因为它说“目前您只能在 DPS 资源创建(或更新您的 DPS 资源创建代码)期间链接集线器。”但在上述 DPS Create REST API 调用期间,我看不到设置 IoT 中心的选项。

发送一些参数链接 connectionString 属性是否可以完成工作或其他事情,因为我没有看到任何与使用 REST 调用在 DPS 创建中链接物联网集线器相关的文档?

如果 REST api 尚不支持,我有哪些选项可以在 DPS 中链接 IoT 集线器。我看到链接的其他选项是 ARM 模板和 Azure CLI。我们可以使用 ARM 模板,但这只是一次部署,不确定我是否可以从 Web 应用程序中利用它。 Azure CLI 也是如此,我如何从 Web 应用程序中使用它?

【问题讨论】:

    标签: azure azure-iot-hub azure-rest-api azure-iot-dps


    【解决方案1】:

    创建 Azure IoT 中心 DPS 资源时,您可以将要链接到的 IoT 中心列表作为 properties 的一部分传递。

    例子:

    {
      "location": "East US", 
      "type": "Microsoft.Devices/ProvisioningServices",
      "properties": {
         "iotHubs": [
            {
              "applyAllocationPolicy": true,
              "allocationWeight": "1",
              "connectionString": "HostName=iothub-001.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=xxxxxxxx",
              "location": "East US"
            },
            {
              "applyAllocationPolicy": true,
              "allocationWeight": "1",
              "connectionString": "HostName=iothub-002.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=xxxxxxxx",
              "location": "East US"
            }
          ]
      }
    }
    

    documentation of the Azure IoT Hub DPS resource 中的更多信息。

    【讨论】:

    • 谢谢@kartben 是的,在我发帖后,我稍后在文档链接的请求正文部分了解了该属性对象。会试试的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    • 2015-05-19
    相关资源
    最近更新 更多