CATALOG

The key to the connection of smoke alarms is "event-driven" - silent monitoring at ordinary times, and triggering an alarm immediately once the smoke concentration exceeds the standard. Thingboot's open interface just supports this mode. Below I will explain step by step how to set up this closed loop.

Solution: Connect smoke alarms based on Thingboot’s open interface to implement fire alarms

Hello! Let’s talk about how to do it todayfire smoke alarmSeamlessly integrate into your system through Thingboot’s open interface.

Don’t worry, this sounds pretty hardcore, but in fact Thingboot’s interface is designed to be very user-friendly. Our goal is simple:Once the smoke alarm goes off, your mobile phone, management background or speaker can immediately know it and even respond automatically.

I will take you through this process below. Although it is detailed, I try to make it as easy as chatting.

Step One: Preparation—Know Your "Warriors"

Before we start writing code, we must first prepare the "things".

  1. Hardware equipment: You should have one in the Thingboot ecosystem.Smart smoke sensor. For example, products such as "Smart Human Presence Radar and Smoke Sensor [Wall Mounted]" commonly seen on their official website have integrated smoke sensor modules..

  2. Platform credentials

    • Register an account: First go to the Thingboot official website to register an account and log in to the workbench.

    • Get key: In "IoT Console" -> "Development Settings", find two key strings:AppID(developer ID) andAppSecret(developer password). These two are like the "user name" and "ultimate password" you need to enter the system. Be sure to keep them..

    • Device ID: In your console device list, find the smoke alarm and copy itsDevice ID(Device unique ID). This is the number of the "little soldier" you want to command..

  3. The network is smooth: Make sure your smoke alarm has been successfully configured through Wi-Fi and the online status is "active".

Step 2: Core logic - not only "hear" the alarm, but also "understand" the alarm

The docking logic of smoke alarms is different from that of ordinary switches. We take the initiative to control the switch (ask it to "turn on the lights"), while the alarm comes to us on its own initiative (to shout "fire").

There are two levels here:

  1. Passive reception (message push):This isThe most core and most real-timeway. You need to set up a server address (URL) accessible from the public network. After configuring this URL in the Thingboot console, as long as the smoke concentration reaches the threshold, the sensor will immediately push data to this address. When your server receives this HTTP request, you will know that something happened, and you can immediately send a text message or app notification to the administrator..

  2. Active query (optional): If you don’t have a public network server, or want to be a double insurance, you can also have your program proactively ask about the device status every few seconds. However, there is a delay in this method. It is not as good as pushing in real time..

Step 3: Practical drill - how to receive the "fire" signal

This is our most core step today. Assuming you already have a server (such as Alibaba Cloud or Tencent Cloud's ECS), we need to configure it to receive alarms.

Scenario: When the smoke alarm detects heavy smoke, it proactively tells your server.

The Thingboot platform will send a message to your server when the sensor status changes.HTTP POST request. Your server needs to write an interface to "catch" this request.

Development work you need to do (backend):

You need to write code to open an interface on your server (for example:http://yourdomain/api/smoke_callback). This interface is used to receive data from the platform.

What does the received data look like?Suppose you receive a JSON data packet pushed by the platform, which usually contains the device ID and smoke status:

Code processing logic (pseudocode idea):When your interface is called, you need to do these things:

  1. receive request: Get the JSON data sent by the platform.

  2. Parse data:have a lookalarm_statusIs it 1, orsmoke_concentrationIs it greater than the threshold you set (such as 50).

  3. trigger action

    • if it's a fire: Immediately call the SMS service provider's API to send text messages to the property manager; or send template messages to residents through the WeChat interface.

    • Linkage with other devices: At this time, you can call core step in reverse"Issuing instructions to the device" interface, turn on the exhaust fan, or let the smart speaker sound the "ding ding ding" alarm sound and voice evacuation prompts.

Step 4: Advanced linkage - what to do after calling the police?

Calling the police is only the first step, how to deal with it is the key. using core step"Send commands to the device"Interface, you can implement automated rescue.

Scenario: Smoke alarm -> trigger audible and visual alarm + turn on exhaust fan

At this time we have to take the initiative. usePOSTmethod callhttps://api.thingboot.com/{AppID}/device/control/interface.

Request example:

  • addresshttps://api.thingboot.com/yourAppID/device/control/?sign=calculated signature&ts=current timestamp

  • HeaderContent-Type: application/json

  • Body (JSON)

At the same time, send another command to the sound and light alarm:

Notice: When issuing an order, a signature (Sign) is required. The official signature algorithm is very clear:Sign = md5( md5(AppSecret) + ts ). Just MD5 your developer password once, splice it with the timestamp, and then MD5 the whole thing again.. But don’t be afraid, the official documentation provides demos in various languages ​​​​(CURL, Java, C, etc.), you can just copy and paste and change the parameters to use it..

Step 5: The easiest pitfall (intimate tips)

  1. Signature problem: This is the reason why 90% of developers fail to connect for the first time. Remember to check that the timestamp isSecond level(10 digits) instead of milliseconds (13 digits). In addition, if you are just doing functional verification, you can temporarily turn on "debug mode" in the development settings. At this time, the systemDon't check signature, so that you can run through the process first.

  2. IP whitelist: If it is a production environment, remember to add the server's public IP to the whitelist of the console, otherwise the interface will be rejected..

  3. Command format: Different device commands are different. For smoke sensors, the status is usually read; for speakers or power strips, commands are issued.Be sure to read the "Product Manual" of the corresponding product, there will be details in itpower=1stillswitch=on.

  4. Network stability: Wi-Fi smoke sensors rely on the home network. Turn on the "offline monitoring" function of the device. If the device goes offline, your system must be able to sense it and remind the user to check the network.

Summarize

Connecting to Thingboot’s fire and smoke alarm is essentially three steps:

  1. receive: Write an interface and wait to receive the "fire" notification proactively sent by the sensor.

  2. judge: Determine whether the smoke concentration in the data exceeds the standard.

  3. hair: Once a fire is confirmed, immediately send instructions to other equipment such as exhaust fans and speakers for linkage.

As long as you follow this idea and complete the first step of "receiving callbacks", the entire system will be alive. Thingboot's interface documentation is very detailed. As long as you calm down and read it, you can basically run through the first process in ten minutes. I hope your fire warning system will be online soon to protect everyone’s safety!