El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Deliver an Asynchronous Command

Updated on 2025-03-03 GMT+08:00

Function

A product model defines commands that the IoT platform can deliver to devices. An application can call this API to deliver asynchronous commands to a specific device to control the device. The platform delivers commands to the device and asynchronously returns the command execution result to the application. The command execution result supports data forwarding. After the application calls the API for creating a rule triggering condition (resource is set to device.command.status and event to update) and the API for creating a rule action and activates a rule, the platform pushes the result to the server specified by the rule when the command status changes. The server can be a user-defined HTTP server, AMQP server, or Huawei Cloud storage server. For details, see Pushing a Device Command Status Change Notification.

Notes:

  • This API is used only to deliver commands asynchronously to NB-IoT devices.

  • This API supports asynchronous command delivery to a single device. For details about how to deliver commands to multiple devices asynchronously, see Creating a Batch Task.

Debugging

You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.

URI

POST /v5/iot/{project_id}/devices/{device_id}/async-commands

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Parameter description: project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

device_id

Yes

String

Parameter description: ID of the device to which the command is delivered. The ID is unique and is allocated by the platform during device registration.

Value: The value can contain a maximum of 128 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

No

String

Parameter description: user token. You can obtain the token by calling the IAM API Obtaining a User Token Through Password Authentication. In the returned response header, X-Subject-Token is the desired user token. For details about how to obtain the token, see Token Authentication.

Instance-Id

No

String

Parameter description: instance ID. Unique identifier of each instance in the physical multi-tenant scenario. Mandatory for professional editions and recommended in other cases. Log in to the IoTDA console and choose Overview in the navigation pane to view the instance ID. For details, see Viewing Instance Details.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

service_id

No

String

Parameter description: ID of the device service that the device command belongs to, which is defined in the product model associated with the device. This parameter is mandatory if the device requires codecs to parse commands.

Value: The value can contain a maximum of 64 characters.

command_name

No

String

Parameter description: command name, which is defined in the product model associated with the device. This parameter is mandatory if the device requires codecs to parse commands.

Value: The value can contain a maximum of 128 characters.

paras

Yes

Object

Parameter description: command executed by the device. The command is in JSON format (key-value pairs). If service_id is specified, each key is a paraName in commands in the product model. If service_id is left empty, custom command format is used. {"value":"1"} is an example device command. The specific format depends on the application and device. The maximum size of the request object is 256 KB.

expire_time

No

Integer

Parameter description: duration for the platform to cache commands. The unit is second. The platform can cache up to 20 messages (that is, up to 20 commands in the PENDING state). This parameter is valid only when send_strategy is set to delay. By default, commands are cached for 24 hours and can be cached for up to 2 days.

send_strategy

Yes

String

Parameter description: delivery policy. By default, commands are cached and then delivered.

Options:

  • immediately: The command is delivered immediately. In this case, expire_time is invalid.

  • delay: The command is cached and delivered after the device reports data or goes online. If expire_time is set to 0 or not specified, the command is cached for 24 hours by default.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

device_id

String

Unique device ID, which is allocated by the platform during device registration.

command_id

String

Device command ID, which is unique and is allocated by the platform during command delivery.

service_id

String

ID of the device service that the device command belongs to, which is defined in the product model associated with the device.

command_name

String

Command name, which is defined in the product model associated with the device.

paras

Object

Command executed by the device. The command is in JSON format (key-value pairs). If service_id is specified, each key is a paraName in commands in the product model. If service_id is left empty, custom command format is used. {"value":"1"} is an example device command. The specific format depends on the application and device.

expire_time

Integer

Duration for the platform to cache commands, in seconds.

status

String

Device command status. If the command is cached, PENDING is returned. If the command is delivered to the device, SENT is returned.

created_time

String

UTC time when the command was created. The value is in the format of yyyyMMdd'T'HHmmss'Z'.

send_strategy

String

Delivery policy. immediately indicates that the command is delivered immediately. delay indicates that the command is cached and delivered when the device reports data or goes online.

Example Requests

Creating an asynchronous command. The command name is ON_OFF, and the command is ON.

POST https://{endpoint}/v5/iot/{project_id}/devices/{device_id}/async-commands

{
  "service_id" : "reboot",
  "command_name" : "ON_OFF",
  "paras" : {
    "value" : "ON"
  },
  "expire_time" : 0,
  "send_strategy" : "immediately"
}

Example Responses

Status code: 200

OK

{
  "device_id" : "c1224afb-e9f0-4916-8220-b6bab568e888",
  "command_id" : "b1224afb-e9f0-4916-8220-b6bab568e888",
  "service_id" : "Switch",
  "command_name" : "ON_OFF",
  "send_strategy" : "immediately",
  "paras" : {
    "value" : "ON"
  },
  "expire_time" : 0,
  "status" : "SENT",
  "created_time" : "20151212T121212Z"
}

Status Codes

Status Code

Description

200

OK

400

Bad Request

401

Unauthorized

403

Forbidden

404

Not Found

500

Internal Server Error

Error Codes

See Error Codes.

Utilizamos cookies para mejorar nuestro sitio y tu experiencia. Al continuar navegando en nuestro sitio, tú aceptas nuestra política de cookies. Descubre más

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback