Internet of things multi-Android client state synchronization method

By using MQTT and UDP protocols in tandem, the client can directly broadcast to achieve state synchronization among multiple Android clients in the Internet of Things, solving the problems of poor state consistency, high backend dependency, and large latency. It is compatible with various types of terminals and improves the real-time performance and reliability of synchronization.

CN121771226APending Publication Date: 2026-03-31SICHUAN CHANGHONG EDUCATION TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511990203.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-26
Publication Date
2026-03-31

AI Technical Summary

Technical Problem

Existing IoT multi-Android client state synchronization suffers from poor state consistency, high backend dependency, large latency, and insufficient compatibility.

Method used

It employs a combination of MQTT and UDP protocols to achieve state synchronization through direct broadcasting from the client. This includes client initialization, MQTT message listening and parsing, and UDP synchronization message construction and broadcasting. Combined with timestamp verification and exception handling mechanisms, it ensures state consistency and low latency.

Benefits of technology

It achieves real-time and consistent state synchronization across multiple Android clients, reduces backend dependencies and deployment costs, adapts to various terminals, and improves the reliability and security of synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121771226A_ABST
    Figure CN121771226A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of Internet of Things communication, discloses an Internet of Things multi-Android client state synchronization method, and solves the problems of poor state consistency, high back-end dependence, large delay and insufficient compatibility in the prior art. According to the scheme, the method comprises the steps that after a client completes initialization, MQTT connection with a rear end is established, an MQTT state message pushed by the rear end is monitored, after the message is received, equipment state information is obtained through analysis, local state cache and a UI interface are updated, meanwhile, the client serves as a distribution node, a UDP synchronization message containing the equipment state and the IP of the distribution node is established, and the UDP synchronization message is sent to the client. The UDP synchronization message is broadcasted to the local area network, other clients in the local area network receive the UDP synchronization message and then verify whether the distribution node IP is the client in the local area network, if the verification is passed, the message is analyzed, the state updating timestamp and the local cache timestamp are compared, and the local state cache and the UI interface are updated only when the state updating timestamp is larger.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of Internet of Things (IoT) communication technology, and specifically to a method for synchronizing the status of multiple Android clients in the Internet of Things. Background Technology

[0002] With the deep integration of IoT technology and smart terminals, the need for multiple Android clients (such as mobile phones, tablets, and smart control screens) to collaboratively control IoT devices (lights, air conditioners, sensors, etc.) in scenarios such as homes and offices is becoming increasingly common. In these scenarios, after a user issues a control command through any client, all associated clients need to display the latest device status in real time and consistently to avoid misoperation due to status discrepancies and ensure a good user experience.

[0003] In current mainstream IoT control systems, the interaction between Android clients and device status generally adopts a core model of HTTP command issuance + MQTT status feedback: the client sends device control commands to the backend via HTTP requests, the device executes the commands and reports the status change information to the backend, and the backend then pushes update messages to all clients subscribed to the device status topic via the MQTT protocol. However, this model still has many shortcomings in scenarios where multiple Android clients collaborate within the same local area network: (1) Poor state consistency, which easily leads to erroneous operations: MQTT message push relies on the connection management and forwarding capabilities of the Broker (message broker server). However, in practical applications, due to factors such as Broker connection pool capacity limitations and client network fluctuations, some clients often miss receiving MQTT status messages. For example, if a user adjusts the air conditioner temperature from 24°C to 26°C using mobile phone A, the status update message pushed by the backend is only received by mobile phone A, while tablet B, not having received the message, still displays 24°C. This results in inconsistent device statuses displayed on different clients, potentially leading to duplicate or erroneous operations by the user.

[0004] (2) High backend dependency and significant synchronization delay: To mitigate the inconsistency in state, existing solutions often employ a backend MQTT message mass sending mechanism. This means that after receiving a device state update, the backend proactively pushes an MQTT message to all clients bound to that device. However, this approach significantly increases backend bandwidth and computing power consumption, especially in scenarios with a large number of devices and frequent state updates, leading to a sharp increase in backend pressure. Furthermore, the state messages require a public network forwarding path from device to backend to client, resulting in synchronization delays (typically ≥500ms), which cannot meet the needs of real-time collaborative control across multiple clients.

