Equipment switching method and device based on lightweight message transmission protocol

Select the target MQTT proxy by monitoring the switching message of the MQTT proxy and obtaining the load information, solve the problem that the message synchronization and consistency are difficult to guarantee during device switching, and realize the timely synchronization and consistency of the data when the device is connected.

CN119363548AActive Publication Date: 2025-01-24GREE ELECTRIC APPLIANCE INC OF ZHUHAI +1
View PDF 4 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

MQTT brokers are usually deployed in a single point, relying on a single broker for message transmission and processing. When devices switch to different brokers, the synchronization and consistency of messages are difficult to guarantee.

Method used

By monitoring the switching message of the MQTT proxy, determine the target MQTT proxy that the target smart device needs to switch, obtain the load information of each MQTT agent, select the target MQTT proxy according to the load information, and switch the target smart device to the proxy.

Benefits of technology

It achieves timely synchronization of messages and data when the device switches connections, avoids data loss, and improves message synchronization and consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119363548A_ABST
    Figure CN119363548A_ABST
Patent Text Reader

Abstract

The invention discloses an equipment switching method and device based on a lightweight message transmission protocol. The method comprises the following steps: when a switching message of a lightweight message transport protocol MQTT proxy is monitored, determining a target intelligent device which needs to perform MQTT proxy switching according to the switching message; load information of each MQTT agent in a control platform where the target intelligent device is located is obtained, and the load information is used for representing the number of intelligent devices in an intelligent home system where the target intelligent device currently managed by each MQTT agent is located; determining a target MQTT proxy switched by the target intelligent device according to the load information; and switching the target intelligent equipment from the current MQTT proxy to the target MQTT proxy. According to the method and the device, the technical problem that the synchronization and the consistency of messages are difficult to guarantee when the equipment is switched to different agents because the MQTT agent is generally deployed at a single point and depends on a single agent to carry out message transmission and processing in the related technology is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data transmission, and in particular to a device switching method and apparatus based on a lightweight message transmission protocol. Background Art

[0002] MQTT (Message Queuing Telemetry Transport) is a lightweight message transmission protocol. In actual applications, devices may need to switch connections to different MQTT brokers due to network fluctuations, mobility, etc. However, during the switching process, device data synchronization and message consistency become an urgent problem to be solved. If the device loses messages or fails to synchronize data in time during the switching process, it will lead to system instability and data inconsistency.

[0003] In the prior art, MQTT agents are usually deployed in a single point, relying on a single agent for message transmission and processing. When devices switch to different agents, the synchronization and consistency of messages are difficult to guarantee. In addition, the existing distributed cache technology lacks targeted optimization when processing MQTT messages, and cannot efficiently achieve data synchronization when devices switch.

[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0005] The embodiment of the present invention provides a device switching method and apparatus based on a lightweight message transmission protocol, so as to at least solve the technical problem in the related technology that the MQTT agent is usually deployed at a single point and relies on a single agent for message transmission and processing. When the device switches to a different agent, the synchronization and consistency of the message are difficult to ensure.

[0006] According to one aspect of an embodiment of the present invention, a device switching method based on a lightweight message transfer protocol is provided, comprising: when a switching message of a lightweight message transfer protocol MQTT agent is monitored, determining a target smart device that needs to perform MQTT agent switching according to the switching message; obtaining load information of each of the MQTT agents in a control platform where the target smart device is located, wherein the load information is used to indicate the number of smart devices in a smart home system where the target smart device is currently managed by each of the MQTT agents; determining a target MQTT agent to which the target smart device is switched according to the load information; and switching the target smart device from the current MQTT agent to the target MQTT agent.

[0007] Optionally, monitoring a switching message of a lightweight message transfer protocol MQTT agent includes: monitoring the device connection status of the target smart device to obtain a monitoring result; when the monitoring result indicates that there is a change in the device connection status, determining that the switching message of the MQTT agent is monitored, wherein the change includes at least one of the following: a change in the location of the target smart device and a network delay in the target smart device.

[0008] Optionally, the load information of each MQTT agent in the control platform where the target smart device is located is obtained, including: obtaining the agent information of the MQTT agent to which each smart device in the smart home system is currently connected; 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 transfer protocol also includes: in the process of switching the target smart device from the current MQTT agent to the target MQTT agent, monitoring the connection status between the target smart device and the target MQTT agent to obtain a monitoring result; when the monitoring result indicates that an abnormality occurs in the connection between the target smart device and the target MQTT agent, triggering the connection switching process of the target smart device.

