Bu sayfa henüz yerel dilinizde mevcut değildir. Daha fazla dil seçeneği eklemek için yoğun bir şekilde çalışıyoruz. Desteğiniz için teşekkür ederiz.

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 a Message to a Device

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

Function

This API is used by an application to deliver a message to a device. After an application delivers a message to the platform, the platform returns a response to the application and then sends the message to the device. The response returned by the platform may not be the device receiving result. Call the API Pushing a Device Message Status Change Notification for the platform to push the device receiving result to the application.

Notes:

  • This API is only used to deliver messages to MQTT devices.

  • This API supports message delivery to a single device. For details about how to deliver messages to multiple devices, 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}/messages

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 message 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

message_id

No

String

Parameter description: message ID, which is user-defined (UUID is recommended). The ID must be unique under a device. Otherwise, an error is returned.

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

name

No

String

Parameter description: message name.

Value: The value can contain a maximum of 128 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.

message

Yes

Object

Parameter description: message content. String and JSON formats are supported.

properties

No

PropertiesDTO object

Parameter description: property parameter of the message delivered to the device.

encoding

No

String

Parameter description: encoding format for the message content. The default value is none.

Options:

  • none

  • base64

payload_format

No

String

Parameter description: valid payload format. This parameter is valid when the encoding format for the message content is none. The default value is standard, indicating that the message content is encapsulated in the standard format.

Options:

  • standard

  • raw: The message content is directly delivered as the payload.

topic

No

String

Parameter description: (optional) suffix of the custom topic through which the message is delivered to the device. This parameter is applicable only to MQTT devices. You can only enter topics configured on the tenant product page. Otherwise, the verification will fail. The prefix that the platform adds to a message topic is $oc/devices/{device_id}/user/. You can add a part to the prefix. For example, if you add messageDown to the prefix, the topic is $oc/devices/{device_id}/user/messageDown. Replace device_id with the actual gateway ID of the device. If you specify the topic, messages are delivered to the device through this topic. If you do not specify the topic, messages are delivered to the device through the default topic. The default topic is $oc/devices/{device_id}/sys/messages/down. Either this parameter or the topic_full_name parameter can be specified.

topic_full_name

No

String

Parameter description: (optional) name of the topic through which the message is delivered to the device. You can specify a custom topic. The platform does not check whether the topic is defined on the platform and transparently transmits the topic to the device. The device needs to subscribe to the specified topic first. Either this field or the topic parameter can be specified.

ttl

No

Integer

Parameter description: aging time of the caches of delivered messages on the platform, in minutes. The default value is 1440. The value of ttl must be a multiple of 5, that is, the granularity is 5 minutes. If this parameter is set to 0, messages are not cached. The maximum cache duration is 1,440 minutes.

Table 4 PropertiesDTO

Parameter

Mandatory

Type

Description

correlation_data

No

String

Parameter description: data in the request and response modes of MQTT 5.0. This parameter is optional. You can use this parameter to configure data in the request and response modes of MQTT.

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

response_topic

No

String

Parameter description: response topic in the request and response modes of MQTT 5.0. This parameter is optional. You can use this parameter to configure the response topic in the request and response modes of MQTT.

Value: The value can contain a maximum of 128 characters. Only letters, digits, and special characters (_-?=$#+/) are allowed.

user_properties

No

Array of UserPropDTO objects

Parameter description: custom property. This parameter is optional. You can use this parameter to configure custom properties. A maximum of 20 customized attributes can be configured.

Table 5 UserPropDTO

Parameter

Mandatory

Type

Description

prop_key

No

String

Parameter description: key of the custom property.

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

prop_value

No

String

Parameter description: value of the custom property.

Value: The value can contain a maximum of 128 characters. Only letters, digits, underscores (_), and question marks (?) are allowed. '#().,& %@!-.

Response Parameters

Status code: 201

Table 6 Response body parameters

Parameter

Type

Description

message_id

String

Message ID, which is specified by you (UUID is recommended). The message ID must be unique under a device. If the ID is not specified, the platform automatically generates one.

result

MessageResult object

Result of delivering the message. The value is in JSON format.

Table 7 MessageResult

Parameter

Type

Description

status

String

Message status, including PENDING, DELIVERED, FAILED, and TIMEOUT. If the device is offline, the platform caches the message and returns PENDING. The platform delivers the message after the device reports data. If the device is online, the platform directly delivers the message. If the message is successfully delivered, the platform returns DELIVERED. If the message fails to be delivered, the platform returns FAILED. If the message is not delivered to the device within the default time (one day), the platform sets the message status to TIMEOUT. In addition, an application can subscribe to the message execution result. The platform pushes the result to the application.

created_time

String

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

finished_time

String

UTC time when the message was delivered to the device, failed to be delivered, or timed out. The value is in the format of yyyyMMdd'T'HHmmss'Z'.

Example Requests

  • Creates a message and delivers it through the default topic of the platform.

    POST https://{endpoint}/v5/iot/{project_id}/devices/{device_id}/messages
    
    {
      "message_id" : "99b32da9-cd17-4cdf-a286-f6e849cbc364",
      "name" : "messageName",
      "message" : "HelloWorld"
    }
  • Creates a message and delivers it through a custom topic on the platform.

    POST https://{endpoint}/v5/iot/{project_id}/devices/{device_id}/messages
    
    {
      "message_id" : "99b32da9-cd17-4cdf-a286-f6e849cbc364",
      "name" : "messageName",
      "message" : "HelloWorld",
      "topic" : "testTopic"
    }
  • Creates a message and delivers it through a custom topic.

    POST https://{endpoint}/v5/iot/{project_id}/devices/{device_id}/messages
    
    {
      "message_id" : "99b32da9-cd17-4cdf-a286-f6e849cbc364",
      "name" : "messageName",
      "message" : "HelloWorld",
      "topic_full_name" : "/test/customTopic/testTopic"
    }

Example Responses

Status code: 201

Created

{
  "message_id" : "b1224afb-e9f0-4916-8220-b6bab568e888",
  "result" : {
    "status" : "PENDING",
    "created_time" : "20151212T121212Z",
    "finished_time" : "20151212T121213Z"
  }
}

Status Codes

Status Code

Description

201

Created

400

Bad Request

401

Unauthorized

403

Forbidden

404

Not Found

500

Internal Server Error

Error Codes

See Error Codes.

Sitemizi ve deneyiminizi iyileştirmek için çerezleri kullanırız. Sitemizde tarama yapmaya devam ederek çerez politikamızı kabul etmiş olursunuz. Daha fazla bilgi edinin

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback