Device switching method and apparatus based on lightweight message transmission protocol

By monitoring MQTT broker switching messages and selecting a target broker based on load information, combined with distributed caching and synchronization technologies, the data synchronization and consistency issues during MQTT broker switching are resolved, ensuring timely data synchronization and system stability during the switching process.

CN119363548BActive Publication Date: 2025-11-14GREE ELECTRIC APPLIANCE INC OF ZHUHAI +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411495180.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-24
Publication Date
2025-11-14
Estimated Expiration
2044-10-24

AI Technical Summary

Technical Problem

During MQTT broker switching, existing technologies struggle to guarantee message synchronization and consistency, especially when a device switches from one broker to another, which can easily lead to data loss and inconsistency.

Method used

By monitoring MQTT agent switching messages, the load information of each agent in the control platform where the target smart device is located is obtained. The target agent is selected based on the load information, and distributed caching and synchronization are performed during the switching process to ensure timely data synchronization and avoid data loss.

Benefits of technology

It enables timely synchronization of messages and data when devices switch connections, improving message synchronization and consistency, enhancing system stability and reliability, and making it suitable for IoT application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119363548B_ABST
    Figure CN119363548B_ABST
Patent Text Reader

Abstract

This invention discloses a device switching method and apparatus based on the Lightweight Message Transfer Protocol (MQTT). The method includes: upon detecting a switching message from a MQTT broker, determining the target smart device requiring MQTT broker switching based on the switching message; obtaining load information of each MQTT broker in the control platform where the target smart device resides, wherein the load information indicates the number of smart devices in the smart home system currently managed by each MQTT broker; determining the target MQTT broker to which the target smart device should switch based on the load information; and switching the target smart device from the current MQTT broker to the target MQTT broker. This invention solves the technical problem in related technologies where MQTT brokers are typically deployed at a single point, relying on a single broker for message transmission and processing, making it difficult to guarantee message synchronization and consistency when devices switch to different brokers.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data transmission technology, and more specifically, to a device switching method and apparatus based on a lightweight message transmission protocol. Background Technology

[0002] MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol. In practical applications, devices may need to switch connections to different MQTT brokers due to network fluctuations, mobility, or other reasons. However, during the switching process, data synchronization and message consistency become critical issues. If a device loses messages or fails to synchronize data in a timely manner during the switching process, it will lead to system instability and data inconsistency.

[0003] In existing technologies, MQTT brokers are typically deployed at a single point, relying on a single broker for message transmission and processing. When devices switch to different brokers, message synchronization and consistency are difficult to guarantee. Furthermore, existing distributed caching technologies lack specific optimizations for handling MQTT messages, making it impossible to efficiently achieve data synchronization during device switching.

[0004] There is currently no effective solution to the above problems. Summary of the Invention

[0005] This invention provides a device switching method and apparatus based on a lightweight message transmission protocol, which at least solves the technical problem in related technologies where MQTT brokers are usually deployed at a single point and rely on a single broker for message transmission and processing. When a device switches to a different broker, it is difficult to guarantee message synchronization and consistency.

[0006] According to one aspect of the present invention, a device switching method based on a Lightweight Messaging Protocol (MQTT) is provided, comprising: upon detecting a switching message of a MQTT broker, determining a target smart device requiring MQTT broker switching based on the switching message; obtaining load information of each MQTT broker in the control platform where the target smart device is located, wherein the load information is used to indicate the number of smart devices in the smart home system where the target smart device is located, currently managed by each MQTT broker; determining the target MQTT broker to which the target smart device is switching based on the load information; and switching the target smart device from the current MQTT broker to the target MQTT broker.

[0007] Optionally, detecting a switching message from the Lightweight Message Transfer Protocol (MQTT) broker includes: monitoring the device connection status of the target smart device and obtaining a monitoring result; when the monitoring result indicates that the device connection status has changed, determining that a switching message from the MQTT broker has been detected, wherein the change includes at least one of the following: the location of the target smart device has changed, or the target smart device experiences network latency.

[0008] Optionally, obtaining the load information of each MQTT agent in the control platform where the target smart device is located includes: obtaining the agent information of the MQTT agents currently connected to each smart device in the smart home system; determining the number of smart devices currently managed by each MQTT agent based on the agent information; and obtaining the load information of each MQTT agent based on the number of devices.

[0009] Optionally, the device switching method based on the Lightweight Message Transmission Protocol further includes: during the process of switching the target smart device from the current MQTT broker to the target MQTT broker, monitoring the connection status between the target smart device and the target MQTT broker, and obtaining monitoring results; when the monitoring results indicate that the connection between the target smart device and the target MQTT broker is abnormal, triggering the connection switching process of the target smart device.

