This is a more practical access solution. I will combine the interface characteristics of Thingboot to explain clearly how to turn this 5-digit master control PDU from a "manual switch" into an "intelligent device that obeys your program commands."
Brothers, let’s talk about something dry today.
If you have already got the Thingboot unit in your hand,5-digit master control PDU(That's the UNI-PDU-ZK-5), or if you are planning to use it to manage equipment in the computer room, studio or even home, you may soon encounter a pain point:
Although this thing can connect to the Internet, it can't always let me hold the phone and click on the app, right? i want itAutomatic linkage——For example, when the temperature is high, the air conditioner automatically restarts, or when the network is disconnected, the optical modem is automatically powered off and restarted. I even want to write a script to link it to my business system.
Can this be done? Of course you can.
Today we are going to talk about how to useThingboot’s open interface, transforming this PDU from an "obedient soldier" into a "commander who can think automatically."
core products: Thingboot 5-digit master control PDU (UNI-PDU-ZK-5)core weapons: HTTP open interface, single control/batch control, status query
Step 1: Understand your "weapon"—the interface capabilities of the PDU
Before we start writing code, we must first figure out what words this PDU can understand.
According to the official manual, although this 5-digit master control PDU looks like a power strip, it has a built-in WiFi module. You don’t need to buy any gateway, just connect it to the Internet, and it will wait for your instructions on the LAN or even the Internet..
It mainly supports the following "saucy operations":
Single hole position control: For example, only the third hole is closed.
Fully open/fully closed: One-click power off, simple and crude.
batch control: One command controls the opening of channel 1 and channel 3 at the same time.
Custom linkage: This is our protagonist today.
Step 2: Preparation before the war - get the key to the "remote control"
To control it remotely, you need to get three things first, none of which are essential.
AppID/AppSecret: Equivalent to your account password. Log in to the Thingboot console and find it in "Development Settings".
Device ID: That is the ID card of your PDU. You can see that series of numbers in the device list.
Signature algorithm: This is to prevent others from tampering with your device. The algorithm announcement is quite simple:
sign = md5( md5(AppSecret) + ts ). In fact, it is to MD5 the AppSecret once, add the current timestamp, and MD5 the whole thing again.
Tips: The error of the timestamp cannot be too large and can be obtained dynamically when writing code.
Step 3: Core tactics - how to implement "custom linkage logic"?
Many friends will ask: "What I want is not to press the switch manually. What I want is 'if... then...'. How can I do this?"
In fact, the logic is very simple:Your server serves as the brain, and the PDU serves as the hands and feet.
You need to write a piece of logic (that is, a script) in your business system. This logic is responsible for monitoring various conditions. Once the conditions are triggered, the HTTP interface of Thingboot will be called.
Let’s look directly at how to adjust the interface.
1. Issue a command: cut off power to a certain jack
Suppose you detect that the server temperature is too high and you need to immediately turn off the cooling fan connected to "jack 1" and then restart it (that is, first off and then on), you can directly send a POST request.
interface address
https://api.thingboot.com/{Your AppID}/device/control/?sign={Signature}&ts={Timestamp}Request body format (JSON)
power1Represents the 1st jack. If it is to control the second one, it ispower2.0means closed,1Represents open.
Actual scenario walkthrough:Suppose you want to restart the optical modem (plugged into port 1), you need to power off first, wait 5 seconds and then power on again. Your Python code logic probably looks like this:
2. Batch operation: leave work or go to work with one click
If you are leaving get off work and want to turn off all devices except the "router" jack, you don't need to send 3 commands.
you candeviceOnly one device ID is written in the parameter, but inorderHere, the status of all roads is defined at once:
It's even simpler. If you want to turn it off completely, just send{"power":"off"}It's also possible.
3. Actual linkage: building a "watchdog" system
This is the most classic way to play PDU. For example, if the network in your home or computer room is unstable, and you want the PDU to automatically restart the dial-up device, you can't get up in the middle of the night and unplug it, right?
Logical design:
Monitoring script:Run a script on your server every 1 minute
pingCheck Baidu (or your gateway).Judgment logic: If ping fails for three consecutive times, it is determined as a "network failure".
perform action
Call the interface to turn off the jack where the "optical modem" and "main router" are located (for example, jacks 3 and 4).
Wait 10 seconds.
Call the interface to open jacks 3 and 4.
Send a notification to your mobile phone (Business WeChat/DingTalk/Bark, etc.).
In this way, you will have aSmart computer room with self-healing capabilities.
Step 4: Advanced gameplay - asynchronous messages and complex linkage
If you feel that it is too laborious to query every 1 minute, or you want to do more complex linkage (for example, press the button of the A socket, and the B socket lights up), you can use Thingboot'sPush messagemechanism.
Simply put, when the status of the PDU changes (for example, you press a physical button on the power strip, or the current overload trips), the cloud will actively push this event to the server address you configured.
You can take advantage of this:scene: When your PDU connected to the main circuit detects that the power is lower than 10W (indicating that the connected computer is shut down), it will automatically power off all slave circuit devices such as monitors, printers, and speakers next to it, truly achieving zero standby power consumption.
A Guide to Avoiding Pitfalls
This part is based on my experience and can help you save a lot of debugging time:
About signature: The signature string splicing must follow the official documentation. Many people report errors because the timestamp is not processed properly.
tslocation. If you are not sure, test it with Postman before writing the code..About feedback: Call the interface and return
code 200does not representThe power strip is really powered on! It just means "the order was issued". If the device is disconnected or the relay is stuck, you won't know.solution: If you want to ensure that the operation is really successful, use the query interface or directly read the current status of the device.
Power limit: Although this row of plugs is marked with a single hole of 1500W and a total power of 2500W-3000W, if it is an inductive load (such as a motor or compressor), the instantaneous current may be very large, leaving a margin..
Summarize
To put it bluntly, accessing the 5-digit PDU of Thingboot is actually adjusting an HTTP interface.
There are only three steps to your development:
Go backstage and get it
AppIDandSecret.Write the function that generates the signature.
Written
order={"powerX": 0/1}business logic.
When you complete these three steps, you will give this PDU "wisdom". It is no longer just a power strip, but the "last line of defense" in your entire automated operation and maintenance system - the capable person who can physically cut off power and help you solve the crash problem.
If you have any unresolved signature verification issues, or if you want to see specific Python/Java code snippets, you can communicate again at any time!