[0005] (3) High compatibility and deployment costs, poor adaptability: Some solutions attempt to achieve state synchronization through client-to-client communication, but this requires pre-maintaining a list of IP addresses for all clients within the local area network, making configuration complex and only supporting specific Android versions, thus failing to adapt to multi-terminal scenarios.

[0006] In addition, existing technologies rely on third-party communication frameworks (such as MQTT and Netty), which increases software complexity. If only UDP is used to implement direct communication between clients, although latency can be reduced, the connectionless nature of UDP can easily lead to the loss of state messages, and the reliability of initial state synchronization cannot be guaranteed. On the other hand, relying solely on the MQTT protocol cannot solve the problems of missed pushes and latency in multi-client scenarios.

[0007] Therefore, there is an urgent need to develop a lightweight, low-latency, backend-independent, and highly compatible multi-Android client state synchronization solution. Summary of the Invention

[0008] The technical problem to be solved by this invention is to provide a method for synchronizing the state of multiple Android clients in the Internet of Things, which solves the problems of poor state consistency, high backend dependency, large latency and insufficient compatibility in the prior art.

[0009] The technical solution adopted by the present invention to solve the above-mentioned technical problems is as follows: A method for synchronizing the state of multiple Android clients in the Internet of Things (IoT) includes the following steps: S1. After each Android client starts, it automatically initializes the MQTT connection parameters and UDP communication parameters; S2. Each Android client establishes a long MQTT connection with the backend, subscribes to a preset IoT device status topic, and listens for MQTT status messages pushed by the backend in real time; S3. When any Android client acts as a distribution node and receives the MQTT status message, it parses the message to obtain device status information containing device ID, status type, status value, and update timestamp. S4. The distribution node updates its local status cache and UI interface based on the device status information. After the update is successful, it constructs a UDP synchronization message containing the device status information and the distribution node's IP address. S5. The distribution node broadcasts the UDP synchronization message to the UDP broadcast address and preset port of the local area network via a UDP socket; S6. Other Android clients within the local area network listen to the preset UDP broadcast port. After receiving the UDP synchronization message, they verify whether the distribution node IP belongs to the current local area network segment. If the verification is successful, they parse the message and compare the status update timestamp with the local cache timestamp. They only update the local status cache and UI interface when the status update timestamp is larger.

[0010] Furthermore, in step S1, the MQTT connection parameters include: the backend MQTT Broker address, port, and client ID; the UDP communication parameters include: the preset UDP broadcast port, LAN IP address, and broadcast address.

[0011] Furthermore, the client ID is generated using the format of device MAC address + 8-digit random string. Furthermore, in step S4, the UDP synchronization message is in JSON format and contains at least five fields: deviceId (device ID), statusType (status type), statusValue (status value), timestamp (update timestamp), and broadcasterIp (distribution node IP). When broadcasting UDP, local area network broadcasting is enabled by configuring setBroadcast.

[0012] Furthermore, in step S2, the Android client only starts the UDP listening thread after the MQTT connection is successful and the state topic is subscribed.

[0013] Furthermore, in step S4, when updating the local state cache and the UI interface, the order is to update the local state cache first and then update the UI interface.

[0014] Furthermore, in step S6, if the client simultaneously receives the status update of the same device via both MQTT direct reception and UDP reception, the status updated by the timestamp will be given priority; if the timestamps are the same, the status received directly via MQTT will be retained first.

[0015] Furthermore, step S2 also includes: After establishing a persistent MQTT connection with the backend, the Android client monitors the connection status. If the MQTT connection is detected to be broken, a timed reconnection mechanism is initiated.

[0016] Furthermore, step S5 also includes: if the distribution node fails to send a UDP synchronization message, it will retries twice and then terminate, and an error log will be recorded.

[0017] Furthermore, step S6 also includes: after the client receives and updates the state via UDP, it triggers a local state update flag to prevent itself from initiating UDP broadcasts again.