[0010] Optionally, monitoring the connection status between the target smart device and the target MQTT broker includes: the target smart device sending heartbeat data packets to the target MQTT broker at predetermined intervals; in each predetermined interval, after determining that the target smart device has sent the heartbeat data packet to the target MQTT broker, obtaining the feedback result of the target MQTT broker to the heartbeat data packet to monitor the connection status, wherein the feedback result indicates that the MQTT broker does not respond to the heartbeat data packet within a predetermined time period, and the connection status is determined to be a connection failure; when the feedback result indicates that the MQTT broker responds to the heartbeat data packet within the predetermined time period, the connection status is determined to be a connection success.

[0011] Optionally, determining that the target smart device is switched from the current MQTT broker to the target MQTT broker includes: obtaining the latest data of the target smart device from other cache nodes through the target MQTT broker, wherein the other cache nodes are cache nodes deployed on other MQTT brokers besides the target MQTT broker, and the latest data includes the device information of the target smart device and the interaction information of the target smart device.

[0012] Optionally, obtaining the latest data of the target smart device from other cache nodes through the target MQTT broker includes: determining the identification information of the latest data; and obtaining the latest data of the target smart device from the other cache nodes through the target MQTT broker when it is determined from the identification information that the latest data does not duplicate the current data of the target smart device already cached by the target MQTT broker.

[0013] Optionally, the device switching method based on the Lightweight Message Transfer Protocol further includes: deploying cache nodes on each of the MQTT brokers of the control platform; selecting a primary cache node from the plurality of cache nodes, so that when a smart device in the smart home system publishes a message, the message is distributed to other cache nodes besides the primary cache node through the primary cache node, wherein when the smart device publishes the message, the message is first sent to the primary cache node.

[0014] According to another aspect of the present invention, a device switching apparatus based on Lightweight Messaging Protocol (MQTT) is also provided, comprising: a first determining unit, configured to determine a target smart device requiring MQTT agent switching based on a switching message detected by the MQTT agent; an acquiring unit, configured to acquire load information of each MQTT agent in the control platform where the target smart device is located, wherein the load information indicates the number of smart devices in the smart home system where the target smart device is located, currently managed by each MQTT agent; a second determining unit, configured to determine the target MQTT agent to which the target smart device is switched based on the load information; and a switching unit, configured to switch the target smart device from the current MQTT agent to the target MQTT agent.

[0015] Optionally, the first determining unit includes: a monitoring module, configured to monitor the device connection status of the target smart device and obtain a monitoring result; and a first determining module, configured to determine that a switching message of the MQTT broker has been detected when the monitoring result indicates that the device connection status has changed, wherein the change includes at least one of the following: the location of the target smart device has changed, or the target smart device has network latency.

[0016] Optionally, the acquisition unit includes: a first acquisition module, configured to acquire proxy information of the MQTT proxy currently connected to each of the smart devices in the smart home system; a second determination module, configured to determine the number of smart devices currently managed by each of the MQTT proxies based on the proxy information; and a second acquisition module, configured to acquire the load information of each of the MQTT proxies based on the number of devices.

[0017] Optionally, the device switching device based on the Lightweight Message Transmission Protocol further includes: a monitoring unit, used to monitor the connection status between the target smart device and the target MQTT agent during the process of switching the target smart device from the current MQTT agent to the target MQTT agent, and obtain monitoring results; and a triggering unit, used to trigger the connection switching process of the target smart device when the monitoring results indicate that the connection between the target smart device and the target MQTT agent is abnormal.

[0018] Optionally, the monitoring unit includes: a sending module, configured to send heartbeat data packets to the target MQTT agent via the target smart device at predetermined intervals; and a third acquisition module, configured to, at each predetermined interval, after determining that the target smart device has sent the heartbeat data packet to the target MQTT agent, acquire the feedback result of the target MQTT agent to the heartbeat data packet, so as to monitor the connection status, wherein the feedback result indicates that when the MQTT agent does not respond to the heartbeat data packet within a predetermined time period, the connection status is determined to be a connection failure; and when the feedback result indicates that the MQTT agent responds to the heartbeat data packet within the predetermined time period, the connection status is determined to be a connection success.

[0019] Optionally, the switching unit includes: a fourth acquisition module, configured to, after determining that the target smart device has switched from the current MQTT broker to the target MQTT broker, acquire the latest data of the target smart device from other cache nodes through the target MQTT broker, wherein the other cache nodes are cache nodes deployed on other MQTT brokers besides the target MQTT broker, and the latest data includes device information of the target smart device and interaction information of the target smart device.

