Professional Documents
Culture Documents
Lab Guide –
O&M Feedback
1.2 Procedure
When the technical support engineer server accesses the open API of the IoT platform for the
first time, the technical support engineer server needs to invoke the interface to complete
authentication and obtain the access token.
Note that the authentication API is the prerequisite for invoking other APIs. Except for the
authentication API, the subsequent requests must carry the app_key and Authorization
parameters in the request header. The value of app_key must be the same as that of appId in
the request parameter. Authorization is accessToken.
A lot 开发实验 第2页
Certificate files (client.crt and client.key) are required for device authentication. Place the
authentication files in the corresponding directory in the OBS bucket for easy reading.
If you forget the application ID and secret, go to HUAWEI CLOUD IoT platform to view the
application interconnection domain name (URL), port number, and protocol.
A lot 开发实验 第3页
The app ID is displayed. If you forget the secret, you can reset the secret and save it to the
local host.
The URL, port number, and application key (appID and key) are obtained.
Use the requests library to send a post request.
import requests,json # Imported package
Import OS
def readCertificate():
certFilePath = './client.crt' #Path of the configuration authentication file
certFilePath2 = './client.key'
cert = (certFilePath, certFilePath2)
return cert
url = 'https://iot-api.cn-north-4.myhuaweicloud.com:8743/api/v3.0/auth/tokens'
#The URL is subject to the IoT platform address. The port number is usually 8743.
r = requests.post(url, headers=headers, data=payload_js, cert=readCertificate(), verify=False):
Note that the validity period of the accessToken is 3600s. If the platform is not used for a
long time, authentication needs to be performed again.
The authorization parameter must contain Authorization and app_key. Authorization is the
obtained accessToken. The URI is in the format of https://ip:port number
/api/v3.0/devices/{deviceId}/commands. The request body contains the serviceId, method,
expireTime, and body parameters. "body":{"ioswitch":"1678923450"} indicates the content of
the request, the number sequence "1678923450" indicates the display sequence of the
offering on the developer board.
Mandatory request parameters are as follows:
A lot 开发实验 第6页
To obtain the value of deviceId, choose Device > All Devices to view the device list.
Set deviceId to the value of deviceId in the basic information and edit the post request.
headers = {"Authorization":"92b1a166448d6398a9e41e7aa5f39d2",
"app_key":"vpfqC_pEExjfFoDj0DU4Mt78ioca"}:
body = {"serviceId":"Delivery",
"method":"SET_LIGHT_ON",
"expireTime": 0,
"body":{"ioswitch":"1678923450"}} # Offering display sequence. The number indicates the offering ID.
The initial sequence is 0123456789.
url = 'https://iot-api.cn-north-4.myhuaweicloud.com:8743/api/v3.0/devices/1ebce315-1226-4066-bf5e-
494e06d77b99/commands' ##The URI format is HYPERLINK "https://ip" https://ip address:port number
/api/v3.0/devices/{deviceId}/commands.
1.2.2 Verification
步骤 1 Output the request result.
After the request for changing the offering placement sequence is sent, the developer board is
displayed as follows.