Among all the interfaces open on the platform, issuing commands to devices is the most essential and frequently used command.
When first accessing the device, it is also recommended to implement the "Issuing commands to devices" first, and then implement other functions through other interfaces.
Before sending commands to the device, please make sure that the device is connected to the network and is displayed online in the console.
When first accessing the device, it is also recommended to implement the "Issuing commands to devices" first, and then implement other functions through other interfaces.
Before sending commands to the device, please make sure that the device is connected to the network and is displayed online in the console.
Preparation
Before starting to write code, please do the following preparations:
1 Registered and logged in to the platform and installed the "IoT console" module
2 The device is powered on, online, and can be controlled in the console
3 Download / install a similar interface request tool (if not)
Start access
4.1 Send command interface
Interface address:
https://api.thingboot.com/{AppID}/device/control/?sign={sign}&ts={ts}
{AppID} is your application ID (generated by the platform)Please enter the console, in the development settings page to view.
{sign} and {ts} algorithm, please see the description in the previous section
{AppID} is your application ID (generated by the platform)Please enter the console, in the development settings page to view.
{sign} and {ts} algorithm, please see the description in the previous section
Request data:
This command issues the command of to with ID 820720
For more configuration parameters, please refer to section4.2 "Product Supported Commands"below
{
"device":820720,
"order":{"power1":"1"}
}
Request method: POST; Data format: JSONThis command issues the command of to with ID 820720
For more configuration parameters, please refer to section4.2 "Product Supported Commands"below
Request parameters
When the parameters are relatively long, it is recommended to use the POST method.
| Name | Required | Type | Description |
|---|---|---|---|
| gateway | No | string | When sending a order to a device that must be forwarded by its associated gateway, you must specify the gateway’s device ID—the unique ID found on the gateway housing and in the management console.
To include multiple gateways, separate their IDs with a comma (,) or vertical bar (|); up to five gateways can be specified at once. |
| device | No | string | Device ID, Unique Device ID (Found on the device housing and console)
When specifying multiple devices, connect them with a separator (, or |).When specifying multiple devices, these devices do not need to belong to the same product category, but they must support the same command. |
| order | No | string | Command: JSON String (Recommended) or Direct Parameter Transmission
Simple Commands: Can be sent via GET or POST directly in the format: Device Attribute Name=Attribute Value
Complex or Long Commands: Please send via POST in the format: {"order":{"Command Content"}}
In some business scenarios, it is necessary to carry specific information (e.g., order number) in the command.You can add an extra field to the order object. For example:{"power":1,"extra":"T25030700001"}
This specific information will be returned as-is in the asynchronous message push corresponding to this command.
Note: The extra field only supports uppercase/lowercase letters (a-zA-Z) and numbers (0-9), with a maximum length of 32 characters. |
Return results
It should be noted that a status code of 200 only indicates that the platform has received a valid device ID and parameter name, and has successfully sent a command to the device.
However, the device may be offline, or there may be errors in the
| Name | Type | Description |
|---|---|---|
| code | int | 200: Command issued successfully.
501: No Device ID specified. The Device ID must be a single integer, or multiple integers separated by "|" or ",". This ID is available in the Device List API and can also be viewed in the Device List section of this console.
502: Device does not exist or no available devices. All provided Device IDs are invalid. Please check if the Device IDs are correct and whether the devices have been deleted.
503: Excessive devices specified. A maximum of 100 Device IDs can be specified at one time.
504: Multiple Device IDs specified, but some are unavailable (non-existent, no permission, or deleted).
50xx: Please refer to "Global Error Codes". |
4.2 Product supports commands
4.2.1 产品命令
| Command | Name | Content | Description |
|---|---|---|---|
| power1 | 通 | {"power1":"1"} | |
| 断 | {"power1":"0"} | ||
| power2 | 通 | {"power2":"1"} | |
| 断 | {"power2":"0"} | ||
| power3 | 通 | {"power3":"1"} | |
| 断 | {"power3":"0"} | ||
| power4 | 通 | {"power4":"1"} | |
| 断 | {"power4":"0"} | ||
| batch | 全开 | {"batch":{"power":1}} | |
| 全关 | {"batch":{"power":0}} | ||
| 线路1|3|5|7开 | {"batch":{"relay":[1,3],"power":1}} | ||
| 线路1|3|5|7关 | {"batch":{"relay":[1,3],"power":0}} | ||
| 线路2|4|6开 | {"batch":{"relay":[2,4],"power":1}} | ||
| 线路2|4|6关 | {"batch":{"relay":[2,4],"power":0}} | ||
| point | 500毫秒,全部线路 | {"point":{"interval":500}} | |
| 1秒,线路1|3 | {"point":{"relay":[1,3],"interval":1000}} | ||
| 2秒,线路2 | {"point":{"relay":[2],"interval":2000}} | ||
| reset | 500毫秒,全部线路 | {"reset":{"interval":500}} | |
| 1秒,线路1|3 | {"reset":{"relay":[1,3],"interval":500}} | ||
| 2秒,线路2 | {"reset":{"relay":[2],"interval":2000}} | ||
| 5秒,线路2|4 | {"reset":{"relay":[2,4],"interval":5000}} |
4.2.2 System command
| Command | Name | Content | Description |
|---|---|---|---|
| system | GetNetworkInfo | network | |
| Get device status | state | ||
| Connect WiFi | wifi_connect | ||
| Connect to configured WiFi | wifi_connect_multi | ||
| Disconnect WiFi | wifi_disconnect | ||
| Enter private deployment mode (If configured) |
private | ||
| Reboot | restart |