[0010] Optionally, the connection status between the target smart device and the target MQTT agent is monitored, including: sending a heartbeat data packet to the target MQTT agent according to a predetermined period by the target smart device; in each of the predetermined periods, after determining that the target smart device sends the heartbeat data packet to the target MQTT agent, obtaining the feedback result of the target MQTT agent on the heartbeat data packet to monitor the connection status, wherein when the feedback result indicates that the MQTT agent has not provided feedback on the heartbeat data packet within a predetermined period, the connection status is determined to be a connection failure; when the feedback result indicates that the MQTT agent has provided feedback on the heartbeat data packet within the predetermined period, the connection status is determined to be a connection success.

[0011] Optionally, determining that the target smart device switches from the current MQTT agent to the target MQTT agent includes: obtaining the latest data of the target smart device from other cache nodes through the target MQTT agent, wherein the other cache nodes are cache nodes deployed on other MQTT agents other than the target MQTT agent, and the latest data includes device information of the target smart device and 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 agent, including: determining identification information of the latest data; when it is determined according to the identification information that there is no data duplication between the latest data and the current data of the target smart device already cached by the target MQTT agent, obtaining the latest data of the target smart device from the other cache nodes through the target MQTT agent.

[0013] Optionally, the device switching method based on the lightweight message transmission protocol also includes: deploying cache nodes on each of the MQTT agents of the control platform; selecting a primary cache node from the 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 except 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 an embodiment of the present invention, a device switching device based on a lightweight message transmission protocol is also provided, including: a first determination unit, used to determine the target smart device that needs to perform MQTT agent switching according to the switching message when a switching message of a lightweight message transmission protocol MQTT agent is monitored; an acquisition unit, used to obtain the load information of each of the MQTT agents 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 of the MQTT agents; a second determination unit, used to determine the target MQTT agent to which the target smart device is switched according to the load information; a switching unit, used to switch the target smart device from the current MQTT agent to the target MQTT agent.

[0015] Optionally, the first determination unit includes: a monitoring module, used to monitor the device connection status of the target smart device to obtain a monitoring result; a first determination module, used to determine that a switching message of the MQTT agent is monitored when the monitoring result indicates that there is a change in the device connection status, wherein the change includes at least one of the following: a change in the location of the target smart device, or a network delay in the target smart device.

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

[0017] Optionally, the device switching device based on the lightweight message transfer protocol also includes: a monitoring unit, used to monitor the connection status between the target smart device and the target MQTT agent to obtain a monitoring result during the process of switching the target smart device from the current MQTT agent to the target MQTT agent; and a triggering unit, used to trigger the connection switching process of the target smart device when the monitoring result indicates that an abnormality occurs in the connection between the target smart device and the target MQTT agent.

[0018] Optionally, the monitoring unit includes: a sending module, used to send heartbeat data packets to the target MQTT agent through the target smart device according to a predetermined period; a third acquisition module, used to obtain the feedback result of the target MQTT agent on the heartbeat data packet in each predetermined period after determining that the target smart device sends the heartbeat data packet to the target MQTT agent, so as to monitor the connection status, wherein when the feedback result indicates that the MQTT agent has not provided feedback on the heartbeat data packet within a predetermined time period, the connection status is determined to be a connection failure; when the feedback result indicates that the MQTT agent has provided feedback on 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, which is used to obtain the latest data of the target smart device from other cache nodes through the target MQTT agent after determining that the target smart device is switched from the current MQTT agent to the target MQTT agent, wherein the other cache nodes are cache nodes deployed on other MQTT agents other than the target MQTT agent, 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 determination submodule for determining identification information of the latest data; an acquisition submodule for obtaining the latest data of the target smart device from the other cache nodes through the target MQTT agent when it is determined according to the identification information that there is no data duplication between the latest data and 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 also includes: a deployment unit, used to deploy cache nodes on each of the MQTT agents of the control platform; a selection unit, used to select a primary cache node from the multiple cache nodes, so that when the smart device in the smart home system publishes a message, the message is distributed to other cache nodes except 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 an embodiment of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes a stored program, wherein the program executes any one of the above-mentioned device switching methods based on the lightweight message transmission protocol.

[0023] According to another aspect of an embodiment of the present invention, a processor is provided, the processor being used to run a program, wherein the program, when running, executes any one of the above-mentioned device switching methods based on the lightweight message transmission protocol.