[0020] Optionally, the fourth acquisition module includes: a determining submodule, used to determine the identification information of the latest data; and an acquisition submodule, used to acquire the latest data of the target smart device from other cache nodes through the target MQTT agent when it is determined from the identification information that the latest data does not duplicate the current data of the target smart device already cached by the target MQTT agent.

[0021] Optionally, the device switching device based on the Lightweight Message Transmission Protocol further includes: a deployment unit for deploying cache nodes on each of the MQTT brokers of the control platform; and a selection unit for selecting a primary cache node from the plurality of cache nodes, so that when a smart device in the smart home system publishes a message, the message is distributed to other cache nodes besides the primary cache node through the primary cache node, wherein when the smart device publishes the message, the message is first sent to the primary cache node.

[0022] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored program, wherein the program executes the device switching method based on the Lightweight Message Transfer Protocol as described in any one of the above embodiments.

[0023] According to another aspect of the present invention, a processor is also provided, the processor being configured to run a program, wherein the program, when running, executes the device switching method based on the Lightweight Message Transfer Protocol as described above.

[0024] According to another aspect of the present invention, a computer program product is also provided, including computer instructions, which, when executed by a processor, perform the device switching method based on the Lightweight Message Transfer Protocol described in any one of the above embodiments.

[0025] In this embodiment of the invention, upon detecting a switching message from a Lightweight Message Transfer Protocol (MQTT) broker, the target smart device requiring MQTT broker switching is determined based on the switching message; the load information of each MQTT broker in the control platform where the target smart device resides is obtained, wherein the load information indicates the number of smart devices in the smart home system currently managed by each MQTT broker; the target MQTT broker to which the target smart device is switching is determined based on the load information; and the target smart device is switched from the current MQTT broker to the target MQTT broker. Through the technical solution provided by this invention, distributed caching and synchronization technologies are used to ensure timely synchronization of messages and data when a device switches connections, avoiding data loss. This achieves the technical effect of improving message synchronization and consistency, thereby solving the technical problem in related technologies where MQTT brokers are typically deployed at a single point, relying on a single broker for message transmission and processing, making it difficult to guarantee message synchronization and consistency when a device switches to different brokers. Attached Figure Description

[0026] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:

[0027] Figure 1 This is a hardware structure block diagram of a mobile terminal for a device switching method based on a lightweight message transmission protocol according to an embodiment of the present invention.

[0028] Figure 2 This is a flowchart of a device switching method based on a lightweight messaging protocol according to an embodiment of the present invention;

[0029] Figure 3 This is a flowchart of an optional device switching method based on a lightweight messaging protocol according to an embodiment of the present invention;

[0030] Figure 4 This is a schematic diagram of a device switching device based on a lightweight message transmission protocol according to an embodiment of the present invention. Detailed Implementation

[0031] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0032] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0033] As described in the background section, MQTT brokers in related technologies are typically deployed at a single point, relying on a single broker for message transmission and processing. When devices switch to different brokers, message synchronization and consistency are difficult to guarantee. To address these shortcomings, embodiments of the present invention provide a device switching method and apparatus based on a lightweight message transmission protocol, a computer-readable storage medium, a processor, and a computer program product.

[0034] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.

[0035] The methods and embodiments provided in this invention can be executed on a mobile terminal, a computer terminal, or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal for a device switching method based on a lightweight messaging protocol, according to an embodiment of the present invention. Figure 1 As shown, a mobile terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.

[0036] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the device switching method based on the Lightweight Message Transfer Protocol in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the aforementioned networks may include wireless networks provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0037] According to an embodiment of the present invention, a method embodiment of a device switching method based on a lightweight messaging protocol is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0038] Figure 2 This is a flowchart of a device handover method based on a lightweight messaging protocol according to an embodiment of the present invention, such as... Figure 2 As shown, the device handover method based on the Lightweight Messaging Protocol includes the following steps:

[0039] Step S202: When a switch message for the Lightweight Message Transfer Protocol (MQTT) broker is detected, the target smart device that needs to switch the MQTT broker is determined based on the switch message.

[0040] In this embodiment, the MQTT broker switching messages of smart devices are monitored in real time, and then the target smart device for MQTT broker switching is determined based on the switching messages.

[0041] The aforementioned smart devices and target smart devices are all smart devices within a smart home system, such as refrigerators, air conditioners, washing machines, and televisions in a user's home.

[0042] Step S204: Obtain the load information of each MQTT agent in the control platform where the target smart device is located. The load information is used to indicate the number of smart devices in the smart home system where the target smart device is currently managed by each MQTT agent.

[0043] In this embodiment, load balancing can be performed among multiple MQTT brokers to avoid overloading a single broker.

[0044] Step S206: Determine the target MQTT broker switched by the target smart device based on the load information.

[0045] In this embodiment, the target MQTT broker that the target smart device switches to can be selected based on the load information determined above.

[0046] Step S208: Switch the target smart device from the current MQTT broker to the target MQTT broker.

[0047] As described above, in this embodiment of the invention, when a switching message of the Lightweight Message Transfer Protocol (MQTT) agent is detected, the target smart device requiring MQTT agent switching is determined based on the switching message; the load information of each MQTT agent in the control platform where the target smart device is located is obtained, wherein the load information is used to indicate the number of smart devices in the smart home system where the target smart device is currently managed by each MQTT agent; the target MQTT agent to which the target smart device is switching is determined based on the load information; and the target smart device is switched from the current MQTT agent to the target MQTT agent. This achieves the goal of ensuring timely synchronization of messages and data when the device switches connections through distributed caching and synchronization technology, avoiding data loss, and thus achieving the technical effect of improving message synchronization and consistency.

[0048] Therefore, the technical solutions provided by the embodiments of the present invention solve the technical problem in the related technologies that MQTT brokers are usually deployed at a single point, rely on a single broker for message transmission and processing, and when the device switches to different brokers, it is difficult to guarantee message synchronization and consistency.

[0049] According to the above embodiments of the present invention, detecting a switching message of the Lightweight Message Transfer Protocol (MQTT) broker includes: monitoring the device connection status of the target smart device and obtaining a monitoring result; when the monitoring result indicates that the device connection status has changed, determining that a switching message of the MQTT broker has been detected, wherein the change includes at least one of the following: the location of the target smart device has changed, or the target smart device has network latency.

[0050] In this embodiment, when a device (i.e., a smart device) needs to switch to a new MQTT broker due to network fluctuations or mobility, it will detect the MQTT broker switching message.

[0051] According to the above embodiments of the present invention, obtaining the load information of each MQTT agent in the control platform where the target smart device is located may include: obtaining the agent information of the MQTT agents currently connected to each smart device in the smart home system; determining the number of smart devices currently managed by each MQTT agent based on the agent information; and obtaining the load information of each MQTT agent based on the number of devices.

[0052] In this embodiment, load balancing can be performed among multiple MQTT brokers to prevent overload of a single MQTT broker. For example, connections can be dynamically allocated to the most suitable MQTT broker based on factors such as the smart device's geographical location and network latency.

[0053] According to the above embodiments of the present invention, the device switching method based on the Lightweight Message Transmission Protocol further includes: during the process of switching the target smart device from the current MQTT broker to the target MQTT broker, monitoring the connection status between the target smart device and the target MQTT broker, and obtaining monitoring results; when the monitoring results indicate that the connection between the target smart device and the target MQTT broker is abnormal, triggering the connection switching process of the target smart device.

[0054] In this embodiment, when a device needs to switch connections to a new MQTT broker due to network fluctuations or mobility, the new broker obtains the latest messages and data from the device through the data synchronization module. The device connection management module is responsible for coordinating the device connection switch to ensure a smooth transition during the switchover process.

[0055] In this embodiment, connection status monitoring is also performed, that is, the connection status of the device is monitored in real time, and when a connection abnormality is detected, the connection switching process is automatically triggered.

[0056] According to the above embodiments of the present invention, monitoring the connection status between a target smart device and a target MQTT broker includes: sending heartbeat data packets to the target MQTT broker at predetermined intervals by the target smart device; in each predetermined interval, after determining that the target smart device has sent heartbeat data packets to the target MQTT broker, obtaining the feedback result of the target MQTT broker on the heartbeat data packets to monitor the connection status, wherein the connection status is determined to be a connection failure when the feedback result indicates that the MQTT broker has not responded to the heartbeat data packets within a predetermined time period; and the connection status is determined to be a connection success when the feedback result indicates that the MQTT broker has responded to the heartbeat data packets within a predetermined time period.

[0057] In this embodiment, a heartbeat mechanism can be used to periodically detect the online status of the device to ensure connection stability.

[0058] According to the above embodiments of the present invention, determining that a target smart device is switched from the current MQTT broker to the target MQTT broker includes: obtaining the latest data of the target smart device from other cache nodes through the target MQTT broker, wherein the other cache nodes are cache nodes deployed on other MQTT brokers besides the target MQTT broker, and the latest data includes the device information and interaction information of the target smart device.

[0059] In this embodiment, a cache node is deployed on each MQTT broker, and data synchronization between the cache nodes is achieved through distributed caching technology.

