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

Configure Desired Properties in a Device Shadow

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

Function

This API is used by an application to configure properties in the desired section of a device shadow. When the device goes online or reports properties, the desired properties are delivered to the device.

Introduction:

A device shadow is a JSON file used to store and obtain device status.

  • Each device has only one device shadow, which is uniquely identified by the device ID.

  • A device shadow stores the properties (status) reported by a device and the properties (status) expected by an application.

  • You can obtain and set the device properties through the device shadow, regardless of whether the device is online.

  • After a device goes online or reports data, if the reported properties are different from the desired ones, the desired properties are delivered to the device. The desired properties can be delivered only when they have been defined in the product model and method is specified as W.

  • This API can be used to configure desired shadow data of a single device. For details about how to configure desired shadow data of multiple devices, see Creating a Batch Task.

Restrictions:

Keys in the device shadow JSON file cannot contain periods (.), dollar signs ($), and the null character (hexadecimal ASCII code 00). Otherwise, the device shadow file cannot be updated.

Debugging

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

URI

PUT /v5/iot/{project_id}/devices/{device_id}/shadow

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: device ID, which uniquely identifies a device. The value of this parameter is specified during device registration or allocated by the platform. If the value is allocated by the platform, the value is in the format of [product_id][node_id]. 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. X-Subject-Token in the response header returned by the API 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

shadow

No

Array of UpdateDesired objects

Parameter description: data structure of the desired properties in the device shadow.

Table 4 UpdateDesired

Parameter

Mandatory

Type

Description

service_id

Yes

String

Parameter description: device service ID, which is defined in the product model associated with the device.

desired

Yes

Object

Parameter description: desired properties in the device shadow. The data is JSON data and is in the format of key-value pairs. Each key is a parameter name of a property (property_name) in the product model. Only one-layer structure is supported, as shown in the example request. To delete all desired properties, leave the value empty (for example, "desired":{}). To delete a desired property, set the value of the property to null (for example, {"temperature":null}).

version

No

Long

Parameter description: version of the device shadow. When this parameter is carried, the platform will check whether the value is the same as the current shadow version. The initial value is 0.

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

device_id

String

Device ID, used to uniquely identify a device. The value of this parameter is specified during device registration or allocated by the platform. If the value is allocated by the platform, the value is in the format of [product_id]_[node_id].

shadow

Array of DeviceShadowData objects

Device shadow data structure.

Table 6 DeviceShadowData

Parameter

Type

Description

service_id

String

Device service ID, which is defined in the product model associated with the device.

desired

DeviceShadowProperties object

Latest desired properties delivered to the device. The data is JSON data and is in the format of key-value pairs. Each key is a parameter name of a property (property_name) in the product model.

reported

DeviceShadowProperties object

Latest properties reported by the device. The data is JSON data and is in the format of key-value pairs. Each key is a parameter name of a property (property_name) in the product model.

version

Long

Version of the device shadow. When this parameter is carried, the platform will check whether the value is the same as the current shadow version. The initial value is 0.

Table 7 DeviceShadowProperties

Parameter

Type

Description

properties

Object

Properties stored in the device shadow. The data is JSON data and is in the format of key-value pairs. Each key is a parameter name of a property (property_name) in the product model. Only one-layer structure is supported, as shown in the example.

Note: Keys in the JSON file cannot contain periods (.), dollar signs ($), and the null character (hexadecimal ASCII code 00). Keys that contain these special characters will cause device shadow update failures.

event_time

String

Time when the event occurred. The value is in the format of yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z.

Example Requests

  • Configures the expected data of the device shadow. The expected value of temperature is 60.

    PUT https://{endpoint}/v5/iot/{project_id}/devices/{device_id}/shadow
    
    {
      "shadow" : [ {
        "service_id" : "WaterMeter",
        "desired" : {
          "temperature" : "60"
        },
        "version" : 1
      } ]
    }
  • Delete the expected value of the temperature property from the device shadow.

    PUT https://{endpoint}/v5/iot/{project_id}/devices/{device_id}/shadow
    
    {
      "shadow" : [ {
        "service_id" : "WaterMeter",
        "desired" : {
          "temperature" : null
        },
        "version" : 2
      } ]
    }

Example Responses

Status code: 200

OK

{
  "device_id" : "40fe3542-f4cc-4b6a-98c3-61a49ba1acd4",
  "shadow" : [ {
    "service_id" : "WaterMeter",
    "desired" : {
      "properties" : {
        "temperature" : "60"
      },
      "event_time" : "20151212T121212Z"
    },
    "reported" : {
      "properties" : {
        "temperature" : "60"
      },
      "event_time" : "20151212T121212Z"
    },
    "version" : 2
  } ]
}

Status Codes

Status Code

Description

200

OK

400

Bad Request

401

Unauthorized

403

FORBIDDEN

404

Not Found

409

CONFLICT

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