[0024] According to another aspect of an embodiment of the present invention, a computer program product is provided, including computer instructions, which, when executed by a processor, execute any one of the above-mentioned device switching methods based on the lightweight message transmission protocol.

[0025] In an embodiment of the present invention, when a switching message of a lightweight message transmission protocol MQTT agent is monitored, the target smart device that needs to switch the MQTT agent is determined according to 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 currently managed by each MQTT agent is located; the target MQTT agent to which the target smart device is switched is determined according to the load information; and the target smart device is switched from the current MQTT agent to the target MQTT agent. Through the technical solution provided by the present invention, it is achieved to ensure that the messages and data of the device can be synchronized in time when switching connections through distributed caching and synchronization technology to avoid data loss, and the technical effect of improving the synchronization and consistency of messages is achieved, thereby solving the technical problem that the MQTT agent in the related technology is usually deployed at a single point, relying on a single agent for message transmission and processing, and when the device switches to a different agent, the synchronization and consistency of the message is difficult to ensure. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

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

[0028] Figure 2 is a flow chart of a device switching method based on a lightweight message transmission protocol according to an embodiment of the present invention;

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

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

[0031] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings 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 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 and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0033] As introduced in the background technology, in the related technology, the MQTT agent is usually deployed at a single point and relies on a single agent for message transmission and processing. When the device switches to a different agent, the synchronization and consistency of the message are difficult to guarantee. In view of the above defects, in the embodiments of the present invention, 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 are provided.

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

[0035] The method embodiments provided in the embodiments of the present invention can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 FIG. 1 is a hardware structure block diagram of a mobile terminal of a device switching method based on a lightweight message transmission protocol according to an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.

[0036] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the device switching method based on the lightweight message transmission protocol in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, the above method is implemented. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the above-mentioned network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof. The transmission device 106 is used to receive or send data via a network. The above-mentioned specific examples of the network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as 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 message transmission protocol is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0038] Figure 2 is a flow chart of a device switching method based on a lightweight message transmission protocol according to an embodiment of the present invention. Figure 2 As shown, the device switching method based on the lightweight message transmission protocol includes the following steps:

[0039] Step S202: when a switch message of a lightweight message transfer protocol MQTT agent is detected, a target smart device that needs to perform MQTT agent switch is determined according to the switch message.

[0040] In this embodiment, the switching message of the MQTT agent of the smart device is monitored in real time, and then the target smart device for MQTT agent switching is determined according to the switching message.

[0041] Among them, the above-mentioned smart devices and target smart devices are all smart devices in the smart home system, for example, refrigerators, air conditioners, washing machines, televisions, etc. in the user's home.

[0042] Step S204, obtaining 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 currently managed by each MQTT agent is located.

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

[0044] Step S206: determining the target MQTT proxy to which the target smart device switches according to the load information.

[0045] In this embodiment, the target MQTT broker to which the target smart device switches may be selected according to the load information determined above.

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

[0047] From the above, it can be seen that in an embodiment of the present invention, when a switching message of a lightweight message transfer protocol MQTT agent is monitored, the target smart device that needs to switch the MQTT agent is determined according to 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 currently managed by each MQTT agent is located; the target MQTT agent to which the target smart device switches is determined according to the load information; the target smart device is switched from the current MQTT agent to the target MQTT agent, thereby ensuring that the messages and data of the device can be synchronized in time when switching connections through distributed caching and synchronization technology to avoid data loss, thereby achieving the technical effect of improving the synchronization and consistency of messages.

[0048] Therefore, the above-mentioned technical solution provided by the embodiment of the present invention solves the technical problem in the related technology that the MQTT agent is usually deployed at a single point, relies on a single agent for message transmission and processing, and when the device switches to a different agent, the synchronization and consistency of the message are difficult to ensure.

[0049] According to the above embodiment of the present invention, monitoring the switching message of the lightweight message transfer protocol MQTT agent includes: monitoring the device connection status of the target smart device to obtain a monitoring result; when the monitoring result indicates that there is a change in the device connection status, determining that the switching message of the MQTT agent is monitored, wherein the change includes at least one of the following: the location of the target smart device changes, and the target smart device has a network delay.

[0050] In this embodiment, when a device (ie, a smart device) needs to switch connection to a new MQTT broker due to network fluctuation or mobility, a switching message of the MQTT broker is monitored.