[0018] The beneficial effects of this invention are: (1) Improved real-time performance and consistency, eliminating erroneous operations: This invention overcomes the transmission bottleneck of traditional backend MQTT mass messaging by changing the local area network (LAN) synchronization logic from backend forwarding to direct client broadcasting. The LAN broadcast latency of the UDP protocol is ≤100ms, far lower than the synchronization latency of public network forwarding (≥500ms), ensuring virtually imperceptible latency for multiple clients' state updates. Simultaneously, through a mechanism of UDP broadcasting by the distribution node plus timestamp verification by other clients, even if some clients miss receiving backend MQTT messages, the latest state can be completed via UDP synchronization, achieving a synchronization success rate of ≥99.5%. This completely solves the problem of inconsistent states between different clients and avoids user errors caused by state discrepancies.

[0019] (2) No additional backend dependencies, reducing deployment and maintenance costs: This invention requires no modification to the existing logic of the backend MQTT Broker, nor does it require the addition of extra functions such as mass messaging or state storage. Synchronization is achieved entirely through protocol coordination on the client side, significantly reducing backend bandwidth usage and computing power consumption. For scenarios where IoT systems have already been deployed, implementation can be achieved simply by upgrading the software on the Android client side, without modifying the hardware or backend architecture. This shortens the development cycle, reduces adaptation costs, and provides strong compatibility and scalability.

[0020] (3) Lightweight and compatible, adaptable to multiple scenarios and versions of terminals: This invention eliminates reliance on third-party communication frameworks, using only native Android APIs (DatagramSocket, MqttClient, etc.) to implement core functions, eliminating the need for additional libraries and reducing software complexity and maintenance costs. Furthermore, the solution supports all mainstream Android versions 7.0 and above, and is compatible with various Android smart terminals such as smartphones, tablets, and smart control systems, covering diverse application scenarios including home, office, and industrial IoT.

[0021] (4) Multiple safeguards enhance synchronization reliability and security: This invention constructs a triple reliability guarantee system of protocol complementarity, verification, and exception handling: First, the MQTT protocol ensures reliable reception of initial state messages, and the UDP protocol ensures fast synchronization within the local area network, with the two complementing each other to avoid the defects of a single protocol; second, LAN IP verification prevents unauthorized external messages from intruding, and timestamp comparison prevents old states from overwriting new states, ensuring synchronization accuracy; third, for scenarios such as MQTT disconnection and UDP transmission failure, a timed reconnection and retry mechanism is designed, while "local update flag" prohibits repeated broadcasts, avoiding broadcast storms and ensuring a stable and uninterrupted synchronization process.

[0022] (5) Intelligent adjudication of state conflicts, balancing credibility and accuracy: When a client simultaneously receives status updates for the same device via both MQTT direct reception (from the backend) and UDP reception (from other clients), this invention employs a priority decision-making logic: states updated with timestamps are prioritized to ensure the latest device status is displayed; if timestamps are identical, the state received directly via MQTT is retained, as MQTT messages, originating directly from the backend, are more reliable. This logic ensures both the timeliness of the status update and the reliability of the source, further improving the accuracy of status synchronization. Attached Figure Description

[0023] Figure 1 This is a flowchart illustrating the processing flow of each client in the IoT multi-Android client state synchronization method of this invention. Detailed Implementation

[0024] This invention aims to provide a method for synchronizing the state of multiple Android clients in the Internet of Things (IoT), addressing the problems of poor state consistency, high backend dependency, high latency, and insufficient compatibility in existing technologies. Its core idea is to construct an integrated logic of reliable backend reception and fast local area network synchronization through the collaborative use of MQTT and UDP protocols, thereby resolving the consistency, latency, and backend dependency issues in synchronizing the state of multiple Android clients.

[0025] Specifically, this invention achieves the core idea described above through the following means: First, leveraging the reliability of the MQTT protocol, each client subscribes to the backend device status topic via a long connection, ensuring stable reception of initial status messages and avoiding UDP packet loss defects; Second, relying on the low latency characteristics of the UDP protocol, the client receiving the MQTT status message acts as a distribution node, directly synchronizing the status to other clients via LAN broadcast, eliminating the need for backend forwarding and reducing synchronization latency; Third, reliability is enhanced through multiple protection mechanisms, including using a unique client ID to avoid connection conflicts, LAN IP verification to prevent illegal messages, timestamp comparison to ensure status timeliness, and local update markers to prevent broadcast storms. Simultaneously, exception handling logic such as MQTT reconnection and UDP retry is designed to achieve lightweight, compatible, and real-time consistent multi-client status synchronization without relying on third-party frameworks or additional backend computing power.

