How to connect the 5-bit remote control sub-control PDU to the software project
1. Why does the school activity room need this?
Let’s talk about what problems we encountered first.
In activity rooms in schools (such as music classrooms, art workshops, and club activity rooms), cabinets are often stuffed with a lot of equipment - speakers, projectors, wireless microphone receivers, routers, etc. The previous management method was quite a headache:
Tired of manual management: Every time the activity room is used, the teacher has to turn on the equipment in advance and turn it off after use. If he forgets to turn it off, the equipment will stay on all night.
Big waste of resources: After the equipment is on standby for a day, the electricity bill is a trivial matter. The key is that the life of the equipment is affected.
safety hazard: Some students secretly use high-power electrical appliances and have to find someone to repair them if they trip.
What to do?Thingboot’s 5-bit remote control sub-control PDUIt just solves these problems. It is a dedicated smart power strip for cabinets that supports5 jacks independently controlled, each jack can be turned on and off independently, and can also be operated remotely through the HTTP interface.
This article will talk about how to "plug" this hardware into our existing software system, so that teachers can control the power of equipment in the activity room with the click of a button on a computer or mobile phone.
2. What is PDU? Let’s get to know each other briefly
First let’s make it clear what device we want to access.
Thingboot 5-bit sub-control smart PDUIt looks like this (imagine it):
5 national standard jacks, each can be controlled independently
Aluminum alloy shell, installed in the cabinet, has good heat dissipation and is strong
Supports WiFi 2.4G wireless networking, no need to buy additional gateway
Each hole supports a maximum of 1500W, and the entire unit supports a maximum of 3000W.
The most important thing: Open a complete HTTP interface, support remote switch and status query
The simple understanding is:A plug strip that can be connected to the Internet and programmable. You send it an HTTP request, and it turns a certain jack on or off for you.
3. How to access? Take it in three steps
The first step: Preparation work (configure the hardware to the Internet first)
After getting the PDU, you first need to connect it to the school’s WiFi.
Download and register: Go to the Thingboot official website to download their configuration tool (or use the App directly) and register an account.
Add device: Scan the QR code on the PDU (or enter the device ID) and follow the prompts to connect the PDU to the school’s 2.4G WiFi network.. Note: 5G WiFi does not work, you must use 2.4G.
Get key information: Make a note of this PDUDevice ID, and yoursAppIDandApp Key. These must be used for subsequent interface debugging.
Tips: If the WiFi signal in the activity room is not very good, PDU can set up 5 groups of backup WiFi, and it will automatically switch to the one with the strongest signal..
Step 2: Understand how to adjust the interface (out-of-the-box API)
The interface design of Thingboot is quite simple.You don’t need to learn complicated protocols, just know how to send HTTP requests.. Whether it is a Web system, a WeChat applet, or a mobile app, as long as it supports HTTP, you can directly call.
Core interface: issuing instructions to the device
Request address
http(s)://api.thingboot.com/{AppID}/device/control/?sign={sign}&ts={ts}Request method:POST (recommended) or GET
Core parameters
device: Fill in the device ID of the PDU, for example12345678order: Write here what you want to do, for example{"power1":1}Indicates opening the first jack
How to control 5 jacks specifically?
| action | Parameter writing method (order) | illustrate |
|---|---|---|
| Open route 1 | {"power1":1} | 1=on, 0=off |
| Close Route 3 | {"power3":0} | Same as above |
| Switch multiple channels simultaneously | {"power1":1,"power2":0,"power3":1} | Want to control which way to write which way? |
| One click to fully open | {"power":1} | master control order |
| One click to close everything | {"power":0} | Same as above |
How does a signature count? (Don’t be afraid, it’s not complicated)
For security, each request must be signed (sign) and timestamped (ts). The algorithm is roughly like this:
sign = md5(AppID + AppKey + ts)
Just put your AppID, AppKey and current timestamp together to calculate an MD5.
Give a practical example (pseudocode)
Notice: The interface returning 200 only means that the platform has received the instruction, but it does not mean that the device has actually executed it. To confirm the execution results, you must receive asynchronous message push from the cloud.
Step 3: Integrate into your software project (actual scenario)
In this step, we will combine the actual usage scenarios of the school to see how to write the code.
The first scenario: The music teacher turns on all devices with one click before class.
Music teachers need to use: speakers, projectors, wireless microphone receivers, and power amplifiers during class. These four devices are plugged into holes 1, 2, 3, and 4 of the PDU respectively.
The second scenario: get out of class is over, just turn off the projector and turn on the others for a while
Sometimes students have to copy courseware and the speakers have to be used for a while, so turn off the projector first to save power.
The third scenario: The teacher forgets to turn off the device, and the system automatically checks
Write a scheduled task to check the status of the activity room equipment at 10pm every night. If it is found that there is still a device on, it will be turned off automatically and a message will be sent to the teacher.
Scenario 4: Students secretly use high-power electrical appliances, intelligent identification
If the current in a certain hole (for example, reserved for students) is abnormal, you can directly turn it off or alarm. This needs to be matched with the power query interface of the PDU (Thingboot should also support it).
4. Several practical function extensions
After connecting, you can also do these fun things:
Reserved: The teacher reserves the activity room in the system in advance, and when the appointment time comes, the PDU automatically turns on the device. Automatically shuts off after use. No need for teachers to run around.
usage statistics: Record the usage time of each device and generate reports. By the end of the semester you will know which activity room is the most popular and which equipment is used the most.
remote maintenance: The projector or router crashed? Teachers don’t have to run to the activity room to restart. Click the "Restart" button on the software (first turn off and then on), and the device will be restored.
Abnormal alarm: If the device is left open for a long time (for example, more than 12 hours), the system will send a WeChat or SMS reminder to the administrator.
Unified certification of docking schools: It can be connected with the school's LDAP or DingTalk/Enterprise WeChat to enable teachers to scan the QR code to log in and control according to permissions.
5. Guide to Avoiding Pitfalls (Talk from Experience)
Let me tell you in advance about the pitfalls I have stepped on:
WiFi signal needs to be stable: The PDU uses 2.4G WiFi, if the activity room is in a remote corner, add a wireless AP or repeater. If the device goes offline, it cannot be controlled.
Don’t make a mistake with your signature: When generating sign, pay attention to the splicing order of AppID, AppKey, and ts. The timestamp is in seconds, not milliseconds. Newbies are most likely to fall over here.
Asynchronous confirmation is more reliable: The control interface returning 200 does not mean that the device is actually executed.. Subscribe to push messages to confirm device status, or poll the status interface.
Carry out permission control: Do not place high-risk operations such as turning off equipment on pages where students can click on them. If a student is pranked by a classmate and turns off the projector while giving a presentation... the situation will be very embarrassing.
Note the power rating: Maximum power of each hole is 1500W, the whole machine is 3000W. If the activity room has a high-power air conditioner or power amplifier, try to provide separate power supply instead of plugging it all into the PDU.
Leave a manual button: If the network goes down, students cannot attend class. Leave a physical switch or manual button in the activity room so that you can manually cut off the power in an emergency.
6. Summary
It is not technically difficult to connect Thingboot's 5-bit sub-control PDU to the school activity room management system.
For back-end development: It is an HTTP API encapsulation. Just refer to the official documentation and type the code. It can be done in an afternoon.
For front-end development: Just a few buttons, click to call the interface.
to school teachers: In the future, you can control the activity room equipment with just a few clicks on your computer or mobile phone, saving time and effort.
After doing this, the benefits are obvious:
Save power: The equipment will not be forgotten to turn off, which can save a lot of electricity bills in a year.
save trouble: Teachers don’t have to run around opening doors and closing equipment.
Safety: Abnormal power consumption can be detected in time to avoid fire hazards.
major: Information management, the usage status of the activity room is clear at a glance.
Hope this article can help you. If you encounter specific problems during access (such as being unable to get the signature, or being unable to understand the interface error), please feel free to communicate at any time. After all, our goals are the same:Make school management smarter and teachers more worry-free.