[0051] According to the above-mentioned embodiment 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 agent to which each smart device in the smart home system is currently connected; 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 between multiple MQTT brokers to avoid overloading of a single MQTT broker. For example, the connection to the most suitable MQTT broker can be dynamically allocated based on factors such as the geographical location of the smart device and network latency.

[0053] According to the above-mentioned embodiment of the present invention, the device switching method based on the lightweight message transmission protocol also includes: in the process of switching the target smart device from the current MQTT agent to the target MQTT agent, the connection status between the target smart device and the target MQTT agent is monitored to obtain a monitoring result; when the monitoring result indicates that the connection between the target smart device and the target MQTT agent is abnormal, the connection switching process of the target smart device is triggered.

[0054] In this embodiment, when the device needs to switch to a new MQTT broker due to network fluctuations or mobility, the new broker obtains the latest messages and data of the device through the data synchronization module. The device connection management module is responsible for coordinating the connection switching of the device to ensure a smooth transition during the switching 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 embodiment of the present invention, the connection status between the target smart device and the target MQTT agent is monitored, including: sending a heartbeat data packet to the target MQTT agent according to a predetermined period by the target smart device; in each predetermined period, after determining that the target smart device sends a heartbeat data packet to the target MQTT agent, obtaining the feedback result of the target MQTT agent on the heartbeat data packet to monitor the connection status, wherein when the feedback result indicates that the MQTT agent does not provide feedback on the heartbeat data packet within a predetermined time period, the connection status is determined to be a connection failure; when the feedback result indicates that the MQTT agent provides feedback on the heartbeat data packet within the predetermined time period, the connection status is determined to be a connection success.

[0057] In this embodiment, the online status of the device can be regularly detected through a heartbeat mechanism to ensure the stability of the connection.

[0058] According to the above embodiment of the present invention, determining that the target smart device switches from the current MQTT agent to the target MQTT agent includes: obtaining the latest data of the target smart device from other cache nodes through the target MQTT agent, wherein the other cache nodes are cache nodes deployed on other MQTT agents except the target MQTT agent, and the latest data includes device information of the target smart device and interaction information of the target smart device.

[0059] In this embodiment, cache nodes are deployed on each MQTT agent, and data synchronization is performed between the cache nodes through distributed cache technology.

[0060] Obtain the latest data of the target smart device from other cache nodes through the target MQTT proxy, including: determining identification information of the latest data; when it is determined based on the identification information that there is no data duplication between the latest data and the current data of the target smart device already cached by the target MQTT proxy, obtaining the latest data of the target smart device from other cache nodes through the target MQTT proxy.

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

[0062] In this embodiment, when the device switches to connect to a new MQTT broker, the new broker synchronizes the latest messages and data of the device from other cache nodes. Use timestamps or version numbers to ensure the latest data and avoid data conflicts. Data transmission optimization: Use incremental synchronization technology to only transmit changed data and reduce network bandwidth consumption.

[0063] According to the above embodiment of the present invention, the device switching method based on the lightweight message transmission protocol also includes: deploying cache nodes on each MQTT agent of the control platform; selecting a main 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 except the main cache node through the main cache node, wherein when the smart device publishes a message, the message is first sent to the main cache node.

[0064] In this embodiment, consistency algorithms such as Paxos and Raft can be used to ensure the order and consistency of messages. These algorithms select a master node through an election mechanism to coordinate the processing and synchronization of messages. In addition, in an embodiment of the present invention, the message processing process 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 that the order of messages on all nodes is consistent through a consistency algorithm. Once the message is confirmed on most nodes, the master node submits the message and notifies the device.

[0065] Figure 3 is a flowchart of an optional device switching method based on a lightweight message transmission protocol according to an embodiment of the present invention, such as Figure 3As shown, first, cache nodes can be deployed through the distributed cache module: cache nodes are deployed on each MQTT agent, and data is synchronized between cache nodes through distributed cache technology. Use a distributed hash table (DHT) to distribute and store device messages and data in multiple cache nodes. Each cache node is responsible for a specific range of data, and the storage location of the data is calculated through a hash function. When the device switches connection, the latest messages and data are obtained through a synchronization mechanism. Synchronization mechanism: When the device switches to a new MQTT agent, the new agent synchronizes the latest messages and data of the device from other cache nodes. Use timestamps or version numbers to ensure the latest data and avoid data conflicts. Data transmission optimization: Use incremental synchronization technology to only transmit changed data to reduce network bandwidth consumption. Use compression algorithms to further optimize data transmission efficiency.

