This is a solution for connecting with Thingboot smart air conditioner remote control to achieve "mobile phone control + status feedback". I will help you talk about this thoroughly in the order of "overall principle -> interface docking -> status feedback logic -> avoiding pitfalls".
Solution: Mobile air conditioner remote control and status feedback system based on Thingboot open interface
1. Pain point: Why must the "status feedback" be resolved after the air conditioner remote control is connected?
"Status feedback" simply means, is the air conditioner on or off now? Is the temperature 26 degrees or 24 degrees?
The most common pitfall is: the user clicks "Shut Down" on the mobile phone, and the interface shows that the air conditioner is turned off. But due to poor WiFi signal, misaligned infrared, or the air conditioner crashes, the air conditioner is actually still on. As a result, the user thought it was turned off and went on a trip, leaving the air conditioner on for a week.
this isThe command was issued, but the equipment did not execute it..
Thingboot’s open interface clearly states:The API returns 200, which only means that the platform has received the instruction and issued it to the device. It does not mean that the air conditioner has actually been executed.. Therefore, we must have a mechanism to confirm the status.
2. Overall structure: What do you need to prepare?
hardware:ThingbootSmart air conditioner remote control(It’s that little device with an infrared transmitter).
platform: Thingboot Open Platform (obtain AppID and AppSecret).
your mobile phone: Your App or mini-program.
Operation process:Mobile App -> (send commands) -> Thingboot Cloud -> air conditioner remote control (receive commands) -> infrared transmitter -> air conditioner
Status feedback path:Air conditioner (running status) -> Air conditioner remote control (sensing current/power? Or just one-way infrared?)Note: Ordinary infrared remote controls are one-way, and the air conditioner will not tell the remote control "I am off". We need to compensate for this through logic.
3. Specific docking steps
1. Preparation: Get the key
First, get yourAppIDandAppSecret.The signature algorithm is:sign = md5(md5(key) + timestamp). Just encapsulate this in the code, mainly for safety.
2. Core functions: How to control the air conditioner with your mobile phone?
we want to call"Send commands to the device"interface.
interface address
http(s)://api.thingboot.com/{AppID}/device/control/Request method:POST (recommended, longer parameters are better).
Key parameters
device: The ID of your air conditioner remote control (can be found on the device casing or console).order: This is a JSON string that tells the remote control what infrared code to send.
Example: Java/Python/JS logic pseudocode
3. Key difficulty: How to implement "status feedback"?
As mentioned above, Thingboot's equipment only returns "command has been delivered". In order to get the real air conditioner status, we have three levels of solutions:Use in sequence
Solution A: Rely on the device to proactively report (most recommended)Thingboot’s smart air conditioner remote control actually has a built-inInfrared code libraryandfeedback mechanism.when you send{"power":1}, the remote control emits an infrared code.If your air conditioner is a newer brand on the market (such as Gree, Midea, etc.), the remote control will turn on"Infrared return code"or"Power detection"Function.
logic: After the remote control transmits the code, it will monitor whether the air conditioner emits a "beep" reply sound or current fluctuations.
docking: You need to subscribe to ThingbootDevice status push(via MQTT or HTTP callback).
result: When the air conditioner is actually turned on, the cloud will push you a message
status: onlineOr specific temperature data, the mobile interface will then update the check mark.
Plan B: Polling query (a cover-up plan, suitable for old air conditioners without feedback)If your air conditioner is older and does not support status return, then you need to uselogically consistent.
Issue instructions: Send a command on the mobile phone, and the interface immediately turns gray or displays "Executing...".
delayed feedback:Set a timer (eg 5 seconds). Don't show success immediately.
No exception prompt: If no error report is received from the device within 5 seconds (
offline), we will default to air conditionerExecuted.Notice: This situation requires a little design on the UI, such as displaying "Signal has been sent" instead of "Air conditioner has responded".
Option C: Virtual mapping + sensor assistanceUtilize the Thingboot ecosystemTemperature and humidity sensor.
principle: If you issue a "cooling to 24 degrees" command. After 10 minutes, you check the temperature of the temperature and humidity sensor.
logic: If the temperature drops, it means the air conditioner is working; if the temperature does not change or even rises, it means the air conditioner is not turned on or the setting is wrong.
this is aClosed loop verification, although sometimes used in automation scenarios.
4. A slightly colloquial "Guide to avoid pitfalls"
Misunderstanding about "200 OK"A common mistake for novices is to see the interface return 200 or
{"code":200}, a pop-up window "Operation Successful" appears.Never!It is clearly written in the document: "200 only means that the platform has received the command...the device may be offline.".Correct approach: Received 200, just said "command has been issued". You have to wait until you receive the pushed "Execution Successful" event to be considered truly successful.Gateway problemIf the remote control is connected to 2.4G WiFi, the signal is very good. But if you put it in a metal cabinet or in a corner, the WiFi will be weak.There is one in the interface parameters
gateway, if the signal is not good, you can specify the gateway to forward. If the device is offline, you will receive504error code.Repeat commandThe user taps three times in succession to "cool down". Remember to do it on the front endThrottle. Because once there are too many infrared emissions, the air conditioner may not understand it (some air conditioners beep three times to change the temperature). It is best to disable the button for 1 second each time the mobile phone sends a command.
Private deploymentIf this is a solution for a large customer (such as a hotel), the customer is worried about data security. Thingboot device supportPrivatizationdeploy. You can connect all the data to the customer's own server instead of going to Thingboot's public cloud, so the delay is lower and more secure.
5. Summarize the code logic
If you were to write code now, the process would look like this:
User clicks "Start"->The interface displays Loading.
Call core step interface-> get
{"code":200}(If an error is reported, the user will be prompted that the network is abnormal).Enable MQTT monitoring(Or wait for HTTP callback):
if received
device_statusfor1, Loading becomes "on" and displays green status.If no message is received within 5 seconds, it will prompt "The device may be offline, please check the remote control network" and the status will be grayed out.
Refresh interface: Always keep the phone interface status = the last confirmed actual device status.
With this combo, your mobile app can not only control the air conditioner, but alsoAccurately tell users whether the air conditioner is obedient or not. This is basically the common practice for smart home apps currently on the market.