[0026] In this invention, all Android clients execute a unified process, and any client can act as a distribution node to trigger full synchronization. (See also...) Figure 1 It includes the following processes: 1. Client initialization: MQTT parameter configuration and connection establishment: After the client starts, it automatically generates a unique client ID and automatically configures MQTT connection parameters (including Broker address, port, and authentication information) to establish a long-lived connection with the backend MQTT Broker. Upon successful connection, it subscribes to preset device status topics; if the connection fails, a timed reconnection mechanism is initiated until the connection is successful or the maximum number of retries is reached.

[0027] UDP parameter configuration and socket initialization: The client synchronously calculates the local area network broadcast address, initializes the UDPSocket and enables broadcast permissions, and binds to the preset port to listen for UDP messages. If the preset port is occupied, it automatically switches to the backup port to ensure that the UDP function is enabled normally.

[0028] The parallel initialization of the dual protocols here ensures that the client can quickly acquire the ability to receive and synchronize states after startup.

[0029] 2. MQTT Message Processing: Receive backend status and trigger local updates. MQTT message listening and parsing: The client maintains a persistent MQTT connection to listen for status messages pushed from the backend in real time. Upon receiving a message, it parses it into a pre-defined format to extract the device's unique ID, status type, status value, and update timestamp. If parsing fails, the message is discarded to avoid invalid data consuming resources.

[0030] Local state update: After successful parsing, the client updates the state in a "cached first, UI later" order. That is, the state information is first stored in the local cache, and then the UI is updated synchronously to ensure data consistency and synchronization with user visual feedback. If the update fails, an error log is recorded and subsequent synchronization operations are terminated.

[0031] 3. UDP broadcasting and receiving: UDP Synchronization Message Construction and Broadcasting: After a successful local state update, the client automatically constructs a UDP synchronization message containing complete state information and its own IP address, and sends it to the local area network broadcast address via a UDP socket. If the transmission fails, a retry mechanism is initiated. If the retry fails after two attempts, the process terminates and logs the message.

[0032] UDP message listening, verification, and status update: Other clients continuously listen to a preset port via UDP sockets. Upon receiving a message, they first verify whether the distribution node's IP belongs to the current local area network segment. After successful verification, they parse the status information and timestamp in the message and compare it with the latest timestamp of the device cached locally. Only when a new message timestamp is updated will the local status be updated in the order of "caching first, then UI"; otherwise, the message will be discarded.

[0033] 4. Exception handling and state conflict resolution: MQTT Disconnection and Reconnection: The client monitors the MQTT connection status in real time. If a disconnection is detected, a timed reconnection mechanism is immediately started. By increasing the reconnection interval, the backend pressure is reduced, and the status receiving capability is quickly restored after the network is restored.

[0034] UDP broadcast retry and storm protection: Automatically retry 2 times after UDP broadcast failure to improve message sending success rate; After the client receives and updates its status via UDP, it triggers the "local status update flag" to prevent itself from initiating UDP broadcast again, avoiding bandwidth congestion caused by multiple clients broadcasting in a loop.

[0035] State conflict resolution: If a client receives state updates for the same device simultaneously via MQTT and UDP, the state updated by the timestamp will prevail. If the timestamps are the same, the state received directly via MQTT will be retained, as MQTT messages come directly from the backend and are more reliable than UDP messages forwarded by the client, thus avoiding state errors.

[0036] Example: This example demonstrates how three Android devices (phone A, phone B, and tablet C) collaboratively control a smart air conditioner. Details are as follows: Initial state: All 3 clients have completed MQTT and UDP initialization, and the local cache and UI both display the air conditioner (device ID: AC_001) temperature as 24℃.

[0037] Status change trigger: The user sends a control command to "adjust the temperature to 26℃" via mobile phone A. The command is transmitted to the backend via HTTP protocol, and the backend forwards it to the air conditioner. After the air conditioner executes the command, it reports the status change information to the backend.

