Equipment cloud timing control method, system and equipment based on MQTT protocol
By using the MQTT protocol -based equipment cloud end -control method in the Internet of Things scenario, the efficiency and accuracy of large -scale device cloud end -controlled efficiency and accuracy are solved, and efficient and reliable timing task management has been achieved. Capability.
Patent Information
- Application Number
- CN202411240145.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-05
- Publication Date
- 2025-01-24
AI Technical Summary
In the Internet of Things scenario, how to efficiently and accurately implement cloud-based timing control for large-scale devices, especially when the device is offline or without clock synchronization capabilities, how to ensure reliable triggering and management of timing tasks.
The cloud end -control method based on the MQTT protocol is adopted. By creating a timing task, the design of the device concentrated device subscribes to the TOPIC containing time -time information. The subscription instruction is issued under the cloud and the time control instruction is sent through the MQTT BROKER at the predetermined time point. When the device is re -connected after the device is offline, the relevant topic is automatically subscribed to receive the timing control instruction.
It significantly reduces the burden on cloud servers, improves resource usage efficiency, enhances time accuracy and device response accuracy, has higher scalability and stability, and can achieve punctual and reliable scheduled task execution in large-scale device scenarios.
Smart Images

Figure CN119363742A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a device cloud timing control method, system and device based on the MQTT protocol. Background Art
[0002] In recent years, the scale of my country's Internet of Things market has continued to grow, and various Internet of Things devices often have the need for scheduled tasks. There are several common implementation methods: (1) The device side implements the timing. The cloud sends the timing control instructions to the device in advance. The scheduled tasks are stored in the device and the device completes the timing control. The advantage of this method is that the scheduled task can still be triggered even if the device is offline. The disadvantage is that the device clock must be accurate and have the ability to synchronize the clock. However, some devices do not have the ability to synchronize the clock due to various reasons, such as network restrictions that cannot connect to the clock source, or cost factors, and the hardware does not have the ability to synchronize the clock. (2) The cloud sends the corresponding control instructions to the device at the time when the action needs to be triggered, and the timing is implemented in the cloud. The advantage of this implementation is that the device does not need to implement the scheduled task, and can implement more complex timing control, such as weekly timing, or requiring a trigger at 9:00 on weekdays. The cloud can synchronize the calendar to know whether it is a weekday, etc. The disadvantage is that it can only control online devices, and devices that are offline when the scheduled action is triggered cannot be controlled.
[0003] There are several ways to implement timing in the cloud: (1) The timing of each device is implemented separately, and one timing task is only for one device. Disadvantages: 1. When the number of devices is large enough, there are too many cloud timers, and the timing needs to be split into different services for implementation, which requires a lot of resources and is highly complex to implement. (2) The timing of the device is converted into the timing of several time points of the device timing, and the device set that needs to trigger the action at the same time is bound to the corresponding time point. After the timing task is triggered, control instructions are issued to the devices in the device set one by one. This method converts the timing of the number of devices into the timing of the timing point, reducing the number of timers. Disadvantages: When the control is issued to each device, when the device set is large, the issuance time is long, resulting in inaccurate device timing. If there are many timing controls for each device, the issuance of the first timing task cannot be completed between two timing tasks, resulting in backlogs. To solve this problem, the timing control of a large device set must be split into multiple device sets and assigned to multiple services, and each service completes the issuance of its own device set. This requires more cloud resources and is also more complex to implement. Summary of the invention
[0004] In view of the above-mentioned technical deficiencies, the technical problem to be solved by the present invention is to provide a device cloud timing control method, system and device based on the MQTT protocol. The aim is to solve the problem of how to efficiently and accurately implement cloud timing control for large-scale devices in the IoT scenario, while overcoming the challenges of device offline and resource consumption, and ensuring that reliable triggering and management of timing tasks can be achieved even when the device has no clock synchronization capability or the device set is large.
[0005] In order to solve the above technical problems, the present invention adopts the following technical solution: The present invention provides a device cloud timing control method based on the MQTT protocol, comprising:
[0006] Create a scheduled task and specify the devices in the device set to subscribe to the topic containing the scheduled time information;
[0007] The cloud sends instructions to the devices in the designated device set to subscribe to the Topic containing the timing information, and sends timing control instructions to the devices in the designated device set through the MQTT Broker at a predetermined time point;
[0008] The devices in the designated device set perform corresponding operations according to the instructions of the Topic containing the timing information and the timing control instructions issued by the cloud;
[0009] When a device in the designated device set is offline and then reconnected, all topics containing timing information are automatically re-subscribed according to the automatic subscription recovery logic, and the timing control instruction is kept received.
[0010] Furthermore, creating a scheduled task includes:
[0011] Create a scheduled task TimerA for the device, and analyze the time point when the scheduled task TimerA needs to be triggered;
[0012] Check whether there is an identical scheduled task TimerA. If not, create a device set deviceSetA corresponding to the timing point TimeA of the scheduled task TimerA. If yes, directly add the device to the device set deviceSetA corresponding to the timing point TimeA of the scheduled task TimerA. The device set deviceSetA corresponding to the timing point TimeA of the scheduled task TimerA is used as the designated device set.
[0013] Furthermore, the devices in the designated device set perform corresponding operations according to the instructions of the Topic containing the timing time information and the timing control instructions issued by the cloud, including: judging whether to execute the process of the Topic containing the timing time information required by the cloud according to the online status of the device; if it is online, executing the process of the Topic containing the timing time information required by the cloud, otherwise terminating the operation.
[0014] Furthermore, the process of executing the topic that the cloud requires the device to include timing information includes:
[0015] After receiving the instruction to subscribe to the Topic containing the timing information, the device in the designated device set checks whether it has been subscribed. If not, the device in the designated device set connects to the MQTT broker and initiates the subscription at the predetermined time point. If yes, the operation is terminated directly.
[0016] Furthermore, it is characterized in that
[0017] The automatic subscription recovery logic includes:
[0018] The device in the specified device set reconnects to the MQTT Broker, and the cloud receives a connection notification;
[0019] The cloud parses the device ID from the device connection message and searches for a scheduled task set TimerList containing the device from the scheduled task TimerA.
[0020] If yes, then traverse the scheduled task set TimerList, and execute the process of the cloud requiring the device to subscribe to the Topic containing the timing time information one by one for the scheduled task set TimerList;
[0021] If not, end the operation.
[0022] Furthermore, the cloud sends the timing control instruction to the devices in the designated device set through the MQTT Broker at a predetermined time point, including: the cloud sends the timing control instruction in batches to the subscribed devices through the MQTT Broker at the timing point TimeA.
[0023] Furthermore, the cloud sends the following timing control instructions to the subscribed devices in batches through the MQTT Broker at the timing point TimeA:
[0024] Scheduled task TimerA triggers timing point TimeA;
[0025] The cloud sends a timing control instruction to the Topic corresponding to the timing point TimeA;
[0026] The MQTT Broker forwards the received timing control instructions to all devices that subscribe to the Topic corresponding to the timing point.
[0027] A device cloud timing control system based on the MQTT protocol, comprising:
[0028] The device subscription management module is used to create a scheduled task and specify the device in the device set to subscribe to the topic containing the scheduled time information;
[0029] A subscription instruction issuing module, used for the cloud to issue instructions for subscribing to a Topic containing timing information to the devices in the specified device set, and to send the timing control instructions to the devices in the specified device set through the MQTT Broker at a predetermined time point;
[0030] A subscription instruction execution module, used for the devices in the specified device set to perform corresponding operations according to the instructions of the Topic containing the timing time information and the timing control instructions issued by the cloud;
[0031] The automatic subscription recovery module is used to automatically re-subscribe to all topics containing timing time information according to the automatic subscription recovery logic when the device in the designated device set is offline and then reconnected, and keep receiving the timing control instruction.
[0032] An electronic device comprises a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and is characterized in that when the processor executes the computer program, a device cloud timing control method based on the MQTT protocol is implemented.
[0033] A storable medium stores computer executable instructions, which, when executed by a processor, implement a device cloud timing control method based on the MQTT protocol.
[0034] The beneficial effects of the present invention are:
[0035] 1. The present invention significantly reduces the burden on cloud servers, simplifies cloud logic, and improves the efficiency of cloud resource utilization by transferring the execution logic of scheduled tasks from the cloud to the MQTT Broker. This is especially true in scenarios where a large number of device scheduled tasks need to be processed.
[0036] 2. The present invention enhances the time precision and the accuracy of device response. By subscribing to a topic containing timing information, the device can receive control instructions at a precise time point, thus ensuring the timely execution of the timing task.
[0037] 3. The present invention can better utilize the characteristics of MQTT Broker, so that the terminal timing can show higher scalability and stability when facing the increase in the number of devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0039] Figure 1 A schematic diagram of the operation of a device cloud timing control method based on the MQTT protocol provided in Example 1 of the present invention.
[0040] Figure 2 This is a graph showing 10,000 connections subscribing to the same topic and 10,000 subscriptions in Example 3 of the present invention.
[0041] Figure 3 This is a diagram of the number of messages before sending of any one of the 10,000 connections in Example 3 of the present invention.
[0042] Figure 4 This is a diagram of the number of messages sent by any one of the 10,000 connections in Example 3 of the present invention.
[0043] Figure 5 This is a memory growth graph when 10,000 connections are sent in Example 3 of the present invention.
[0044] Figure 6 This is a graph showing 20,000 connections subscribing to the same topic and 20,000 subscriptions in Example 3 of the present invention.
[0045] Figure 7 This is a diagram of the number of messages before sending of any one of the 20,000 connections in Example 3 of the present invention.
[0046] Figure 8 This is a diagram of the number of messages sent by any one of the 20,000 connections in Example 3 of the present invention.
[0047] Fig. 9 This is a memory growth chart when 20,000 connections are sent in Example 3 of the present invention. DETAILED DESCRIPTION
[0048] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0049] Example 1
[0050] like Figure 1 As shown, the present invention provides a device cloud-based timing control method based on the MQTT protocol, including: creating a timing task, specifying that devices in a device set subscribe to a Topic containing timing information; the cloud sends instructions to the devices in the specified device set to subscribe to the Topic containing timing information, and sends timing control instructions to the devices in the specified device set through the MQTTBroker at a predetermined time point; the devices in the specified device set perform corresponding operations according to the instructions of the Topic containing timing information and the timing control instructions sent by the cloud; wherein, when the devices in the specified device set are reconnected after being offline, they automatically re-subscribe to all Topics containing timing information according to the automatic subscription recovery logic, and keep receiving timing control instructions.
[0051] Specifically, creating a scheduled task includes: creating a scheduled task TimerA for the device, and parsing the time point at which the scheduled task TimerA needs to be triggered, such as 9:00 every day or 9:00 every Saturday; checking whether there is already the same scheduled task TimerA, if not, creating a device set deviceSetA corresponding to the timing point TimeA of the scheduled task TimerA; if yes, directly adding the device to the device set deviceSetA corresponding to the timing point TimeA of the scheduled task TimerA; wherein the device set deviceSetA corresponding to the timing point TimeA of the scheduled task TimerA is used as the designated device set; the devices in the designated device set perform corresponding operations according to the instructions of the Topic containing the timing time information and the timing control instructions issued by the cloud, including: judging whether to execute the process of the Topic containing the timing time information required by the cloud according to the online status of the device, if it is online, executing the process of the Topic containing the timing time information required by the cloud, otherwise terminating the operation.
[0052] Among them, the process of executing the topic that the cloud requires the device to contain timing information includes: after the device in the specified device set receives the instruction to subscribe to the topic containing timing information, it checks whether it has been subscribed. If not, the device in the specified device set connects to the MQTT broker and initiates the subscription of the timing point TimeA. If so, the operation is terminated directly.
[0053] Specifically, the automatic subscription recovery logic includes: the device in the specified device set reconnects to the MQTT Broker, and the cloud receives the connection notification; the cloud parses the device identifier from the device connection message, and searches from the scheduled task TimerA whether there is a scheduled task set TimerList containing the device; there may be multiple scheduled task sets TimerList; if there are, traverse the scheduled task set TimerList, and execute the process of the cloud requiring the device to subscribe to the Topic containing the timing information one by one for the scheduled task set TimerList; if not, end the operation.
[0054] Preferably, the cloud sends timing control instructions to the devices in the specified device set through the MQTT Broker at a predetermined time point, including: the cloud sends timing control instructions in batches to the subscribed devices through the MQTT Broker at the timing point TimeA, including: the timing task TimerA triggers the timing point TimeA; the cloud sends the timing control instructions to the Topic corresponding to the timing point TimeA; the MQTT Broker forwards the received timing control instructions to all devices subscribed to the Topic corresponding to the timing point.
[0055] It should be noted that: the present invention provides an implementation method for the cloud-based timing implementation method for issuing instructions with certain characteristics, using the characteristics of the MQTT protocol, and using the timing time as part of the complete topic information for the device to subscribe to and issue control instructions, such as 9:00 / receivectrl. The device subscribes to the topic, and after the timing time, the cloud only needs to issue instructions to a specific topic, here 9:00 / receivectrl, and the devices that subscribe to the topic, that is, the devices that need to trigger actions at a specific time point, can receive the corresponding control instructions. In essence, the group sending action originally implemented by the cloud is completed by the MQTT Broker.
[0056] The present invention is applicable to the MQTT protocol. The implementation on the device side needs to be able to blur the time attribute information of the subscribed topic and process it according to the non-time period in the topic information. It is applicable to instructions with the same control information sent to different devices. The fewer time points all devices need to control at a fixed time, the more obvious the effect. In actual use, the accuracy of most scenarios is minutes. The setting of the timing time is most often the hour, followed by the half hour, and then the 5 / 10 / 15 minute point. Scattered time points are rare. Therefore, the present invention has good applicability in actual scenarios.
[0057] The number of devices in the present invention can grow indefinitely, but the timing points are limited. Based on the cloud timing implementation scheme B, the characteristics of the MQTT protocol are used to subscribe a large set of devices for timing point operations to a specific topic in advance through the MQTT protocol. The device set that needs to trigger the timing task at the same time point subscribes to the same topic. For the instructions issued to each device, the application only needs to send one instruction to the corresponding topic, and the specific sending to each device is done by the MQTT borker, which gives full play to the characteristics of the MQTT borker's strong concurrent processing and high performance, and simplifies the application implementation.
[0058] Specifically, the management data structure of the device timing task is changed from: each device manages its own time: {device1, time1}, {device2, time2}... {deviceN, timeN}, to: {time1, {deviceSet1}}, {time2, {deviceSet2}}... {timeN, {deviceSetN}}, and the total number is a finite set with a certain upper limit under the premise of determining the time accuracy. In actual projects, the number of scheduled times is much smaller than the number of devices to improve management performance.
[0059] Example 2
[0060] Based on Example 1, this embodiment provides a system for a device cloud timing control method based on the MQTT protocol, including:
[0061] The device subscription management module is used to create a scheduled task and specify the device in the device set to subscribe to the topic containing the scheduled time information;
[0062] The subscription instruction sending module is used to send instructions for subscribing to the topic containing timing information to the devices in the specified device set from the cloud, and to send timing control instructions to the devices in the specified device set through the MQTT Broker at a predetermined time point;
[0063] The subscription instruction execution module is used to specify that the devices in the device set perform corresponding operations according to the instructions of the Topic containing the timing information and the timing control instructions issued by the cloud;
[0064] The automatic subscription recovery module is used to automatically re-subscribe to all topics containing timing information according to the automatic subscription recovery logic when the devices in the specified device set are offline and then reconnected, so as to keep receiving timing control instructions.
[0065] Example 3
[0066] This embodiment further provides a computing device, which is applicable to a device cloud timing control method based on the MQTT protocol, including:
[0067] A memory and a processor; the memory is used to store computer executable instructions, and the processor is used to execute computer executable instructions to implement a device cloud timing control method based on the MQTT protocol as proposed in the above embodiment.
[0068] The computer device may be a terminal, and the computer device includes a processor, a memory, a communication interface, a display screen and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, NFC (near field communication) or other technologies. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device may be a touch layer covering the display screen, or a key, trackball or touchpad provided on the housing of the computer device, or an external keyboard, touchpad or mouse, etc.
[0069] This embodiment also provides a storage medium on which a computer program is stored. When the program is executed by a processor, a device cloud timing control method based on the MQTT protocol is implemented as proposed in the above embodiment.
[0070] The storage medium proposed in this embodiment and the data storage method proposed in the above embodiment belong to the same inventive concept. The technical details not fully described in this embodiment can be found in the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.
[0071] Example 4
[0072] like Figure 2 to Figure 9 This example takes a cluster consisting of three MQTT brokers as an example. The software used is emqx. The group performance impact verification is performed on 10,000 and 20,000 devices respectively. The overall delivery is completed within 1 second, and the CPU fluctuation of emqx is small, with the highest point being 0.2, and the memory fluctuation is less than 40M as follows:
[0073] The number of messages that the MQTT broker of the present invention needs to send at a specific timing point does not increase, that is, the subscription request messages executed in advance are scattered. It only needs to complete the subscription before the scheduled task, and there is also a greater tolerance for delayed processing. It is not counted in the number of scheduled control messages. The cloud handles the scheduled tasks more simply. There is no need to manage a set of devices that need to be triggered at a timing point, but instead manages a set of devices that subscribe to the same topic. Usually, the concurrency performance of the MQTT broker is stronger than that of the application service. This implementation can make full use of this point, and the time when the device receives the scheduled instruction is also more accurate.
[0074] like Figure 2 to Figure 9 The system efficiency and stability after the implementation of the present invention are directly demonstrated, especially in the scenario of large-scale device connection and message delivery. Even under high load conditions, the present invention can still ensure efficient and stable communication, and has good control over system resource consumption such as CPU and memory. Figure 2 and Figure 6 Demonstrated the ability of MQTTBroker to handle a large number of subscription requests at different device scales; Figure 3 and Figure 7 , Figure 4 and Figure 8 It reflects the change in the number of messages of a single device before and after receiving the timing instruction, and indirectly reflects the system's precise control and low latency characteristics of message delivery; Figure 5 and Fig. 9 The memory usage is shown, demonstrating the efficient use of resources in large-scale deployments.
[0075] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A device cloud timing control method based on the MQTT protocol, characterized in that: include: Create a scheduled task and specify the devices in the device set to subscribe to the topic containing the scheduled time information; The cloud sends instructions to the devices in the designated device set to subscribe to the Topic containing the timing information, and sends timing control instructions to the devices in the designated device set through the MQTT Broker at a predetermined time point; The devices in the designated device set perform corresponding operations according to the instructions of the Topic containing the timing information and the timing control instructions issued by the cloud; When a device in the designated device set is offline and then reconnected, all topics containing timing information are automatically re-subscribed according to the automatic subscription recovery logic, and the timing control instruction is kept received.
2. A device cloud timing control method based on the MQTT protocol as claimed in claim 1, characterized in that: Creating a scheduled task includes: Create a scheduled task TimerA for the device, and analyze the time point when the scheduled task TimerA needs to be triggered; Check whether there is an identical scheduled task TimerA. If not, create a device set deviceSetA corresponding to the timing point TimeA of the scheduled task TimerA. If yes, directly add the device to the device set deviceSetA corresponding to the timing point TimeA of the scheduled task TimerA. The device set deviceSetA corresponding to the timing point TimeA of the scheduled task TimerA is used as the designated device set.
3. A device cloud timing control method based on the MQTT protocol as claimed in claim 1, characterized in that: The devices in the designated device set perform corresponding operations according to the instructions of the Topic containing timing information and the timing control instructions issued by the cloud, including: judging whether to execute the process of the Topic containing timing information required by the cloud according to the online status of the device; if it is online, executing the process of the Topic containing timing information required by the cloud, otherwise terminating the operation.
4. A device cloud timing control method based on the MQTT protocol as claimed in claim 2, characterized in that: The process of executing the topic that the cloud requires the device to include timing information includes: After receiving the instruction to subscribe to the Topic containing the timing information, the device in the designated device set checks whether it has been subscribed. If not, the device in the designated device set connects to the MQTT broker and initiates the subscription at the predetermined time point. If yes, the operation is terminated directly.
5. A device cloud timing control method based on the MQTT protocol as described in any one of claims 1 or 4, characterized in that: The automatic subscription recovery logic includes: The device in the specified device set reconnects to the MQTT Broker, and the cloud receives a connection notification; The cloud parses the device ID from the device connection message and searches for a scheduled task set TimerList containing the device from the scheduled task TimerA. If yes, then traverse the scheduled task set TimerList, and execute the process of the cloud requiring the device to subscribe to the Topic containing the timing time information one by one for the scheduled task set TimerList; If not, end the operation.
6. A device cloud timing control method based on the MQTT protocol as claimed in claim 1, characterized in that: The cloud sends the timing control instruction to the devices in the designated device set through the MQTT Broker at a predetermined time point, including: the cloud sends the timing control instruction in batches to the subscribed devices through the MQTT Broker at the timing point TimeA.
7. A device cloud timing control method based on the MQTT protocol as claimed in claim 6, characterized in that: At the time point TimeA, the cloud sends the following timing control instructions to the subscribed devices in batches through the MQTT Broker: The scheduled task TimerA triggers the timing point TimeA; The cloud sends a timing control instruction to the Topic corresponding to the timing point TimeA; The MQTT Broker forwards the received timing control instructions to all devices that subscribe to the Topic corresponding to the timing point.
8. A system based on the device cloud timing control method based on the MQTT protocol as claimed in claim 1, characterized in that: include: The device subscription management module is used to create a scheduled task and specify the device in the device set to subscribe to the topic containing the scheduled time information; A subscription instruction issuing module, used for the cloud to issue instructions for subscribing to a Topic containing timing information to the devices in the specified device set, and to send the timing control instructions to the devices in the specified device set through the MQTT Broker at a predetermined time point; A subscription instruction execution module, used for the devices in the specified device set to perform corresponding operations according to the instructions of the Topic containing the timing time information and the timing control instructions issued by the cloud; The automatic subscription recovery module is used to automatically re-subscribe to all topics containing timing time information according to the automatic subscription recovery logic when the device in the designated device set is offline and then reconnected, and keep receiving the timing control instruction.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, wherein: When the processor executes the computer program, the device cloud timing control method based on the MQTT protocol is implemented as described in any one of claims 1 to 7.
10. A storable medium storing computer executable instructions, which, when executed by a processor, implement the steps of a device cloud timing control method based on the MQTT protocol as described in any one of claims 1 to 7.