[0060] The process involves obtaining the latest data of the target smart device from other cache nodes through the target MQTT broker, including: determining the identification information of the latest data; and obtaining the latest data of the target smart device from other cache nodes through the target MQTT broker when it is determined from the identification information that the latest data does not duplicate the current data of the target smart device already cached by the target MQTT broker.

[0061] Optionally, the above identification information may include a timestamp or version number.

[0062] In this embodiment, when a device switches to a new MQTT broker, the new broker synchronizes the device's latest messages and data from other cache nodes. Timestamps or version numbers are used to ensure data up-to-dateness and avoid data conflicts. Data transmission is optimized by using incremental synchronization technology, transmitting only changed data to reduce network bandwidth consumption.

[0063] According to the above embodiments of the present invention, the device switching method based on the Lightweight Message Transmission Protocol further includes: deploying cache nodes on each MQTT agent of the control platform; selecting a master cache node from multiple cache nodes so that when a smart device in the smart home system publishes a message, the message is distributed to other cache nodes besides the master cache node through the master cache node, wherein when a smart device publishes a message, the message is first sent to the master cache node.

[0064] In this embodiment, consensus algorithms such as Paxos and Raft can be used to ensure message order and consistency. These algorithms elect a master node through an election mechanism to coordinate message processing and synchronization. Furthermore, in this embodiment, the message processing flow is as follows: When a device publishes a message, the message is first sent to the master node. The master node distributes the message to other cache nodes and ensures message order consistency across all nodes using a consensus algorithm. Once the message is acknowledged on a majority of nodes, the master node commits the message and notifies the device.

[0065] Figure 3 This is a flowchart of an optional device handover method based on a lightweight messaging protocol according to an embodiment of the present invention, such as... Figure 3As shown, firstly, cache nodes can be deployed using a distributed caching module: cache nodes are deployed on each MQTT broker, and data synchronization between cache nodes is achieved through distributed caching technology. A distributed hash table (DHT) is used to distribute and store device messages and data across multiple cache nodes. Each cache node is responsible for a specific range of data, and the storage location of the data is calculated using a hash function. When a device switches connections, the latest messages and data are retrieved through a synchronization mechanism. Synchronization Mechanism: When a device switches to a new MQTT broker, the new broker synchronizes the device's latest messages and data from other cache nodes. Timestamps or version numbers are used to ensure data up-to-dateness and avoid data conflicts. Data Transmission Optimization: Incremental synchronization technology is used to transmit only changed data, reducing network bandwidth consumption. Compression algorithms are used to further optimize data transmission efficiency.

[0066] In addition, such as Figure 3 As shown, consensus algorithms such as Paxos and Raft are used to ensure message ordering and consistency. These algorithms elect a master node through an election mechanism to coordinate message processing and synchronization. Message processing flow: When a device publishes a message, the message is first sent to the master node. The master node distributes the message to other cache nodes and ensures message order consistency across all nodes through consensus algorithms. Once the message is acknowledged on a majority of nodes, the master node commits the message and notifies the device. Fault handling: In the event of a master node failure, a new master node is elected through a consensus algorithm to continue handling message processing and synchronization. A logging mechanism is used to ensure that uncommitted messages can be resynchronized after a node recovers. Log recording continuously monitors device connections to monitor network fluctuations or connection stability. If device instability is detected, a connection switchover process is automatically triggered. Conversely, a heartbeat mechanism periodically checks the device's online status to ensure connection stability. Load balancing is also performed between MQTT brokers to prevent overload of any single broker.

[0067] Therefore, the technical solutions provided by the embodiments of the present invention introduce distributed caching among multiple MQTT brokers to store and synchronize device messages and data, ensuring that messages and data can be synchronized in a timely manner when devices switch connections, avoiding data loss and inconsistency; designing an efficient data synchronization algorithm ensures that devices can obtain the latest messages and data in a timely manner when switching connections; and using a consistency algorithm ensures the consistency and order of messages when devices switch between different MQTT brokers, effectively solving the data synchronization and message consistency problems when devices switch connections, improving the stability and reliability of the system, and making it suitable for various IoT application scenarios.

[0068] Furthermore, in this embodiment of the invention, distributed caching technology is used to improve the message processing capability of the MQTT broker, thereby enhancing the stability and reliability of the system. Moreover, distributed caching and synchronization mechanisms reduce network latency when devices switch connections, improve the system's response speed, and provide strong scalability, making it suitable for various IoT application scenarios.

[0069] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

