Wireless network dynamic master control election method based on two-layer multicast and MQTT cooperation
By adopting a dynamic master election method for wireless networks that combines Layer 2 multicast and MQTT, we have achieved rapid networking and stable operation transition in a decentralized environment. This solves the problem of rapid election and reliable state coordination in existing technologies, and provides seamless connection and self-healing capabilities, making it suitable for resource-constrained embedded systems.
Patent Information
- Application Number
- CN202511674264.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-14
- Publication Date
- 2026-01-13
AI Technical Summary
Existing wireless network master election and state synchronization schemes in the absence of a central server are difficult to balance rapid election and reliable state coordination, making it difficult to achieve a smooth transition from temporary networking to stable operation in dynamically changing environments. This is especially true in resource-constrained embedded systems where deployment is complex and resource overhead is high.
A dynamic master control election method for wireless networks based on Layer 2 multicast and MQTT collaboration is adopted. By constructing an initial peer node architecture, a master control election module and an MQTT client module are built in. The master control election is carried out using the signal strength information of the Layer 2 multicast transmission link, and the network status synchronization and control signaling transmission are realized through the MQTT Broker. It supports the dynamic migration of master control nodes and the carrying of service messages on the data plane, ensuring the stability and self-healing capability of the network.
It achieves rapid network convergence in a decentralized environment, reduces the risk of channel congestion, ensures that the master node has optimal network connection conditions, avoids message congestion and frequent switching through the master migration algorithm, provides a smooth transition from temporary networking to stable operation and continuous self-healing, and solves the problems of rapid election and reliable state coordination in existing technologies.
Smart Images

