CATALOG

This is a solution that integrates Thingboot 2-way wall switch into smart office scenarios. I will focus on the two core requirements of "access control linkage to turn on the lights" and "turn off the lights with one click after get off work" to explain in detail the interface calling, signature calculation and business logic docking.

1. Let’s first talk about the pain points of the scene.

Have you ever encountered this situation?I work late at night, and when I enter the company gate in the dark, I have to fumble for a long time to find the access card. After swiping the card, I go in. The corridor is dark, and I have to find my mobile phone flashlight to turn on the light... Or, I am obviously the last one to leave, and I have to go from room to room to check whether the lights are turned off.

What we have to do now is to combine the two tasks of "brushing the access control" and "turning on the lights"tied together.

Using Thingboot's 2-way smart wall switch, combined with the extremely simple HTTP interface it opens, we can run through this logic in about ten minutes.

Our goals:

  1. Linked lighting: The moment the door is opened legally (or the work badge is swiped), the main lighting in the office will automatically light up, so there is no need to go into the dark.

  2. Get off work with one click: Click the button on the front end (such as corporate WeChat or App), or trigger it when the last person leaves the house, all the lights in the office will automatically go out, and the exhaust fan can be turned off by the way (the second channel is just used).

Below, I will show you step by step how to solder this hardware into your project code.

2. Hardware selection: Why is it "Thingboot 2-way smart wall switch"?

Since it is "access lighting control", our scene is usually:Turn on the headlights when entering,Turn off the lights/turn off the exhaust fan.

There are several features of this Thingboot switch that are particularly fragrant:

  • 2-way independent control: This means you can connect "Road 1" to the large chandelier in the office, and "Road 2" to the corridor light or exhaust fan. Do not interfere with each other, controlled independently by HTTP interface.

  • Zero fire/single fire compatible: No matter your company is an old house (single live wire) or newly renovated (with neutral wire), you can directly replace the original 86 switch without breaking the wall for wiring..

  • Very fast response: The official data is 80-120ms response. The actual experience is that when you lift the knife and drop it, the light will turn on..

  • Friendly interface: No need to do any complicated MQTT or Socket long connection, just send an HTTP request, any programming language can do it.

3. Core docking: How to adjust the interface?

This is the most critical step. Don’t be scared by the words "smart hardware", think of it as aRelays that can be controlled via URLThat's it.

1. How to make it "turn on the light"?

Thingboot's device control is completed through a POST request.

Request address(It probably looks like this, depending on your console):http(s)://api.thingboot.com/{Your AppId}/device/control/?sign={Signature}&ts={Timestamp}

Request body (Body) - JSON format

Did you see that? It's just so brutal and direct.

  • power1It's the light connected to the "L1" interface of the switch.

  • power2It is the exhaust fan connected to the "L2" interface.

2. What to do with the annoying "signature"?

The most annoying thing when calling an interface is thatsignSignature algorithm, but in fact Thingboot is very simple, justDouble MD5 encryption.

The pseudocode is as follows (no matter you use Java, Python or Go, the logic is the same):

  1. get yoursAppSecret(You can see it in the background of Thingboot).

  2. Count the first layer:secret_md5 = md5(AppSecret)

  3. Splicing timestamp:raw_str = secret_md5 + ts(ts for example is 1712280000)

  4. Count the second level:sign = md5(raw_str)

colloquial explanation: Just encrypt your password MD5 once, followed by the current time (to prevent cheating), and then encrypt it as a whole. Done.

3. Special gameplay: delay and hold

I have to mention a very practical function here. For example, when the door is opened, the light turns on, but the corridor light does not need to stay on. You want it to turn off automatically after 1 minute (to save power). You do not need to write a scheduled task on the server to turn it off.

You only need to do this when issuing the command

In this way, the light is turned on and turns off by itself after 60 seconds, which is especially suitable for scenes that only need to light up when people pass by.

4. Practical implementation: How to combine it with access control/projects?

Suppose you use Python to write the backend, or Node.js to write cloud functions. The business logic is probably like this:

Scenario 1: Swipe card/scan code to open the door -> light turns on

physical link: Access control reader->Access control controller motherboard->Your current business server->Thingbootyun->Smart switch->Light on.

Code logic

The second scenario: Turn off the main gate with one click after work

This one is simpler. You can make an "off duty mode" button on the front end (such as React or applet).When the user clicks, the front end calls your interface, and your back end only needs to send a command to Thingboot:

Thousands of devices in the company? It doesn't matter, it supports batch control,deviceJust use commas to separate the device IDs in the parameters..

5. Guide to avoid pitfalls (very important)

It is very simple to adjust the interface, but to install it in the office and run it stably, you have to avoid these pitfalls in advance:

  1. WiFi signal problem (bloody lesson)Smart wall switch is a go2.4G WiFiof, no gateway required, very convenient. But the weaknesses are also obvious. If the metal shielding in the weak current box or switch bottom box is too severe, the signal will be poor.: Before installation, first use your mobile phone to connect to the WiFi at that location to see if the signal is full. If it is full, install it again; if it is two cells, it may often disconnect after installing it.

  2. Load problem (Led light flashing)If you are connected to an LED energy-saving lamp and there are very few lamp beads (for example, the toilet only has a few watt downlights), there may be a "wisp" (slight flickering) after turning off the light.Solution: Either connect a capacitor in parallel to both ends of the lamp (generally it comes with the switch), or set the switch mode to "pulse mode" in the background, or consult customer service to buy a safety capacitor.

  3. Permissions and SecuritythatAppSecretDon’t write it into the front-end code of the web page!Must be kept by your backend server. Otherwise, if a knowledgeable person presses F12 and sees your key, he can control all the lights in your company, and it will become a "dangerous midnight bell".

6. Summary

Integrate Thingboot's 2-way wall switch into your project, it is actually a"HTTP triggered from gate event"process.

Summarize in three steps:

  1. Install hardware: Replace the switch, turn on the power, and configure the network.

  2. adjust interface: If you write the two lines of MD5 encryption correctly, you can adjust the API and light the lamp.

  3. write logic: In the callback when the access control card is successfully swiped, call the code in step 2.

The advantage of this plan isVery minimally invasive, whether your company's current system is an antique written in PHP or the latest microservice architecture, as long as it supports sending HTTP requests, you can open the switch of the "physical world" in a few minutes.