[0070] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0071] According to embodiments of the present invention, a device handover apparatus based on a lightweight messaging protocol is also provided for implementing the above-described device handover method based on a lightweight messaging protocol. Figure 4 This is a schematic diagram of a device switching device based on a lightweight messaging protocol according to an embodiment of the present invention, such as... Figure 4 As shown, the device includes: a first determining unit 401, an acquiring unit 403, a second determining unit 405, and a switching unit 407. The device switching device based on the Lightweight Message Transmission Protocol will now be described.

[0072] The first determining unit 401 is used to determine the target smart device that needs to switch the MQTT agent when a switching message of the Lightweight Message Transfer Protocol (MQTT) agent is detected.

[0073] The acquisition unit 403 is used to acquire the load information of each MQTT agent in the control platform where the target smart device is located. The load information is used to indicate the number of smart devices in the smart home system where the target smart device is currently managed by each MQTT agent.

[0074] The second determining unit 405 is used to determine the target MQTT broker switched by the target smart device based on the load information.

[0075] Switching unit 407 is used to switch the target smart device from the current MQTT broker to the target MQTT broker.

[0076] It should be noted that the first determining unit 401, the obtaining unit 403, the second determining unit 405, and the switching unit 407 mentioned above correspond to steps S202 to S208 in the above embodiments. The four units and the corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in the above embodiments.

[0077] As can be seen from the above, in the scheme described in the above embodiments of the present invention, the first determining unit can determine the target smart device that needs to switch MQTT agents based on the switching message when a switching message of the Lightweight Message Transfer Protocol (MQTT) agent is detected; the acquiring unit can acquire the load information of each MQTT agent in the control platform where the target smart device is located, wherein the load information is used to indicate the number of smart devices in the smart home system where the target smart device is currently managed by each MQTT agent; the second determining unit can determine the target MQTT agent to which the target smart device is switched based on the load information; and the switching unit can switch the target smart device from the current MQTT agent to the target MQTT agent. This achieves the purpose of ensuring that the messages and data of the device can be synchronized in a timely manner when switching connections through distributed caching and synchronization technology, avoiding data loss, and achieving the technical effect of improving message synchronization and consistency.

[0078] Therefore, the technical solutions provided by the embodiments of the present invention solve the technical problem in the related technologies that MQTT brokers are usually deployed at a single point, rely on a single broker for message transmission and processing, and when the device switches to different brokers, it is difficult to guarantee message synchronization and consistency.

[0079] Optionally, the first determining unit includes: a monitoring module, used to monitor the device connection status of the target smart device and obtain a monitoring result; and a first determining module, used to determine that a switching message of the MQTT broker has been detected when the monitoring result indicates that the device connection status has changed, wherein the change includes at least one of the following: the location of the target smart device has changed, or the target smart device has network latency.

[0080] Optionally, the acquisition unit includes: a first acquisition module, used to acquire agent information of the MQTT agent currently connected to each smart device in the smart home system; a second determination module, used to determine the number of smart devices currently managed by each MQTT agent based on the agent information; and a second acquisition module, used to acquire the load information of each MQTT agent based on the number of devices.

[0081] Optionally, the device switching device based on the Lightweight Message Transmission Protocol further includes: a monitoring unit, used to monitor the connection status between the target smart device and the target MQTT agent during the process of switching the target smart device from the current MQTT agent to the target MQTT agent, and obtain monitoring results; and a triggering unit, used to trigger the connection switching process of the target smart device when the monitoring results indicate that the connection between the target smart device and the target MQTT agent is abnormal.

[0082] Optionally, the monitoring unit includes: a sending module, used to send heartbeat data packets to the target MQTT broker via the target smart device at predetermined intervals; and a third acquisition module, used to acquire the feedback result of the target MQTT broker to the heartbeat data packets after determining that the target smart device has sent heartbeat data packets to the target MQTT broker at each predetermined interval, so as to monitor the connection status. The feedback result indicates that if the MQTT broker does not respond to the heartbeat data packets within a predetermined time, the connection status is determined to be a connection failure; if the feedback result indicates that the MQTT broker responds to the heartbeat data packets within a predetermined time, the connection status is determined to be a connection success.

[0083] Optionally, the switching unit includes: a fourth acquisition module, used to acquire the latest data of the target smart device from other cache nodes through the target MQTT broker after determining that the target smart device has switched from the current MQTT broker to the target MQTT broker, wherein the other cache nodes are cache nodes deployed on other MQTT brokers besides the target MQTT broker, and the latest data includes the device information of the target smart device and the interaction information of the target smart device.

