This is an integrated solution for "2-way DC circuit controller" based on the Thingboot open platform. In order to make it less boring for you to read, I tried to write it in more colloquial "human language", like an old engineer giving you advice.
1. Let’s first talk about what this thing does.
Hello brothers, when we are doing Internet of Things projects, one of the most common pain points we encounter is:"I've written the code and set up the platform, but how do I get the program to control that broken machine?"
To put it bluntly, it is how to open the wall between the digital world (your backend/App) and the physical world (motor, light bulb, solenoid valve).
Today we will take the Thingboot family’s"Intelligent DC Controller 2 Channels"Let's cut this board. The name sounds long, but actually it is just one"Relay" that can connect to the Internet.
"2 way"What does it mean? There are two switches on it, which can control the on and off of the two circuits respectively.
"DC"What does it mean? Usually we control 12V or 24V equipment, such as the power supply of surveillance cameras, door locks, small water pumps, and LED light strips, all relying on it.
What we have to do is add this guy to your project.
2. Hardware wiring: Don’t panic, it’s just a matter of plugging in two wires
Many backend bosses who make software get confused when they see the hardware, thinking that they need to connect oscilloscopes and solder circuits. In fact, this thing is now as simple as a power strip.
Take this controller as an example. We don’t care how complicated it is internally. Just imagine it as aNetwork-controlled "switches"
Power supply end: Connect it to the 12V/24V power adapter.
Output terminal (COM & NO/NC)
If you want to control a light, cut the positive lead of the light and connect one end toCOMmouth, and the other end receivesNO(Normally open, that is, disconnected by default).
In this way, the lights are usually off. When you click "Turn on" in the background, the relay clicks shut, the circuit is connected, and the light turns on.
The hardware is that simple.The core idea is: use this small board to replace your hands to close the switch and cut off the power.
3. Software docking: how to use code to tell it to work
This step is the core and the most conscientious part of Thingboot. They made the process extremely simple,The complex TCP long connection and packet loss retransmission are all encapsulated, and the HTTP interface is directly exposed to you..
In other words, you don't need to do any underlying Socket communication. Just send an HTTP request like adjusting the Alipay interface.
What we have to do is——"Control device on/off".
1. Preparation
First go to Thingboot's console to get three things:
AppID: Your project ID card.
AppSecret: Your password, used for encryption.
Device ID: The device number of the 2-way controller (it can be seen on the case or in the background).
2. How to control the first and second channels?
Assuming your device ID is100860, you want to connect atRoute 1Turn on the light above.
According to their interface documentation, you need to send an HTTP request.
Request example (open the first route):If you use PythonrequestsLibrary writing, the code logic is roughly like this (the details of authentication are handled for you here, and they must be dynamically generated when actually callingsign):
Here comes the point:
ch1It is channel 1; if it is to control the second channel, usech2.If you want to open both at the same time, you can even do it in one request, for example
"order":{"ch1":1,"ch2":1}.
3. Where is "sensor power management" reflected?
The title requirement is "Sensor Device Power Management". Light manual switch is not enough, we have to make itIntelligent.
Assume that your project also has a temperature and humidity sensor (or other sensors on the Thingboot platform).business logic: When the temperature sensor detects that it exceeds 40 degrees, it will automatically turn on the fan (connected to the 2nd circuit of the controller).
The code logic is roughly as follows:
4. Advanced skills: How to manage more elegantly?
In an actual project, you may have more than one or two devices, maybe hundreds. There are two points to note at this time:
1. Develop a logic of "automatic shutdown after timeout"
Many times we control motors or lights only for a moment, or we are afraid of forgetting to turn them off and causing an accident.When issuing instructions, if you use MQTT to subscribe, or cooperate with the platform's rule engine, you can be a "watchdog".Ideas: When issuing the "open" command, a timestamp is recorded in the program. The "off" command will be automatically issued after 3 minutes. This is much more flexible than buying a timer switch.
2. Status feedback, don’t panic
Are you unsure about Guangfa's instructions? This controller will make a "click" sound when it moves, which is physical feedback. But at the software level, you can query the device status interface or subscribe to topics reported by the device.You can ask at any time: "Brother, is channel 1 open or disconnected now?" The interface will tell you.ch1: 1still0. In this way, on your backend interface, the switch button will know whether it is ON or OFF..
3. Dealing with concurrency and frequency
The interface limitation of Thingboot is1 time/second. Don’t worry, this is to protect your project from malicious attacks. For scenarios such as controlling lights and motors, once per second is completely enough. Don't create an endless loop to brush the interface, otherwise your IP will be blocked.
5. Summarize
Integrating Thingboot's 2-way DC controller into the project actually means"Three steps"
wiring: Connect the 12V power supply, and connect the device (light, motor) you want to control to the "COM" and "NO" ports in series.
Read the documentation: Get the AppID and DeviceID on the Thingboot Open Platform.
adjust interface:Send an HTTP request and include it in the parameters
ch1=1(on) orch1=0(close).
The biggest advantage of this thing is that you don’t need to reinvent the wheel from scratch. You don’t need to understand the electromagnetic principles of relay coils, nor do you need to understand the AT commands of WiFi modules.You can think of it as a remote control switch that can be accessed through the URL, placed in your project, is responsible for pressing down the 220V or 12V strong electricity for you with a "click" sound.
Moreover, Thingboot’s open platform is permanently free, so hurry up and play before they charge..