[0066] In addition, if Figure 3 As shown in the figure, consistency algorithms such as Paxos and Raft are used to ensure the order and consistency of messages. These algorithms select a master node through an election mechanism to coordinate the processing and synchronization of messages. Message processing process: 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 the consistency of the message order on all nodes through a consistency algorithm. Once the message is confirmed on most nodes, the master node submits the message and notifies the device. Fault handling: When the master node fails, a new master node is selected through a consistency algorithm to continue to be responsible for message processing and synchronization. A logging mechanism is used to ensure that uncommitted messages can be resynchronized after the node is restored. Here, logging can be used to continuously monitor device connections; to continuously monitor device network fluctuations or device connection stability, and automatically trigger the connection switching process when the device is unstable; conversely, the heartbeat mechanism is used to regularly detect the online status of the device to ensure the stability of the connection; load balancing is also performed between MQTT agents to avoid overloading a single agent.

[0067] Therefore, through the above-mentioned technical solution provided by the embodiment of the present invention, a distributed cache is introduced between multiple MQTT agents to store and synchronize the messages and data of the devices, ensuring that the messages and data can be synchronized in time when the devices switch connections, avoiding data loss and inconsistency; an efficient data synchronization algorithm is designed to ensure that the devices can obtain the latest messages and data in time when switching connections; through a consistency algorithm, the consistency and sequence of messages are ensured when the devices switch between different MQTT agents, which can effectively solve the data synchronization and message consistency problems when the devices switch connections, improve the stability and reliability of the system, and is suitable for various Internet of Things application scenarios.

[0068] In addition, in the embodiment of the present invention, the message processing capability of the MQTT agent is improved through distributed caching technology, and the stability and reliability of the system are enhanced; moreover, through distributed caching and synchronization mechanisms, the network delay when the device switches the connection is reduced, the response speed of the system is improved, and the scalability is relatively strong, which is suitable for various IoT application scenarios.

[0069] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

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

[0071] According to an embodiment of the present invention, there is also provided a device switching apparatus based on a lightweight message transmission protocol for implementing the above-mentioned device switching method based on a lightweight message transmission protocol. Figure 4 is a schematic diagram of a device switching apparatus based on a lightweight message transmission 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 is described below.

[0072] The first determining unit 401 is configured to determine a target smart device that needs to perform MQTT proxy switching according to the switching message when a switching message of a lightweight message transfer protocol MQTT proxy 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, wherein the load information is used to indicate the number of smart devices in the smart home system where the target smart device currently managed by each MQTT agent is located.

[0074] The second determining unit 405 is configured to determine a target MQTT proxy to which the target smart device switches according to the load information.

[0075] The switching unit 407 is used to switch the target smart device from the current MQTT agent to the target MQTT agent.

[0076] It should be noted here that the above-mentioned first determination unit 401, acquisition unit 403, second determination unit 405 and switching unit 407 correspond to steps S202 to S208 in the above-mentioned embodiments, and the four units are the same as the instances and application scenarios implemented by the corresponding steps, but are not limited to the contents disclosed in the above-mentioned embodiments.

[0077] As can be seen from the above, in the scheme recorded in the above-mentioned embodiment of the present invention, the first determination unit can be used to determine the target smart device that needs to switch the MQTT agent according to the switching message when monitoring the switching message of the lightweight message transmission protocol MQTT agent; the acquisition unit is used to 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 currently managed by each MQTT agent is located; the second determination unit is used to determine the target MQTT agent to which the target smart device switches according to the load information; the switching unit is used to switch the target smart device from the current MQTT agent to the target MQTT agent, thereby achieving distributed caching and synchronization technology to ensure that the messages and data of the device can be synchronized in time when switching connections, to avoid data loss, and to achieve the technical effect of improving the synchronization and consistency of messages.

[0078] Therefore, the above-mentioned technical solution provided by the embodiment of the present invention solves the technical problem in the related technology that the MQTT agent is usually deployed at a single point, relies on a single agent for message transmission and processing, and when the device switches to a different agent, the synchronization and consistency of the message are difficult to ensure.