Figure CN121334808A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of distributed systems and wireless communication, in particular to a wireless network dynamic master election method based on two-layer multicast and MQTT cooperation. BACKGROUND
[0002] With the rapid development of Internet of Things (IoT), edge computing and mobile communication technology, the decentralized and self-organizing wireless network MESH architecture is increasingly popular in scenarios such as unmanned aerial vehicle clusters, intelligent sensor networks and industrial edge systems, which lack fixed infrastructure. In these environments, network nodes need to autonomously complete networking, coordination and task execution without a central server, posing severe challenges to the autonomy, robustness and scalability of the system. How to achieve fast master election, reliable state synchronization and efficient fault recovery has become a key technical problem in building a resilient and highly available distributed system. In the dynamic network environment of wireless MESH, the election and maintenance mechanism of the master node directly affects the availability, response speed and self-healing ability of the system.
[0003] However, existing master management schemes still face significant limitations in practical applications. Existing heartbeat mechanisms based on periodic broadcast or multicast can achieve fast node discovery and master election, but due to the lack of a structured state synchronization mechanism, they are prone to cause inconsistent node views and can cause channel congestion in large-scale deployments, making it difficult to support reliable state management. Solutions that rely on centralized coordination services such as ZooKeeper and etcd can guarantee strong consistency, but they require stable infrastructure to be pre-set, which is complex to deploy and resource-intensive, making it difficult to adapt to edge environments where nodes frequently connect and disconnect, especially for resource-constrained embedded systems. Existing technologies cannot balance fast election in the network initialization phase and reliable state coordination in the running phase, and the speed of the control plane and the reliability of the data plane cannot be effectively coordinated, making it difficult for the system to smoothly transition from temporary networking to stable operation in a dynamic environment. SUMMARY
[0004] Therefore, it is necessary to provide a wireless network dynamic master election method based on two-layer multicast and MQTT cooperation that can achieve smooth transition from temporary networking to stable operation.
[0005] A wireless network dynamic master election method based on two-layer multicast and MQTT cooperation, the method comprising: Constructing an initial peer-to-peer node architecture and deploying multiple network nodes with equal communication and processing capabilities, each node having a master election module and an MQTT client module built-in, all nodes initially in a peer-to-peer state; Each node initiates Layer 2 multicast communication through the master election module by using a MAC multicast address at the data link layer, periodically sends wireless link signal strength information between itself and neighboring nodes to adjacent nodes, and receives link signal strength information transmitted by other nodes through Layer 2 multicast; Each node performs link quality score calculation through the master election module according to the obtained network-wide link signal strength information, each node synchronizes its own link quality score and master candidate information to the entire network through Layer 2 multicast, the receiving node compares the link quality scores of all candidates, and selects the node with the highest link quality score as the master node; The master node starts the local MQTT Broker module, synchronizes the network state address information of its MQTT Broker to the entire network through Layer 2 multicast, other nodes receive the network state address information through their own MQTT client module, and establish a connection with the MQTT Broker of the master node based on the network state address information, build an MQTT communication architecture, the MQTT data plane in the MQTT communication architecture carries business message transmission between nodes, and the MQTT control plane carries network state perception, master migration notification and other control signaling transmission; Each node periodically publishes its real-time link quality score to the entire network through the MQTT control plane, and the master node collects and analyzes the network-wide link quality score data in real time; if the master node detects that the link quality degradation rate of itself exceeds a preset threshold in consecutive multiple monitoring periods, and there is at least one neighbor node whose link quality score difference with the link quality score of itself is greater than a preset threshold, and the current master term has exceeded a preset protection period, the master dynamic migration process is triggered; The original master node that triggers the migration process publishes a resignation notice to the entire network through the MQTT control plane, and stops receiving new election requests; the neighbor node whose link quality score meets the condition is the new master candidate node, starts the local MQTT Broker module, and synchronizes the network state address information of its MQTT Broker through the MQTT control plane; after other nodes receive the network state address information of the new master candidate node, they switch the connection to the MQTT Broker of the new master node through the MQTT client module; the original master node keeps the MQTT Broker running for a preset period of time, and closes the Broker after the existing clients complete session cleaning.
[0006] The wireless network dynamic master election method based on the cooperation of two-layer multicast and MQTT provided by the application breaks the dependence on the preset infrastructure by constructing an initial peer-to-peer node architecture, deploying multiple network nodes with equal communication and processing capabilities, and embedding a master election module and an MQTT client module in each node. All nodes can be automatically started without a preset master or external coordination service, avoiding the problems of complex deployment and large resource consumption of the ZooKeeper solution. At the same time, the link signal strength information is transmitted directly at the data link layer using the MAC multicast address, without the need for complex processes such as IP allocation, ARP resolution, or IGMP registration, which not only realizes millisecond-level link awareness but also avoids the protocol overhead and channel congestion risk of three-layer multicast, providing a fast-converging basis for temporary networking and solving the core problem of how to quickly start networking in a centerless environment. During the transition to stable operation, the LQS score calculated based on the link signal strength of the entire network comprehensively considers the link quality, number of neighbors, and stability to ensure that the elected master node has the optimal network connection conditions and topological centrality, reducing the risk of subsequent service interruption. After the master node starts the MQTT Broker, low-bandwidth, asynchronous interaction is realized through data plane bearing business messages, and the control plane transmits network status and migration signaling to maintain network consistency, which not only makes up for the lack of structured state synchronization in traditional broadcast / multicast solutions but also adapts to resource limitations in edge environments through lightweight protocols, realizing seamless connection from temporary networking to stable data transmission. The master node collects LQS data from the entire network in real time through the MQTT control plane, and initiates migration when the link degradation threshold is exceeded, there is a better node, and the protection period is exceeded, which not only avoids message congestion caused by link degradation but also prevents frequent switching caused by transient fluctuations through multiple conditions. The original master keeps the Broker running until the session is cleaned up, and the new master synchronizes the address through multicast, ensuring that the switching is imperceptible. At the same time, each node locally caches messages, temporarily stores data when the network is interrupted or the master is missing, and automatically retransmits them after recovery, completely solving the message loss problem in network reconstruction and forming a full-cycle stable guarantee, ultimately realizing smooth transition and continuous self-healing from temporary networking to stable operation. BRIEF DESCRIPTION OF DRAWINGS
[0007] Figure 1 A flowchart of a wireless network dynamic master election method based on the cooperation of two-layer multicast and MQTT in one embodiment; Figure 2 A schematic diagram of an initial peer-to-peer node architecture in one embodiment; Figure 3 A flowchart of a master election algorithm in one embodiment; Figure 4 A flowchart of master election and centralized network establishment / reconstruction in another embodiment; Figure 5 This is a schematic diagram of the master control migration process based on relative link advantage in one embodiment; Figure 6 This is a flowchart illustrating the local message caching and recovery mechanism in one embodiment. Detailed Implementation
[0008] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0009] In one embodiment, such as Figure 1 As shown, a dynamic master election method for wireless networks based on Layer 2 multicast and MQTT collaboration is provided, including the following steps: Step 102: Construct an initial peer-to-peer node architecture, deploy multiple network nodes with equal communication and processing capabilities, each node has a built-in master election module and MQTT client module, and all nodes are initially in a peer-to-peer state.
[0010] Building the initial peer-to-peer node architecture as follows Figure 2 As shown, the network consists of multiple peer-to-peer nodes, including node A, node B, and node C. Each node has a built-in master node election module and MQTT client module. Initially, all nodes are equal and possess the same communication and processing capabilities. The master node sends election-related messages to other nodes via Layer 2 multicast to complete the node election. After node A is elected as the master node, it starts its MQTT Broker module. Nodes B and C establish connections with the MQTT Broker in node A through their MQTT clients to conduct publish / subscribe communication. The MQTT data plane handles inter-node business communication, while the MQTT control plane handles network status awareness and network establishment and reconstruction.
[0011] By adopting an architecture design where all nodes are initially peer-to-peer and include a built-in master node election module and MQTT client module, decentralized network startup and dynamic role allocation are achieved. This avoids dependence on a preset master node or external coordination services, allowing the system to autonomously negotiate the master role when any node joins or the network initializes, thus improving the network's self-organization capabilities and topology adaptability.
[0012] Step 104: Each node initiates Layer 2 multicast communication at the data link layer using MAC multicast addresses through the master election module, periodically sending wireless link signal strength information between itself and its neighboring nodes to neighboring nodes, while simultaneously receiving link signal strength information transmitted by other nodes through Layer 2 multicast.
[0013] The master election algorithm proposed in the application has the principle that each node is divided into three grades of excellent, good and poor by sensing the wireless link quality between neighbors, and calculates its comprehensive link score (LQS). The score is composed of three parts: the sum of the quality weight of the neighbor link, the neighbor number weighted item and the stability bonus. The node with the highest final score is selected as the master to ensure that it has the best connection quality and topological centrality in the network.
[0014] Figure 3 In the figure, four nodes (nodes A to D) are connected by different colored lines to represent their respective link quality: green represents "excellent" (RSSI ≥ -70 dBm), orange represents "good" (-85 ≤ RSSI < -70 dBm), and red represents "poor" (RSSI < -85 dBm). Each node calculates its LQS score according to the quality and number of its adjacent links, among which node B has the highest score and is therefore selected as the new master and starts the local MQTT Broker service to provide topics such as mesh / join and mesh / members for other nodes to access and synchronize status.
[0015] The master election and link state sensing are implemented using two-layer multicast, which directly transmits election-related messages through MAC multicast addresses at the data link layer without relying on IP address allocation, ARP resolution or routing protocol support. This avoids the complex processes such as IGMP registration, multicast routing establishment and TTL hop limit in three-layer multicast, realizes millisecond-level fast convergence, reduces communication delay and protocol overhead, and has higher real-time performance and robustness.
[0016] In step 106, each node calculates the link quality score through the master election module according to the acquired network-wide link signal strength information, and synchronizes the link quality score and master candidate information to the entire network through two-layer multicast. The receiving node compares the link quality scores of all candidates and selects the node with the highest link quality score as the master node.
[0017] All nodes are in a peer-to-peer state initially, and link quality assessment and master candidate competition are performed through local two-layer multicast mechanism. When a node starts or the network topology changes, each member node sends signal strength information to neighboring devices through two-layer multicast to evaluate the connection stability and link quality between them.
[0018] After completing the preliminary link detection, each node calculates its priority to become the master node according to the preset comprehensive scoring mechanism (including link quality, number of neighbors, running stability, etc.), and synchronizes the master candidate information to the whole network through two-layer multicast. The receiving node compares and confirms the received information, and finally selects the node with the optimal network condition as the master node, realizing the dynamic establishment of the master role.
[0019] The master election algorithm based on link quality score (LQS) comprehensively evaluates link quality, number of neighbors, and running stability to ensure that the node with the highest score is elected as the master. The master node has better network connection conditions and centralized topology position, improving its reliability as a communication hub and data forwarding efficiency, and reducing the risk of service interruption due to link degradation of the master node.
[0020] Step 108, use the master node to start the local MQTT Broker module, and synchronize its MQTT Broker network state address information to the whole network through two-layer multicast; other nodes receive network state address information through their own MQTT client module, and establish connection with the MQTT Broker of the master node based on the network state address information, build MQTT communication architecture, and MQTT data face carries business message transmission between nodes in the MQTT communication architecture, and MQTT control plane carries network state perception, master migration notification, and other control signaling transmission.
[0021] As shown in Figure 4 After the master node is determined, it enters the second stage: Broker starts and synchronizes with the network. The elected master node starts the MQTT Broker service locally and broadcasts its network state address information, including IP address, port number, and session identifier, through two-layer multicast, so that other member nodes can obtain the master position information. After receiving the information, the remaining nodes actively initiate a connection request to access the MQTT service provided by the master node, thereby realizing centralized communication synchronization of the entire network and building a data transmission channel.
[0022] The MQTT protocol is used for both data plane and control plane design. In the data plane, MQTT undertakes business data transmission function, realizing decoupling, asynchronous, and low bandwidth consumption data interaction; in the control plane, reliable transmission of control signaling and consistency maintenance of the whole network state are realized, significantly reducing system complexity and resource overhead.
[0023] Step 110, each node periodically publishes its real-time link quality score to the whole network through the MQTT control plane, and the master node collects and analyzes the link quality score data of the whole network in real time; if the master node detects that the link quality degradation ratio of itself exceeds the preset threshold in continuous multiple monitoring periods, and there is at least one neighbor node whose link quality score difference with the link quality score of itself is greater than the preset threshold, and the current master term has exceeded the preset protection period, the master dynamic migration process is triggered.
[0024] As shown in Figure 5 , all nodes periodically perform health checks, calculate their own LQS, and publish them through MQTT, so that each node can master the global network status in real time. When the network health status of the current master node continues to deteriorate and it is detected that its link quality score (LQS) has fallen below that of other potential candidate nodes, the system will start the active master migration process.
[0025] Step 112, the original master node triggering the migration process publishes the resignation notice to the whole network through the MQTT control plane, and stops receiving new election requests; the neighbor nodes whose link quality scores meet the conditions become new master candidate nodes, start the local MQTT Broker module, and synchronize the network status address information of their own MQTT Broker through the MQTT control plane; after receiving the network status address information of the new master candidate node, other nodes switch the connection to the MQTT Broker of the new master node through the MQTT client module; the original master node keeps the MQTT Broker running for a preset period of time, and closes the Broker after the existing clients complete the session cleaning.
[0026] As shown in Figure 5 , in continuous multiple heartbeat periods, if the link quality degradation ratio of the master node X exceeds the preset threshold (for example, 66%), and there is a neighbor node Y whose LQS is higher than that of X by more than 3.0, and the current term has exceeded the protection period, the master node X judges that it no longer has the optimal network conditions, and triggers the active resignation mechanism. At this time, the master node X publishes its intention to resign to the network, and stops receiving new election requests to prevent service conflicts. At the same time, the candidate node Y has higher LQS and better connection ability, and starts the local MQTT Broker service immediately after receiving the master resignation signal, and publishes its own service address information (such as IP, port, and new term number). After receiving this information, other slave nodes start to gradually connect to the new master node Y, and complete the smooth switching of the communication channel. To avoid service interruption, the original master node X still keeps the MQTT Broker running for a period of time during the handover, allowing existing clients to complete message transmission and session cleaning. After the new master node Y takes over stably, the old master node X automatically closes its Broker service to avoid forming a ghost node or double service conflict.
[0027] The master dynamic migration algorithm based on relative link advantage realizes preventive, low-delay and non-aware master migration, avoids message congestion or response lag caused by link quality decline of master node; at the same time, through setting multiple judgment conditions and term protection mechanism, frequent master switching caused by link transient fluctuation is effectively prevented, and system stability is ensured.
[0028] In the self-organizing establishment or reconstruction process of MESH network, the centralized service (such as MQTT Broker) may be temporarily missing. Each node in the proposal has the ability of local persistent message cache, and when it is detected that the network is unreachable or there is no master, the messages that should be published are temporarily stored in local Flash or non-volatile memory. After the network is restored or a new master is established, the node automatically connects and plays back the cached messages in batches, realizing no data loss.
[0029] As shown in Figure 6 , node A generates messages in the masterless stage, and writes them into the local cache because it cannot connect to the Broker. When it receives the new master ready, node A connects to the Broker and queries the cache, and retransmits all unsent messages in order. After successful transmission, the cache is marked as sent, and subsequent cleaning is performed.
[0030] Each node has a local persistent message cache mechanism, which temporarily stores the messages to be published during the absence of the master or network interruption, and automatically retransmits them after the network is restored, effectively solving the problem of message loss during network establishment and reconstruction, ensuring the integrity of critical business data, and realizing reliable data transmission.
[0031] The wireless network dynamic master election method based on the two-layer multicast and MQTT cooperation, constructs an initial peer-to-peer node architecture, deploys multiple network nodes with equal communication and processing capabilities, each node is built-in with a master election module and an MQTT client module, breaks the dependence on the preset infrastructure, and all nodes can be automatically started without a preset master or external coordination service, avoiding the problems of complex deployment and large resource consumption of ZooKeeper and other solutions. At the same time, the link signal strength information is transmitted directly in the data link layer using the MAC multicast address, without the need for complex processes such as IP allocation, ARP resolution or IGMP registration, which not only realizes millisecond-level link awareness, but also avoids the protocol overhead and channel congestion risk of three-layer multicast, providing a fast convergence basis for temporary networking, and solving the core problem of how to quickly start networking in a centerless environment. In the transition to stable operation, based on the LQS score calculated by the link signal strength of the entire network, the link quality, the number of neighbors and the stability are comprehensively considered to ensure that the elected master node has the optimal network connection conditions and topological centrality, reducing the risk of subsequent service interruption. After the master node starts the MQTT Broker, low-bandwidth asynchronous interaction is realized through data plane bearing business messages, and network state and migration signaling are transmitted through the control plane to maintain network consistency, which not only makes up for the lack of structured state synchronization in traditional broadcast / multicast solutions, but also adapts to resource limitations in edge environments through lightweight protocols, realizing seamless connection from temporary networking to stable data transmission. The master node collects LQS data from the entire network in real time through the MQTT control plane, and initiates migration when the link degradation threshold is exceeded, there is a better node, and the protection period is exceeded, which not only avoids message congestion caused by link degradation, but also prevents frequent switching caused by transient fluctuations through multiple conditions. The original master keeps the Broker running until the session is cleaned up, and the new master synchronizes the address through multicast, ensuring that the switching is not perceived. At the same time, each node locally caches messages, temporarily stores data when the network is interrupted or the master is missing, and automatically retransmits after recovery, completely solving the message loss problem in network reconstruction, forming a full-cycle stable guarantee, and finally realizing smooth transition and continuous self-healing from temporary networking to stable operation.
[0032] In one embodiment, the link quality score is composed of the sum of the quality weights of the node and neighbor links, the number of neighbors weighted item, and the link stability bonus, which is: LQS = (Σ neighbor link quality weight) + (neighbor number x number weighting coefficient) + stability bonus.
[0033] In one embodiment, the number weighting coefficient is dynamically adjusted according to the total number of network nodes, and the more the total number of nodes, the smaller the coefficient value; the stability bonus is determined according to the length of continuous operation without interruption of the node, and the longer the operation time, the higher the bonus value.
[0034] In one of the embodiments, the network state address information includes IP address, port number and session identification; the MQTT Broker of the master node creates at least two topics: one is a data topic for business message transmission, with the naming format of "mesh / data / [business type]"; the other is a control topic for control signaling transmission, with the naming format of "mesh / control / [signaling type]", and the signaling type includes node health status, master term information and migration notification.
[0035] In one of the embodiments, when the master node receives the link quality scores of other nodes through the MQTT control plane, the link quality scores of each node are time-stamped, and only the valid link quality score data within the preset time window is used for analysis.
[0036] In one of the embodiments, the original master node keeps the MQTT Broker running for a preset duration, which is determined according to the average transmission duration of historical business messages and is set as N times of the historical average transmission duration; after starting the MQTT Broker, the new master node repeatedly sends the network state address information M times through the second layer multicast to ensure that all nodes can receive it.
[0037] In one of the embodiments, the local non-volatile storage module uses Flash or EEPROM, and the cached messages include message identification, generation timestamp, message type and message content; before retransmitting the message, the node first queries the master node through the MQTT control plane whether the message identification already exists, and only retransmits the message that does not exist to avoid repeated transmission.
[0038] In one of the embodiments, the master node periodically initiates a network-wide node survival detection through the MQTT control plane, and sends detection signaling to all nodes; if no response signaling from a certain node is received within a preset timeout period, the node is marked as offline, and the offline node information is synchronized to the entire network through the MQTT control plane; after receiving the offline node information, other nodes automatically exclude the link quality data of the offline node when calculating their own link quality scores.
[0039] In one of the embodiments, when a new node joins the wireless MESH network, the new node sends a network access request through the second layer multicast after starting, the master node synchronizes the current network-wide link state and MQTT Broker network state address information to the new node through the second layer multicast after receiving the request; the new node calculates its initial link quality score based on the information and synchronizes it to the entire network, and at the same time connects the MQTT Broker of the master node to complete the network access process without triggering the master node election of the entire network again.
[0040] In one of the embodiments, at any stage, if the node detects that the network is unreachable or there is no available master node, the business messages and control signaling to be published are temporarily stored by the local non-volatile storage module; when the node reconnects to the MQTT Broker of the master node, the unsent messages in the local cache are automatically queried, and are batched and re-sent to the MQTT Broker according to the message generation order, and the messages are marked as sent after the sending is successful and are cleaned up regularly.
[0041] It should be understood that although Figure 1 The steps in the flowcharts of the embodiments are shown in sequence according to the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other sequences. Moreover, Figure 1 At least part of the steps in the embodiments can include multiple sub-steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution sequence of the sub-steps or stages is not necessarily sequential, but can be executed in rotation or alternation with other steps or sub-steps or stages of other steps.
[0042] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing related hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when executed, can include the processes of the above-mentioned embodiments. Any reference to memory, storage, database or other medium used in the embodiments provided by the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0043] Any technical features in the above embodiments can be combined, and for the sake of brevity, not all possible combinations are described above, however, as long as the combinations of technical features do not contradict each other, they shall be considered within the scope of the present disclosure.
[0044] The above embodiments only express several implementation manners of the present application, and the description is relatively specific and detailed, but it shall not be understood as a limitation on the scope of the present application. It should be noted that, for those skilled in the art, several modifications and improvements can be made without departing from the concept of the present application, and these shall be within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the appended claims.
Claims
1. A method for dynamic master election in a wireless network based on Layer 2 multicast and MQTT collaboration, characterized in that, The method includes: Build an initial peer-to-peer node architecture, deploy multiple network nodes with equal communication and processing capabilities, each node has a built-in master election module and MQTT client module, and all nodes are initially in a peer-to-peer state; Each node initiates Layer 2 multicast communication at the data link layer using MAC multicast addresses through the master election module, periodically sending wireless link signal strength information between itself and its neighboring nodes to neighboring nodes, while simultaneously receiving link signal strength information transmitted by other nodes through Layer 2 multicast. Each node calculates the link quality score based on the obtained link signal strength information of the entire network through the master control election module. Each node synchronizes its own link quality score and master control candidate information to the entire network through Layer 2 multicast. The receiving node compares the link quality scores of all candidates and selects the node with the highest link quality score as the master control node. The master node starts its local MQTT Broker module and synchronizes its MQTT Broker's network status address information to the entire network via Layer 2 multicast. Other nodes receive the network status address information through their own MQTT client modules and establish connections with the master node's MQTT Broker based on the network status address information, thus constructing an MQTT communication architecture. In this architecture, the MQTT data plane carries the transmission of business messages between nodes, while the MQTT control plane carries the transmission of control signaling such as network status awareness and master migration notification. Each node periodically publishes its real-time link quality score to the entire network through the MQTT control plane. The master node collects and analyzes the link quality score data of the entire network in real time. If the master node detects that its link quality degradation ratio exceeds the preset threshold in multiple consecutive monitoring periods, and the difference between the link quality score of at least one neighbor node and its own link quality score is greater than the preset threshold, and the current master node term has exceeded the preset protection period, then the master node dynamic migration process is triggered. The original master node that triggered the migration process publishes a resignation notice to the entire network via MQTT control and stops receiving new election requests. Neighboring nodes whose link quality scores meet the criteria become new master candidate nodes, start their local MQTTBroker modules, and synchronize the network status address information of their own MQTT Brokers through the MQTT control plane. After receiving the network status address information of the new master candidate nodes, other nodes switch to the MQTT Broker connected to the new master node through their MQTT client modules. The original master node keeps the MQTT Broker running for a preset time, and shuts down the Broker after the existing clients have completed session cleanup.
2. The method according to claim 1, characterized in that, The link quality score is composed of the sum of the quality weights of the node and its neighboring links, a neighbor quantity weighting term, and a link stability bonus, as follows: LQS = (Σ Neighbor link quality weights) + (Number of neighbors × Quantity weighting coefficient) + Stability bonus.
3. The method according to claim 2, characterized in that, The quantity weighting coefficient is dynamically adjusted based on the total number of network nodes; the more nodes there are, the smaller the coefficient value. The stability bonus is determined based on the duration of continuous operation without disconnection of the node; the longer the operation duration, the higher the bonus value.
4. The method according to claim 1, characterized in that, The network status address information includes IP address, port number, and session identifier; the MQTT Broker of the master node creates at least two topics: one is a data topic for business message transmission, named "mesh / data / [business type]"; the other is a control topic for control signaling transmission, named "mesh / control / [signaling type]", where the signaling type includes node health status, master term information, and migration notification.
5. The method according to claim 1, characterized in that, When the master node receives link quality scores from other nodes through the MQTT control plane, it timestamps the link quality score of each node and only uses valid link quality score data within a preset time window for analysis.
6. The method according to claim 1, characterized in that, The original master node maintains the MQTT Broker for a preset duration, determined based on the historical average transmission time of business messages, and set to N times the historical average transmission time. After starting the MQTT Broker, the new master node repeatedly sends network status address information M times via Layer 2 multicast to ensure that all nodes can receive it.
7. The method according to claim 1, characterized in that, The local non-volatile storage module uses Flash or EEPROM. The cached messages include message identifier, generation timestamp, message type, and message content. Before retransmitting a message, the node first queries the master node via MQTT to see if the message identifier already exists. Only messages that do not exist are retransmitted to avoid duplicate transmission.
8. The method according to claim 1, characterized in that, The method further includes: The master node periodically initiates a network-wide node liveness probe via the MQTT control plane, sending probe signaling to all nodes. If no response signaling is received from a node within a preset timeout period, the node is marked as offline, and the offline node information is synchronized to the entire network via the MQTT control plane. After receiving the offline node information, other nodes automatically remove the link quality data of the offline node when calculating their own link quality score.
9. The method according to claim 1, characterized in that, The method further includes: When a new node joins the wireless MESH network, it sends a network entry request via Layer 2 multicast after startup. Upon receiving the request, the master node synchronizes the current network link status and MQTT Broker network status address information to the new node via Layer 2 multicast. Based on this information, the new node calculates its initial link quality score and synchronizes it to the entire network. At the same time, it connects to the master node's MQTT Broker to complete the network entry process without needing to re-trigger the network master election.
10. The method according to claim 1, characterized in that, The method further includes: At any stage, if a node detects that the network is unreachable or there is no available master node, it temporarily stores the business messages and control signaling to be published through the local non-volatile storage module. When the node reconnects to the MQTT Broker of the master node, it automatically queries the unsent messages in the local cache, resends them to the MQTT Broker in batches according to the message generation order, and marks the messages as sent after successful transmission and cleans them up periodically.
