Thingboot's 40W speaker column has an HTTP interface, which can be connected to your own system through secondary development to realize automatic voice alarm playback. Below is a relatively complete set of solutions, ranging from interface principles to code implementation. You can adjust it according to the actual scenario.
1. Background and applicable scenarios
Thingboot's 40W smart voice column (usually UNI-YY-YZ-40W series) is different from ordinary Bluetooth speakers. It has its own network access capability (WiFi/wired network) and TTS chip. We don't need to transfer audio files to it, we just need to tell it "what to say" through HTTP, and it can synthesize speech directly on the hardware side..
This solution is particularly suitable for these scenarios:
industrial workshop: PLC or sensor detects a fault -> automatically triggers "Equipment High Temperature Warning".
Parking lot management: Abnormal occupancy is recognized -> Directly call for eviction.
Campus/park: Fire signal linkage -> Trigger alarm sound and evacuation instructions.
2. Core preparation: getting the key
Before you start writing code, you need to get two things (like the key and password for your door):
AppID and AppSecret (developer password)Log in to the Thingboot console and register a developer account. You can find these two strings of characters in "Development Settings".
AppIDIt is a public identity mark,AppSecretIt is private and must not be disclosed..Device IDFind the 40W speaker column in the device list of the console and copy its unique number. If there are multiple sound columns that need to be networked for broadcasting, the IDs can be separated by commas..
3. The most difficult step: signature calculation
Thingboot's interface uses dynamic signatures to prevent the interface from being called maliciously. To put it bluntly, it means mixing your password with the current timestamp to generate a temporary token that is only valid for this request.
The calculation rules are:sign = md5( md5(AppSecret) + ts )
Explain the steps of this formula in vernacular:
put yours first
AppSecretDo an MD5 encryption and get a string of 32-bit characters.Put the current timestamp (such as
1747212640) spliced to the string of characters just nowend.Then perform MD5 encryption on the spliced long string to get the final
sign.
For example (concept version):Assume the password is123456, the current time is1747212640.
The first step: md5(123456) =
e10adc...Step 2: Splicing ->
e10adc...1747212640Step 3: md5 (the above result) =
final sign
Notice:TimestamptsIt must also be passed to the interface as a parameter. The server will check the timestamp. If the time difference is too large (for example, more than a few minutes), even the password pair will be invalid. This is to prevent "replay attacks".
4. Secondary development practice: how to write code
Now that there is an open interface, you can use any language to adjust it. Here I usePythonandcommand lineFor example, because Python is most comfortable when writing this type of automated scripts.
1. Issue the "alarm playback" command
Suppose there is an emergency now, and you want the sound column to shout: "Warning, there is a fire in the workshop, please evacuate quickly!"
Request address (URL):https://api.thingboot.com/{your AppID}/device/control/?sign={calculated signature}&ts={current timestamp}
Request body (Body - JSON format):
2. Complete Python sample code
Write a complete script directly here, copy and paste and modify the variables to run:
3. AboutorderAdvanced configuration of fields
During secondary development, we can dynamically modifyorderThe content in it makes the broadcast more suitable for the scene:
Pre-alarm tone: The system has built-in
[alert_1]arrive[alert_5]Five warning tones, includingalert_3Usually a high-pitched fire engine siren sound, especially suitable for emergencies.Dynamically adjust volume: If you are afraid that it will be too noisy at ordinary times and force the alarm to be louder when the alarm is triggered, you can send a command to adjust the volume before broadcasting.
{"volume": "9"}(Volume level 0-9, 9 is the maximum)
Multi-device linkage: If there are several floors where the alarm needs to be heard,
deviceFields can be passed directly as strings, separated by commas, for example"device": "1001,1002,1003", one command can make the whole building ring..
5. Architectural ideas for connecting to own systems
To integrate this set of things into your existing system, you can probably play like this:
Lightweight integration (single point trigger): There is no need to build a server. Directly in your monitoring software or work order system, when an exception error occurs, add a line of code to call the above API.
Middle platform integration (business linkage): Your business system (such as ERP, SaaS) -> Thingboot Cloud API -> 40W sound column.
Private deployment (LAN mode): This is a highlight of Thingboot. If your factory intranet does not have an external network, or you are worried about delays, we support the establishment ofPrivate message server. At this time, the sound column and your server communicate in the same LAN without going through the external network, which is faster and safer..
6. Guide to avoid pitfalls
In actual testing, there are several places where problems are more likely to occur:
Signature error: This is the most common question. examine
tsIs it seconds level (10 digits) instead of milliseconds (13 digits)? Also make suremd5The result is a lowercase 32-bit string.Chinese encoding: In the request body
Content-TypeIt must beapplication/json, JSON itself supports Unicode, just fill in Chinese directly, no transcoding is required.Special character pronunciation: If the amount or mobile phone number is broadcast, you can mark it in the text. For example, when broadcasting "-20 degrees", TTS may pronounce it as "minus twenty degrees". In order to avoid ambiguity, it is best to separate the units or use more standardized expressions..
7. Summary
To put it bluntly, the second development of this 40W sound column isAdjust an HTTP interface. Core energy is mainly spent onGet that MD5 signatureOnce the logic of the signature is solved, all that is left is to usePOSTRequest that the text be sent over. You can directly use the above script to do a test in your system. First let the speaker shout "Hello World", and the subsequent logical connection will be smooth.