这里是 Microsoft 文档的链接,其中规定了请求的限制,但我们从应用程序创建的请求要少得多。
https://learn.microsoft.com/en-us/rest/api/iotcentral/throtdling
尝试请求几次,期望不会出现 Too much requests 错误
以下步骤可在 IoT Central 应用程序中创建作业。
首先在IoTCentral中创建设备:
PUT https://{subdomain}.{baseDomain}/api/devices/{deviceId}?api-version=2022-07-31
Authorization: API tokens
Content-Type: application/json
创建和使用 API 令牌:
身体:
{
"displayName": "Device group 1",
"description": "Custom device group.",
"filter": "SELECT * FROM devices WHERE $template = \"dtmi:modelDefinition:dtdlv2\" AND $provisioned = true"
}
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"
}
}
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
}
]
}