[0079] Optionally, the first determination unit includes: a monitoring module, used to monitor the device connection status of the target smart device to obtain a monitoring result; a first determination module, used to determine that a switching message of the MQTT agent is monitored when the monitoring result indicates that there is a change in the device connection status, wherein the change includes at least one of the following: a change in the location of the target smart device and a network delay in the target smart device.

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

[0081] Optionally, the device switching device based on the lightweight message transmission protocol also includes: a monitoring unit, which is used to monitor the connection status between the target smart device and the target MQTT agent to obtain a monitoring result during the process of switching the target smart device from the current MQTT agent to the target MQTT agent; and a triggering unit, which is used to trigger the connection switching process of the target smart device when the monitoring result indicates that the connection between the target smart device and the target MQTT agent is abnormal.

[0082] Optionally, the monitoring unit includes: a sending module, which is used to send heartbeat data packets to the target MQTT agent through the target smart device according to a predetermined period; a third acquisition module, which is used to obtain the feedback result of the target MQTT agent on the heartbeat data packet in each predetermined period after determining that the target smart device sends the heartbeat data packet to the target MQTT agent, so as to monitor the connection status, wherein when the feedback result indicates that the MQTT agent does not provide feedback on the heartbeat data packet within a predetermined time period, the connection status is determined to be a connection failure; when the feedback result indicates that the MQTT agent provides feedback on the heartbeat data packet within the predetermined time period, the connection status is determined to be a connection success.

[0083] Optionally, the switching unit includes: a fourth acquisition module, which is used to obtain the latest data of the target smart device from other cache nodes through the target MQTT agent after determining that the target smart device is switched from the current MQTT agent to the target MQTT agent, wherein the other cache nodes are cache nodes deployed on other MQTT agents except the target MQTT agent, and the latest data includes device information of the target smart device and interaction information of the target smart device.

[0084] Optionally, the fourth acquisition module includes: a determination sub-module for determining identification information of the latest data; an acquisition sub-module for obtaining the latest data of the target smart device from other cache nodes through the target MQTT agent when it is determined based on the identification information that there is no data duplication between the latest data and the current data of the target smart device already cached by the target MQTT agent.

[0085] Optionally, the device switching device based on the lightweight message transmission protocol also includes: a deployment unit, used to deploy cache nodes on each MQTT agent of the control platform; a selection unit, used to select 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 except the primary cache node through the primary cache node, wherein when the smart device publishes a message, the message is first sent to the primary cache node.

[0086] According to another aspect of an embodiment of the present invention, a processor is provided, and the processor is used to run a program, wherein when the program is run, any one of the above-mentioned device switching methods based on the lightweight message transmission protocol is executed.

[0087] According to another aspect of an embodiment of the present invention, a computer program product is provided, including computer instructions. When the computer instructions are executed by a processor, any one of the above-mentioned device switching methods based on the lightweight message transmission protocol is executed.

[0088] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium including a stored program, wherein the program executes any one of the above-mentioned device switching methods based on the lightweight message transmission protocol.

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

[0090] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for executing the following steps: when a switching message of a lightweight message transfer protocol MQTT agent is monitored, determining a target smart device that needs to switch the MQTT agent according to the switching message; obtaining 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 currently managed by each MQTT agent is located; determining a target MQTT agent to which the target smart device switches according to the load information; and switching the target smart device from the current MQTT agent to the target MQTT agent.

[0091] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for executing the following steps: monitoring the device connection status of the target smart device to obtain a monitoring result; when the monitoring result indicates that there is a change in the device connection status, determining that a switching message of the MQTT agent is monitored, wherein the change includes at least one of the following: a change in the location of the target smart device, or a network delay in the target smart device.

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

[0093] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for executing the following steps: in the process of switching the target smart device from the current MQTT agent to the target MQTT agent, monitoring the connection status between the target smart device and the target MQTT agent to obtain a monitoring result; when the monitoring result indicates that an abnormality occurs in the connection between the target smart device and the target MQTT agent, 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 executing the following steps: sending a heartbeat data packet to the target MQTT agent according to a predetermined period through the target smart device; in each predetermined period, after determining that the target smart device sends a heartbeat data packet to the target MQTT agent, obtaining the feedback result of the target MQTT agent on the heartbeat data packet to monitor the connection status, wherein when the feedback result indicates that the MQTT agent has not provided feedback on the heartbeat data packet within a predetermined time period, determining that the connection status is a connection failure; when the feedback result indicates that the MQTT agent has provided feedback on the heartbeat data packet within a predetermined time period, determining that the connection status is 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 agent, wherein the other cache nodes are cache nodes deployed on other MQTT agents other than the target MQTT agent, and the latest data includes device information of the target smart device 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; when it is determined based on the identification information that there is no data duplication between the latest data and the current data of the target smart device already cached by the target MQTT agent, obtaining the latest data of the target smart device from other cache nodes through the target MQTT agent.

