[Huawei] [cloud technology to share the things I remember growing things 17] a device control command of a lifetime

Abstract things a device control command from birth to complete the mission, its life is what? This article will take you interpret things the complete lifecycle of device control commands.

Outline

Order to effectively manage the devices, product model device are defined in the IOT internet can be issued to the device command, the application server may invoke things internet open API issued commands to the individual devices or a batch device, or the user things made through the internet directly to a single device command, for remote control of the apparatus.

Huawei platform, there are two things command issued mechanisms:

  • Immediately issued: regardless of whether the device is online, the platform received a command to the device immediately. If the device does not receive the command-line or equipment failure is issued. Send a command device support equipment and other applications are granted permission for this application.

    Command issued immediately suitable for real-time requirements there is a scene, such as street lights switch, the switching valve of the gas meter. When using issued immediately, the timing of the command issued by the need to ensure that the application server.

  • Cached fat: Things internet cache after receiving the first command, and other devices on the line, or to the device when the device then reports the data, if there are multiple cached single device command is issued for the serial line. Send a command device support equipment and other applications are granted permission for this application. Cached made suitable for less demanding real-time command of the scene, such as configuration parameters meter.

Using a device LWM2M / CoAP protocols, using the buffer recommended shot mode, the operation mode is set to PSM mode (the default value). For immediate use delivery mode (DRX mode to work or eDRX mode), you need to be successful command issued immediately after the device reported data.

For integrated Lite SDK or use the native protocol MQTT equipment Agent, things only platform supports delivery mode immediately.

Business Process

LWM2M / CoAP protocol device context

Things platform provides two mechanisms hair and cache issued immediately under. When the application server sends a command to the next platform of things, carry parameters expireTime (referred to as TTL, represents the maximum buffer time). Without expireTime, the default expireTime 48 hours.

  • expireTime = 0: command issued immediately.
  • expireTime> 0: buffer command issued.

Command issued immediately process

1578533383875188.png

Application call interface to platform Huawei IOT, the IOT retransmission request to the platform, carrying expireTime parameter is 0. Sample the following message:

 1 Method: POST
 2 request: https://server:port/iocm/app/cmd/v1.4.0/deviceCommands
 3 Header:
 4 "app_key: ******"
 5 "Authorization:Bearer******"
 6 Content-Type:application/json
 7 Body:
 8 {
 9   "deviceId": "********",
10   "command": {
11     "serviceId": "Brightness",
12     "method": "SET_DEVICE_LEVEL",
13     "paras": {
14       "value": "1",
15       }
16   },
17   "callbackUrl": "http://127.0.0.1:9999/cmd/callbackUrl",
18   "expireTime": 0,
19   "maxRetransmit": 1
20 }

2. Things internet call codec plug-Execute command request after encoding operation, the interface will be realized by the device management service and protocol definitions hair LWM2M command message body binary format.

3. Things platform 201 Created returned to the application, carrying the command status SENT. (If the device does not receive the command-line or the device fails and the command state is FAIL)

4. The apparatus returns an ACK response to the received command.

5. If the application carries the "callbackUrl" when commanding, internet push things to the application state notification message carrying the command status DELIVERED. Sample the following message:

 1 Method: POST
 2 request:
 3 Body:
 4 {
 5   "deviceId": "6543214c-72bb-4131-9e14-fad974123456",
 6   "commandId": "108a9c71462a48e09426e06e844d47ba3",
 7   "result": {
 8     "resultCode": "DELIVERED",
 9     "resultDetail":11  }
10null
  }

6. The apparatus returns the Run command execution result by 205 Content response.

7. If the command issued when the application carries "callbackUrl", internet calls things codec decoding device in response to the widget, then push state notification message to the application, the command status is carried SUCCESSFUL. Sample the following message:

 1 Method: POST
 2 request:
 3 Body:
 4 {
 5   "deviceId": "6543214c-72bb-4131-9e14-fad974123456",
 6   "commandId": "108a9c71462a48e09426e06e844d47ba",
 7   "result": {
 8     "resultCode": "SUCCESSFUL",
 9     "resultDetail":11  }
10null
  }

Development processes the command buffer

1578533457726797.png

  1. Application call interface to platform Huawei IOT, the IOT retransmission request to the platform, carrying expireTime parameter is greater than 0.

  2. Things internet write cache command queue, and reports 201 Created, carrying command status PENDING.

  3. On-line device or equipment to report the data to the internet.

  4. After things internet call codec plug-in command request is encoded according to the following protocol specification send commands to the device.

  5. If the application is carried in the command issued when the "callbackUrl", the status of Things platform push notification message to the application, carry command status SENT.

  6. Refer to the subsequent process "now issued command" in Step 4 to Step 7.

Integrated Device Agent Lite SDK / native device context MQTT

Agent Lite SDK for integration or use of equipment MQTT native protocol access, the Internet of Things platform only supports immediate delivery mode, the command will fail when the device is not online.

1578533487368423.png

 

Send command execution process and a state change in the mechanism of the entire command as shown in FIG.

1578533536979635.png

 

  1. Application call interface to platform Huawei IOT, the IOT retransmission request to the internet. Sample the following message:
  2.  1 Method: POST
     2 request: https://server:port/iocm/app/cmd/v1.4.0/deviceCommands
     3 Header:
     4 "app_key: ******"
     5 "Authorization:Bearer******"
     6 Content-Type:application/json
     7 Body:
     8 {
     9   "deviceId": "********",
    10   "command": {
    11     "serviceId": "Brightness",
    12     "method": "SET_DEVICE_LEVEL",
    13     "paras": {
    14       "value": "1",
    15       }
    16   },
    17   "callbackUrl": "http://127.0.0.1:9999/cmd/callbackUrl",
    18   "expireTime": 0,
    19   "maxRetransmit": 1
    20 }

     

  3. Things internet send commands to the apparatus according to the protocol specification.

    MQTT equipment must be designated Topic subscription platform to receive commands sent by the platform, the message sample as follows:

    1 { 
    2 "msgType": "cloudReq", 
    3 "serviceId": "Brightness", 
    4 "mid": 2016, 
    5 "cmd": "SET_DEVICE_LEVEL", 
    6 "paras": { 
    7  "value": "1"
    8  } 
    9 }

     

  4. Things return 202 Accepted to the application platform, carrying command status SENT.

  5. Apparatus returns an ACK response to the received command.

  6. If the application is carried in the command issued when the "callbackUrl", the status of Things platform push notification message to the application, carry command status is DELIVERED. Sample the following message:

     1 Method: POST
     2 request:
     3 Body:
     4 {
     5   "deviceId": "6543214c-72bb-4131-9e14-fad974123456",
     6   "commandId": "108a9c71462a48e09426e06e844d47ba",
     7   "result": {
     8     "resultCode": "DELIVERED",
     9     "resultDetail":11  }
    10null
      }

     

  7. Device performs a return command after the command execution result, the sample message is as follows:

    1 response: Status 
    2 Code: 200 OK

     

  8. If the application is carried in the command issued when the "callbackUrl", calls the Internet of Things platform codec plug-in device decodes the response, and then push state notification message to the application, command status to carry SUCCESSFUL. Sample the following message:

     1 Method: POST
     2 request:
     3 Body:
     4 {
     5   "deviceId": "6543214c-72bb-4131-9e14-fad974123456",
     6   "commandId": "108a9c71462a48e09426e06e844d47ba",
     7   "result": {
     8     "resultCode": "SUCCESSFUL",
     9     "resultDetail":11  }
    10null
      }

    Command Execution State Description

Wait (PENDING)
  • NB-IoT equipment used when commanding, if the data is not reported by the device, the platform will things cached commands issued cache mode, when the task status is "waiting" state.
  • NB-IoT equipment in the delivery mode command issued immediately, no such status.
  • Hair life season, no such state MQTT device.
Extended (EXPIRED)
  • NB-IoT equipment in the resend the command to the device if the time set in the extended, networking platform is not a command issued cache mode, the status is changed to "extended." Extended time will be based on the North to carry expireTime interface prevail, if not carry default 48h.
  • NB-IoT equipment in the delivery mode command issued immediately, no such status.
  • Hair life season, no such state MQTT device.
Cancel (CANCELED) If the task orders issued under the "wait" state, the user manually canceled the mission issued the command, the task status is changed to "canceled." Sent (SENT)
  • NB-IoT equipment used when commanding, delivers equipment to report data cache mode, the platform will things cache command to the device, then the status "waiting" to "already sent."
  • NB-IoT equipment in the command issued immediately issued mode, if the device is online, the status "transmitted."
  • Command issued next season MQTT device, if the device is online status "transmitted."
Timeout (TIMEOUT) after the NB-IoT device receives the command, networking platform within 180 seconds does not receive the response fed back from receiving the command, then the status changes to "time out." MQTT device is no such state.

Delivered (DELIVERED)

Things platform device receives the feedback has been received in response to the command issued after a state change to "service."

Success (SUCCESSFUL)

If the device after executing the command, give feedback command of Things platform successful outcome, the task status is changed to "success."

Failure (FAIL)

  • If the result of the device after executing the command, give feedback of Things platform command fails, the job status will be changed to "fail."
  • NB-IoT devices that employ delivery mode command issued immediately, if the device is offline, the status is "failed."
  • When the command issued MQTT device, if the device is offline, the status is "failed."

Author: Huawei and so enjoy expert I was spiced corned egg

Guess you like

Origin www.cnblogs.com/huaweicloud/p/12525323.html
Recommended