Thingboot's smart switch opens the HTTP interface. To put it bluntly, it provides you with a "remote control" that can directly control the switch through the Internet. Below I will explain step by step how to connect.
1. Preparation work
Before you start, you must have these things in hand:
One (or several) Thingboot smart touch wall switch: No. 1, 2 or 3 is OK, it depends on how many lights you need to control.. This thing can directly replace the original 86-type wall switch in your home without changing the wiring..
A Thingboot developer account: Go to their official website to register one. After registration, enter the console to see your
AppIDandAppSecret, these two are equivalent to your "username" and "password", which will be used later when calling the interface..2.4G Wi-Fi network: Note that it only supports 2.4G frequency band, not 5G.. The switch is directly connected via Wi-Fi, so there is no need to buy an additional gateway, which is more trouble-free.
When you get the device, power it on first, then use a small program or console to connect it to the Internet. After configuration, you can see the device’s unique ID (a string of numbers) in the console. Remember it and use it later..
2. Popular explanation of docking principle
To put it bluntly:Your server (or App backend) sends an HTTP request to Thingboot's API server, telling it "turn on/off which channel of a certain switch". The API server sends this command to the device, and the device executes it..
The whole process is very fast, from sending the command to the device responding in about 80-120 milliseconds..
The interface of Thingboot is very friendly and supports any programming language that can send HTTP requests - Java, Python, PHP, Node.js, Go. You can even use the command line curl to adjust it..
3. Detailed explanation of interface calling
1. Request address and signature
The interface address looks like this:
https://api.thingboot.com/{Your AppId}/device/control/?sign={Signature}&ts={Timestamp}There are two things you need to dynamically generate:
ts: Current timestamp (second level), for example
1704067200.sign: Signature, used to verify your identity. The generation rules are:
sign = md5( md5(AppSecret) + ts )
That is to say, put your
AppSecretDo an MD5 encryption, then add the timestamp, and then do an MD5 of the entire string..
To give an example that is not appropriate but easy to understand: AppSecret is like your bank card password, and the signature is a one-time verification code calculated using the password + the current time. In this way, even if the request is intercepted, others cannot use this signature to do bad things (because the signature will become invalid if the timestamp changes).
2. Request body and command format
Send a request using POST method, and set Content-Type toapplication/json, put two fields in the request body:
device: It is the device ID you see on the console, in string format.
order: Core command, tells the switch what to do.
List of commonly used commands(Take 1-way, 2-way, and 3-way switches as examples):
| what you want to do | order command |
|---|---|
| Turn on channel 1 (such as the living room light) | {"power1": 1} |
| Close Route 1 | {"power1": 0} |
| Open route 2 | {"power2": 1} |
| Close Route 3 | {"power3": 0} |
| Control multiple channels at the same time (turn on 1 and 2, turn off 3) | {"power1": 1, "power2": 1, "power3": 0} |
| Delayed shutdown: turn on channel 1 and automatically turn off after 1 hour | {"point1": "3600000"}(unit is millisecond) |
3. Code examples
Writing it in Python is roughly like this (more intuitive):
It is also OK to use curl on the command line, which is convenient for testing:
4. Touch button local control
In fact, this part of youNo need to do anything——This is the hardware function that comes with the switch.
The user directly touches the touch button on the switch panel with his hand, and the light turns on, and touches it again to turn it off. This control islocal direct connectionYes, it does not go through the network, so it can be used normally even if the network is disconnected..
And because it uses capacitive touch sensing, there is no "click-click" physical loss like traditional mechanical switches. It has a long life and fast response. There is feedback when you touch it with your hand..
So you only need to pay attention to the docking of the remote control interface, and the switch will take care of the local touch.
5. Several practical advanced gameplays
In addition to basic on/off, the interface also supports some useful functions:
Status maintained: For example, if you want the corridor light to be turned on, it will automatically turn off after 10 seconds, no matter who turns it on. You can use the status retention command to save yourself the need to write scheduled tasks yourself..
Control multiple devices simultaneously: The device field supports passing multiple IDs, just separate them with commas. Turn off the lights in the whole house with one click and get it done with just one request.
scheduled tasks: Set a timer in your App, and call the interface to send commands at the specified time, so that you can turn on and off the lights regularly every day..
6. Frequently Asked Questions and Tips
The device cannot connect to the Internet?Check whether the Wi-Fi is 2.4G, 5G is not supported. In addition, the switch supports configuring 5 groups of Wi-Fi and will automatically select the connection with the strongest signal..
Is it wrong to sign a life or death?Check whether the timestamp is in the second level (not milliseconds), whether the MD5 is 32-bit lowercase, and whether the AppSecret is copied completely (don't miss characters).
Can LAN be used?Can. Thingboot's equipment supports privatized deployment and LAN communication. If you don't need cloud functions, you can run it in an intranet environment..
During the debugging phase, you can first test on the console: After the network configuration is successful, you can directly send commands to the device to test in the IoT console of Thingboot. You can verify whether the device is working normally without writing code..
That's about it. The core of the entire docking process is to calculate the signature correctly and write the command format correctly. The rest is manual labor. Thingboot also provides free technical support. If you are really unsure, you can directly ask their engineers..