[0084] Optionally, the fourth acquisition module includes: a determination submodule, used to determine the identification information of the latest data; and an acquisition submodule, used to acquire the latest data of the target smart device from other cache nodes through the target MQTT broker when it is determined from the identification information that the latest data does not duplicate the current data of the target smart device that has been cached by the target MQTT broker.

[0085] Optionally, the device switching device based on the Lightweight Message Transmission Protocol further includes: a deployment unit for deploying cache nodes on each MQTT broker of the control platform; and a selection unit for selecting a primary cache node from multiple cache nodes so that when a smart device in the smart home system publishes a message, the message is distributed to other cache nodes besides the primary cache node through the primary cache node, wherein when a smart device publishes a message, the message is first sent to the primary cache node.

[0086] According to another aspect of the present invention, a processor is also provided, which is used to run a program, wherein the program executes any of the above-described device switching methods based on a lightweight message transmission protocol.

[0087] According to another aspect of the present invention, a computer program product is also provided, including computer instructions, which, when executed by a processor, perform any of the above-described device switching methods based on a lightweight message transmission protocol.

[0088] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored program, wherein the program executes the device switching method based on a lightweight messaging protocol as described above.

[0089] Optionally, in this embodiment, the computer-readable storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any communication device in a group of communication devices.

[0090] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: upon detecting a switching message of a Lightweight Message Transfer Protocol (MQTT) broker, determining the target smart device requiring MQTT broker switching based on the switching message; obtaining the load information of each MQTT broker in the control platform where the target smart device is located, wherein the load information is used to indicate the number of smart devices in the smart home system where the target smart device is currently managed by each MQTT broker; determining the target MQTT broker to which the target smart device is switching based on the load information; and switching the target smart device from the current MQTT broker to the target MQTT broker.

[0091] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: monitoring the device connection status of the target smart device and obtaining monitoring results; when the monitoring results indicate that there is a change in the device connection status, determining that a switching message of the MQTT broker has been detected, wherein the change includes at least one of the following: the location of the target smart device has changed, or there is network latency in the target smart device.

[0092] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: obtaining agent information of the MQTT agents currently connected to each smart device in the smart home system; determining the number of smart devices currently managed by each MQTT agent based on the agent information; and obtaining the load information of each MQTT agent based on the number of devices.

[0093] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: during the process of switching the target smart device from the current MQTT broker to the target MQTT broker, monitoring the connection status between the target smart device and the target MQTT broker and obtaining monitoring results; when the monitoring results indicate that the connection between the target smart device and the target MQTT broker is abnormal, triggering the connection switching process of the target smart device.

[0094] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: sending heartbeat data packets to the target MQTT broker via the target smart device at predetermined intervals; in each predetermined interval, after determining that the target smart device has sent heartbeat data packets to the target MQTT broker, obtaining the feedback result of the target MQTT broker to the heartbeat data packets to monitor the connection status, wherein the feedback result indicates that the MQTT broker has not responded to the heartbeat data packets within a predetermined time period, and the connection status is determined to be a connection failure; when the feedback result indicates that the MQTT broker has responded to the heartbeat data packets within a predetermined time period, the connection status is determined to be a connection success.

[0095] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: obtaining the latest data of the target smart device from other cache nodes through the target MQTT broker, wherein the other cache nodes are cache nodes deployed on other MQTT brokers besides the target MQTT broker, and the latest data includes device information and interaction information of the target smart device.

[0096] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: determining identification information of the latest data; and when it is determined from the identification information that the latest data does not duplicate the current data of the target smart device that has been cached by the target MQTT broker, obtaining the latest data of the target smart device from other cache nodes through the target MQTT broker.

[0097] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: deploying cache nodes on each MQTT broker of the control platform; selecting a master cache node from multiple cache nodes so that when a smart device in the smart home system publishes a message, the message is distributed to other cache nodes besides the master cache node through the master cache node, wherein when a smart device publishes a message, the message is first sent to the master cache node.

[0098] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0099] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0100] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.