[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 agent of the control platform; 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 except the primary cache node through the primary cache node, wherein when the smart device publishes a message, the message is first sent to the primary cache node.

[0098] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0099] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made 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. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

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

[0102] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0103] If the integrated unit is implemented in the form of 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, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.

[0104] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A device switching method based on a lightweight message transmission protocol, characterized in that: include: When a switching message of a lightweight message transmission protocol MQTT agent is detected, a target smart device that needs to perform MQTT agent switching is determined according to the switching message; Obtaining load information of each of the MQTT agents 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 and currently managed by each of the MQTT agents; Determine the target MQTT proxy to which the target smart device switches according to the load information; Switch the target smart device from the current MQTT agent to the target MQTT agent.

2. The device switching method based on the lightweight message transmission protocol according to claim 1 is characterized in that: The switching messages of the lightweight message transmission protocol MQTT agent are monitored, including: Monitor the device connection status of the target smart device to obtain a monitoring result; When the monitoring result indicates that there is a change in the device connection state, it is determined that a switching message of the MQTT agent is monitored, wherein the change includes at least one of the following: a change in the location of the target smart device and a network delay of the target smart device.

3. The device switching method based on the lightweight message transmission protocol according to claim 1 is characterized in that: Also includes: In the process of switching the target smart device from the current MQTT agent to the target MQTT agent, monitoring the connection status between the target smart device and the target MQTT agent to obtain a monitoring result; When the monitoring result indicates that an abnormality occurs in the connection between the target smart device and the target MQTT agent, a connection switching process of the target smart device is triggered.

4. The device switching method based on the lightweight message transmission protocol according to claim 3 is characterized in that: Monitoring the connection status between the target smart device and the target MQTT agent includes: Sending a heartbeat data packet to the target MQTT agent according to a predetermined period by the target smart device; In each of the predetermined cycles, 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 on the heartbeat data packet is obtained to monitor the connection status, wherein when the feedback result indicates that the MQTT agent has not provided feedback on the heartbeat data packet within the predetermined time period, the connection status is determined to be a connection failure; when the feedback result indicates that the MQTT agent provides feedback on the heartbeat data packet within the predetermined time period, the connection status is determined to be a connection success.

5. The device switching method based on the lightweight message transmission protocol according to claim 1 is characterized in that: Determining that the target smart device switches from the current MQTT agent to the target MQTT agent includes: The latest data of the target smart device is obtained from other cache nodes through the target MQTT agent, wherein the other cache nodes are cache nodes deployed on other MQTT agents except the target MQTT agent, and the latest data includes device information of the target smart device and interaction information of the target smart device.

6. The device switching method based on the lightweight message transmission protocol according to claim 5 is characterized in that: Obtaining the latest data of the target smart device from other cache nodes through the target MQTT agent includes: Determining identification information of the latest data; When it is determined according to the identification information that there is no data duplication between the latest data and the current data of the target smart device already cached by the target MQTT proxy, the latest data of the target smart device is obtained from the other cache nodes through the target MQTT proxy.

7. The device switching method based on the lightweight message transmission protocol according to claim 6 is characterized in that: Also includes: Deploy a cache node on each of the MQTT agents of the control platform; A primary cache node is selected 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 except 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.

8. A device switching device based on a lightweight message transmission protocol, characterized in that: include: A first determining unit is used to determine a target smart device that needs to perform MQTT proxy switching according to the switching message when a switching message of a lightweight message transmission protocol MQTT proxy is detected; An acquisition unit, used to acquire load information of each of the MQTT agents 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 and currently managed by each of the MQTT agents; A second determining unit, configured to determine a target MQTT proxy to which the target smart device switches according to the load information; The switching unit is used to switch the target smart device from the current MQTT agent to the target MQTT agent.

9. 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 the lightweight message transmission protocol as described in any one of claims 1 to 7.

10. 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 described in any one of claims 1 to 7 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

  • Distributed MQTT Broker Architecture based on RPL

    KR102074916B1

  • System and method for switching between publish / subscribe services

    US20200287974A1