Azure IOT 中心创建作业 API 上出现“请求过多”错误

问题描述 投票:0回答:1

为警报创建计划作业时,作业 api 中出现以下错误。 error screenshot

这里是 Microsoft 文档的链接,其中规定了请求的限制,但我们从应用程序创建的请求要少得多。

https://learn.microsoft.com/en-us/rest/api/iotcentral/throtdling

尝试请求几次,期望不会出现 Too much requests 错误

azure-web-app-service azure-iot-hub azure-iot-central
1个回答
0
投票

以下步骤可在 IoT Central 应用程序中创建作业。

首先在IoTCentral中创建设备:

PUT https://{subdomain}.{baseDomain}/api/devices/{deviceId}?api-version=2022-07-31
Authorization:  API tokens
Content-Type: application/json

创建和使用 API 令牌:

  • 在浏览器中打开 IoT Central 应用程序,然后转到权限 > API 令牌。
  • 单击生成令牌。系统将提示您为其命名并选择角色。该角色决定使用此令牌的客户端有权在此应用程序中执行哪些操作。
  • 生成令牌并复制值。该值是一个秘密,只会显示一次。

身体:

{
  "displayName": "Device group 1",
  "description": "Custom device group.",
  "filter": "SELECT * FROM devices WHERE $template = \"dtmi:modelDefinition:dtdlv2\" AND $provisioned = true"
}

enter image description here

  • 使用 REST API 在 Azure IoT Central 中添加设备模板。
PUT https://{your-app-subdomain}.azureiotcentral.com/api/deviceTemplates/dtmi:contoso:mythermostattemplate;1?api-version=2022-07-31

Authorization:  API tokens
Content-Type: application/json

身体:

{
    "displayName": "Thermostat",
    "@id": "dtmi:contoso:mythermostattemplate;1",
    "@type": [
        "ModelDefinition",
        "DeviceModel"
    ],
    "@context": [
        "dtmi:iotcentral:context;2",
        "dtmi:dtdl:context;2"
    ],
    "capabilityModel": {
        "@id": "dtmi:contoso:Thermostat;1",
        "@type": "Interface",
        "contents": [
            {
                "@type": [
                    "Telemetry",
                    "Temperature"
                ],
                "description": "Temperature in degrees Celsius.",
                "displayName": "Temperature",
                "name": "temperature",
                "schema": "double",
                "unit": "degreeCelsius"
            },
            {
                "@type": [
                    "Property",
                    "Temperature"
                ],
                "description": "Allows to remotely specify the desired target temperature.",
                "displayName": "Target Temperature",
                "name": "targetTemperature",
                "schema": "double",
                "unit": "degreeCelsius",
                "writable": true,
                "decimalPlaces": 1,
                "displayUnit": "C",
                "maxValue": 80,
                "minValue": 50
            },
            {
                "@type": [
                    "Property",
                    "Temperature"
                ],
                "description": "Returns the max temperature since last device reboot.",
                "displayName": "Max temperature since last reboot.",
                "name": "maxTempSinceLastReboot",
                "schema": "double",
                "unit": "degreeCelsius"
            },
            {
                "@type": "Command",
                "description": "This command returns the max, min and average temperature from the specified time to the current time.",
                "displayName": "Get report",
                "name": "getMaxMinReport",
                "request": {
                    "@type": "CommandPayload",
                    "description": "Period to return the max-min report.",
                    "displayName": "Since",
                    "name": "since",
                    "schema": "dateTime"
                },
                "response": {
                    "@type": "CommandPayload",
                    "displayName": "Temperature Report",
                    "name": "tempReport",
                    "schema": {
                        "@type": "Object",
                        "fields": [
                            {
                                "displayName": "Max temperature",
                                "name": "maxTemp",
                                "schema": "double"
                            },
                            {
                                "displayName": "Min temperature",
                                "name": "minTemp",
                                "schema": "double"
                            },
                            {
                                "displayName": "Average Temperature",
                                "name": "avgTemp",
                                "schema": "double"
                            },
                            {
                                "displayName": "Start Time",
                                "name": "startTime",
                                "schema": "dateTime"
                            },
                            {
                                "displayName": "End Time",
                                "name": "endTime",
                                "schema": "dateTime"
                            }
                        ]
                    }
                }
            },
            {
                "@type": [
                    "Property",
                    "Cloud",
                    "StringValue"
                ],
                "displayName": "Customer Name",
                "name": "CustomerName",
                "schema": "string"
            }
        ],
        "description": "Reports current temperature and provides desired temperature control.",
        "displayName": "Thermostat"
    }
}


enter image description here

  • 然后使用 REST API IoT Central 创建作业。
PUT https://{your-app-subdomain}.azureiotcentral.com/api/jobs/{jobId}?api-version=2022-07-31
Authorization:  API tokens
Content-Type: application/json

身体:

{
  "displayName": "My Job",
  "group": "group1",
  "data": [
    {
      "type": "property",
      "target": "dtmi:contoso:mythermostattemplate;1",
      "path": "targetTemperature",
      "value": 90
    }
  ]
}

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.