[0038] MQTT message reception and local update: The backend pushes an air conditioner status update message (including device ID, temperature 26℃, and update timestamp) via MQTT. Only phone A successfully receives the message (phones B and C did not receive it due to a temporary MQTT disconnection). After parsing the message, phone A updates its local cache and UI to 26℃.

[0039] UDP Broadcast and Cross-Terminal Synchronization: Phone A acts as a distribution node, constructing a UDP synchronization message and broadcasting it to the local area network. Phone B and Tablet C's UDP listening threads receive the message, verify that Phone A's IP address is a local area network address, compare the timestamps to detect the new status update, and synchronously update their local cache and UI to 26°C.

[0040] Results: All three clients ultimately displayed an air conditioning temperature of 26℃, with completely identical statuses and a synchronization delay of ≤100ms, verifying the ability of this invention to complete synchronization in scenarios where some clients miss receiving MQTT messages.

[0041] Although embodiments of the present invention have been described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the present invention, and all such changes and alterations shall not depart from the protection scope of the present invention.

Claims

1. A method for synchronizing states of multiple Android clients in an Internet of Things, the method comprising: The method comprises the following steps: S1. After each Android client is started, automatically initialize the MQTT connection parameters and the UDP communication parameters; S2. Each Android client establishes an MQTT long connection with the backend, subscribes to a preset Internet of Things device state topic, and listens to the MQTT state messages pushed by the backend in real time; S3. When any Android client acts as a distribution node and receives the MQTT state message, device state information including the device ID, the state type, the state value, and the update timestamp is obtained by analysis; S4. The distribution node updates the local state cache and the UI interface based on the device state information, and after successful updating, constructs a UDP synchronization message including the device state information and the distribution node IP; S5. The distribution node broadcasts the UDP synchronization message to the UDP broadcast address and a preset port of the local area network through the UDP Socket; S6. Other Android clients in the local area network listen to the preset UDP broadcast port, and after receiving the UDP synchronization message, verify whether the distribution node IP belongs to the current local area network segment, if the verification is passed, analyze the message and compare the state update timestamp with the local cache timestamp, and only when the state update timestamp is larger, update the local state cache and the UI interface.

2. The Internet of Things multi-Android client state synchronization method of claim 1, wherein in step S1, the MQTT connection parameters include the backend MQTT Broker address, the port, and the client ID; and the UDP communication parameters include the preset UDP broadcast port, the local area network IP, and the broadcast address.

3. The Internet of Things multi-Android client state synchronization method of claim 2, wherein the client ID is generated in the format of device MAC address + 8-bit random string.

4. The Internet of Things multi-Android client state synchronization method of claim 1, wherein in step S4, the UDP synchronization message is in JSON format and at least includes five fields of device ID, state type, state value, update timestamp, and distribution node IP.

5. The Internet of Things multi-Android client state synchronization method of claim 1, wherein in step S2, only when the MQTT connection is successful and the state topic is subscribed, the Android client starts the UDP listening thread.

6. The Internet of Things multi-Android client state synchronization method of claim 1, wherein in step S4, when updating the local state cache and the UI interface, the order of first updating the local state cache and then updating the UI interface is adopted.

7. The Internet of Things multi-Android client state synchronization method of claim 1, wherein in step S6, if the client simultaneously receives the state update of the same device through MQTT direct reception and UDP reception, the state updated with the timestamp is preferred; if the timestamps are the same, the state received through MQTT direct reception is preferred. ​ ​ ​ ​ ​ ​ 8. The IoT multi-Android client state synchronization method of claim 1, wherein, In step S2, further comprising: After the Android client establishes the MQTT long connection with the backend, it monitors the connection state. If it detects that the MQTT connection is disconnected, it starts the timed reconnection mechanism.

9. The IoT multi-Android client state synchronization method of claim 1, wherein, In step S5, further comprising: if the distribution node fails to send the UDP synchronization message, it terminates after 2 retries and records the error log.

10. The method of claim 1-9, wherein, In step S6, further comprising: after the client receives and updates the state through UDP, it triggers the local state update flag and prohibits itself from initiating UDP broadcast again.