[0101] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0102] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0103] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0104] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A device handover method based on a lightweight message transmission protocol, characterized in that, include: When a switch message for the Lightweight Message Transfer Protocol (MQTT) broker is detected, the target smart device that needs to switch the MQTT broker is determined based on the switch message. Obtain the load information of each MQTT agent in the control platform where the target smart device is located, wherein the load information is used to indicate the number of smart devices in the smart home system where the target smart device is currently managed by each MQTT agent; The target MQTT broker switched by the target smart device is determined based on the load information; Switch the target smart device from the current MQTT broker to the target MQTT broker; The detection of a switching message for the Lightweight Message Transfer Protocol (MQTT) broker includes: monitoring the device connection status of the target smart device and obtaining a monitoring result; when the monitoring result indicates that the device connection status has changed, determining that a switching message for the MQTT broker has been detected, wherein the change includes at least one of the following: the location of the target smart device has changed, or the target smart device has network latency; The determination of switching the target smart device from the current MQTT broker to the target MQTT broker includes: obtaining the latest data of the target smart device from other cache nodes through the target MQTT broker, wherein the other cache nodes are cache nodes deployed on other MQTT brokers besides the target MQTT broker, and the latest data includes the device information of the target smart device and the interaction information of the target smart device; The device switching method further includes: deploying cache nodes on each of the MQTT brokers of the control platform; selecting a primary cache node from the plurality of cache nodes, so that when a smart device in the smart home system publishes a message, the message is distributed to other cache nodes besides the primary cache node through the primary cache node, wherein when the smart device publishes the message, the message is first sent to the primary cache node.

2. The device handover method based on a lightweight message transmission protocol according to claim 1, characterized in that, Also includes: During the process of switching the target smart device from the current MQTT broker to the target MQTT broker, the connection status between the target smart device and the target MQTT broker is monitored, and the monitoring results are obtained. When the monitoring results indicate that the connection between the target smart device and the target MQTT broker is abnormal, the connection switching process of the target smart device is triggered.

3. The device handover method based on a lightweight message transmission protocol according to claim 2, characterized in that, Monitoring the connection status between the target smart device and the target MQTT broker includes: The target smart device sends heartbeat data packets to the target MQTT agent at a predetermined period. In each predetermined period, after determining that the target smart device sends the heartbeat data packet to the target MQTT agent, the feedback result of the target MQTT agent to the heartbeat data packet is obtained to monitor the connection status. The feedback result indicates that if the MQTT agent does not respond to the heartbeat data packet within the predetermined time, the connection status is determined to be a connection failure; if the feedback result indicates that the MQTT agent responds to the heartbeat data packet within the predetermined time, the connection status is determined to be a connection success.

4. The device handover method based on a lightweight message transmission protocol according to claim 1, characterized in that, Obtain the latest data of the target smart device from other cache nodes through the target MQTT broker, including: Determine the identification information of the latest data; When it is determined, based on the identification information, that the latest data does not duplicate the current data of the target smart device already cached by the target MQTT broker, the latest data of the target smart device is obtained from the other cache nodes through the target MQTT broker.

5. A device switching device based on a lightweight message transmission protocol, characterized in that, include: The first determining unit is used to determine the target smart device that needs to switch the MQTT agent when a switching message of the Lightweight Message Transfer Protocol (MQTT) agent is detected. The acquisition unit is used to acquire the load information of each MQTT agent in the control platform where the target smart device is located, wherein the load information is used to indicate the number of smart devices in the smart home system where the target smart device is currently managed by each MQTT agent; The second determining unit is used to determine the target MQTT agent switched by the target smart device based on the load information. A switching unit is used to switch the target smart device from the current MQTT broker to the target MQTT broker; The first determining unit includes: a monitoring module, used to monitor the device connection status of the target smart device and obtain a monitoring result; and a first determining module, used to determine that a switching message of the MQTT broker has been detected when the monitoring result indicates that the device connection status has changed, wherein the change includes at least one of the following: the location of the target smart device has changed, or the target smart device has network latency. The switching unit includes a fourth acquisition module, configured to, after determining that the target smart device has switched from the current MQTT broker to the target MQTT broker, acquire the latest data of the target smart device from other cache nodes through the target MQTT broker, wherein the other cache nodes are cache nodes deployed on other MQTT brokers besides the target MQTT broker, and the latest data includes the device information of the target smart device and the interaction information of the target smart device; The device switching device based on the Lightweight Message Transmission Protocol further includes: a deployment unit for deploying cache nodes on each of the MQTT brokers of the control platform; and a selection unit for selecting a primary cache node from the plurality of cache nodes, so that when a smart device in the smart home system publishes a message, the message is distributed to other cache nodes besides the primary cache node through the primary cache node, wherein when the smart device publishes the message, the message is first sent to the primary cache node.

6. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein the program executes the device switching method based on a lightweight messaging protocol as described in any one of claims 1 to 4.

7. A computer program product comprising computer instructions, characterized in that, When the computer instructions are executed by the processor, the device switching method based on the lightweight message transmission protocol as described in any one of claims 1 to 4 is performed.

Citation Information

Patent Citations

  • Geological disaster monitoring method and system, electronic equipment and storage medium

    CN113037803A

  • Method and device for establishing MQTT proxy cluster based on multi-instance micro-service and medium

    CN118827757A