Multi-device charging indicator light synchronization control method based on NTP time calibration
Patent Information
- Application Number
- CN202610732867.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-26
- Publication Date
- 2026-08-28
AI Technical Summary
[0002]目前充电设备所配备的 LED 指示灯大多采用独立本地时钟控制,缺乏统一的时间基准,多设备同时工作时呼吸灯相位难以保持一致,无法实现稳定同频渐变
[0014] Compared with existing technologies, this invention provides a unified time reference for multiple devices through NTP network time calibration, fundamentally solving the problem of multiple devices losing synchronization in their breathing lights and achieving global synchronous gradual change. It employs NTP time synchronization combined with local crystal oscillator drift compensation to effectively reduce accumulated time errors, improving synchronization accuracy and long-term operational stability. Upon power-up, devices automatically perform network discovery and master-slave self-election without manual configuration, simplifying network deployment and enhancing system scalability. Slave devices smoothly correct the breathing phase based on a closed-loop control algorithm, avoiding light jumps and flickering and optimizing the visual experience. It also features a robust anomaly adaptive mechanism, automatically degrading operation in scenarios such as no network, NTP synchronization failure, or master device disconnection, and supports state saving and power-on recovery, significantly improving system reliability and environmental adaptability.
Smart Images

Figure CN122661998A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of indicator light control technology, specifically relating to a method for synchronizing the charging indicator lights of multiple devices based on NTP time calibration. Background Technology
[0002] Currently, most LED indicator lights on charging devices are controlled by independent local clocks, lacking a unified time base. When multiple devices are working simultaneously, it is difficult to keep the breathing light phase consistent, making stable synchronous gradual changes impossible. Existing devices generally do not incorporate NTP network timing mechanisms, relying solely on local crystal oscillators for timing. Long-term operation is prone to time drift, resulting in low synchronization accuracy and poor stability. Multiple devices cannot automatically complete network discovery and master-slave role election, requiring manual parameter configuration, cumbersome network deployment, and insufficient scalability. During phase synchronization adjustment, direct jump correction methods are often used, which easily leads to phenomena such as light flickering and sudden brightness changes, resulting in a poor user experience. Furthermore, in abnormal scenarios such as network disconnection, NTP synchronization failure, and master device offline, the devices lack robust degradation operation and automatic recovery mechanisms, resulting in weak system reliability and environmental adaptability, making it difficult to meet the actual usage requirements of synchronous gradual change control for multi-device networking. Summary of the Invention
[0003] In view of this, the main objective of the present invention is to provide a method for synchronizing the charging indicator lights of multiple devices based on NTP time calibration.
[0004] To achieve the above objectives, the technical solution of the present invention is implemented as follows: This invention provides a method for synchronizing charging indicator lights of multiple devices based on NTP time calibration, comprising the following steps: Step S1: Power on the system and initialize the hardware, network, clock, and configuration files; Step S2: After initialization, perform NTP network time synchronization to obtain a unified time base; Step S3: After NTP synchronization succeeds or fails, the device discovery process is initiated, and the device role is determined through network broadcast and master-slave election; Step S4: The device enters the breathing operation state according to the determined role and performs LED brightness gradual change based on a unified time reference; Step S5: Receive the synchronization signal from the master device from the device, enter synchronization adjustment to correct the breathing phase, and return to breathing operation after phase alignment; Step S6: Respond to the mode switching command to update the breathing gradient parameters, or respond to the shutdown command to perform system shutdown and resource release.
[0005] In the above scheme, step S1 specifically includes: initializing the LED driver module with PWM, using ordinary GPIO in conjunction with hardware LEDC or TIM timer to drive the LED, setting the PWM operating frequency and initial duty cycle, and completing the GPIO pin multiplexing configuration; initializing the network module, prioritizing WiFi or Ethernet connection, obtaining a valid IP address via DHCP or static method, establishing a UDP socket and enabling the broadcast option; initializing the clock module, enabling hardware RTC or system tick timer, and establishing a system time base with microsecond-level precision; if the LED driver initialization fails, it will quickly blink 100ms on / 100ms off to report an error, and if the network fails to obtain an IP address within 10 seconds, it will enter standby mode.
[0006] In the above scheme, step S2 specifically includes: initiating synchronization requests sequentially according to the preset NTP server pool, calculating time offset and round-trip delay according to the RFC5905 protocol to complete calibration; retrying according to the exponential backoff strategy if synchronization fails, and compensating the local clock based on the local crystal oscillator drift rate; successful NTP synchronization requires that the time offset |θ| ≤ 5 seconds, server stratum ≤ 5, round-trip delay δ ≤ 500ms, and synchronization timeout ≤ 3 seconds, and drift compensation is stopped if synchronization is not achieved for more than 24 hours.
[0007] In the above scheme, the device discovery process in step S3 includes: using a custom UDP broadcast protocol, sending a discovery message carrying the unique identifier of the device once per second for three consecutive times, and the device randomly delays the start of sending and receiving by 0 to 2 seconds to avoid conflicts; if it does not hear the master device announcement, it becomes the master device; if it hears it, it completes the master-slave election according to priority and the dictionary order of the device ID; if the slave device does not receive the master device broadcast for 5 seconds, it is determined to be offline and triggers a re-election.
[0008] In the above scheme, in step S3, the master device maintains the online list of slave devices and the heartbeat mechanism. The slave device sends a heartbeat every 2 seconds. If the master device does not receive a heartbeat for more than 5 seconds, it marks the corresponding slave device as offline and removes it from the list. The offline device can be rebroadcast and added back.
[0009] In the above scheme, in step S4, the brightness of the breathing operation is calculated using a sine curve, an exponential pulse curve, or a triangular wave curve, and a 128-point brightness lookup table is supported. Gamma correction is performed before output. The breathing operation is linked with the charging status, and the breathing cycle and brightness range are matched according to different power ranges. When fully charged, it turns into constant brightness, and the parameters are automatically adjusted in high temperature or discharge mode.
[0010] In the above scheme, step S5 specifically includes: the slave device calculates the phase difference based on the master-slave timestamps and performs surround correction and network latency compensation; a positional PID control algorithm is used to smoothly correct the phase, with PID parameters Kp=0.8-1.2, Ki=0.05-0.2, Kd=0.2-0.5, integral limit |integral|≤0.1, phase difference dead zone |error|<0.005, and the maximum adjustment amount per cycle is limited to ±0.02 seconds.
[0011] In the above scheme, in step S5, the PID parameters are adaptively adjusted according to the breathing cycle. If synchronization fails 5 times in a row, the device enters the local free operation mode and attempts to rediscover the master device every 10 seconds.
[0012] In the above scheme, the mode switching in step S6 is triggered by pressing and holding the button for 2 seconds, UART command, or UDP network command. The master device broadcasts a mode change message, and the slave device synchronously updates the breathing parameters. If the switching fails, the previous mode is rolled back and the log is recorded.
[0013] In the above scheme, the system shutdown in step S6 sequentially executes the following steps: stop the breathing thread, shut down the network, set PWM to 0, release GPIO, and save the running state to non-volatile memory. When the system receives a shutdown, low battery, or over-temperature protection signal, it directly enters the shutdown process and executes the corresponding protection action. When power is lost, the LED is safely shut down by power supply from a large capacitor.
[0014] Compared with existing technologies, this invention provides a unified time reference for multiple devices through NTP network time calibration, fundamentally solving the problem of multiple devices losing synchronization in their breathing lights and achieving global synchronous gradual change. It employs NTP time synchronization combined with local crystal oscillator drift compensation to effectively reduce accumulated time errors, improving synchronization accuracy and long-term operational stability. Upon power-up, devices automatically perform network discovery and master-slave self-election without manual configuration, simplifying network deployment and enhancing system scalability. Slave devices smoothly correct the breathing phase based on a closed-loop control algorithm, avoiding light jumps and flickering and optimizing the visual experience. It also features a robust anomaly adaptive mechanism, automatically degrading operation in scenarios such as no network, NTP synchronization failure, or master device disconnection, and supports state saving and power-on recovery, significantly improving system reliability and environmental adaptability. Attached Figure Description
[0015] Figure 1 This is a flowchart of the multi-device charging indicator synchronization control method based on NTP time calibration according to the present invention. Detailed Implementation
[0016] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0017] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, article, or apparatus that includes that element.
[0018] This invention provides a method for synchronizing charging indicator lights of multiple devices based on NTP time calibration, comprising the following steps: Step S1: Power on the system and initialize the hardware, network, clock, and configuration files; Step S2: After initialization, perform NTP network time synchronization to obtain a unified time base; Step S3: After NTP synchronization succeeds or fails, the device discovery process is initiated, and the device role is determined through network broadcast and master-slave election; Step S4: The device enters the breathing operation state according to the determined role and performs LED brightness gradual change based on a unified time reference; Step S5: Receive the synchronization signal from the master device from the device, enter synchronization adjustment to correct the breathing phase, and return to breathing operation after phase alignment; Step S6: Respond to the mode switching command to update the breathing gradient parameters, or respond to the shutdown command to perform system shutdown and resource release.
[0019] In the above scheme, step S1 specifically includes: initializing the LED driver module with PWM, using ordinary GPIO in conjunction with hardware LEDC or TIM timer to drive the LED, setting the PWM operating frequency and initial duty cycle, and completing the GPIO pin multiplexing configuration; initializing the network module, prioritizing WiFi or Ethernet connection, obtaining a valid IP address via DHCP or static method, establishing a UDP socket and enabling the broadcast option; initializing the clock module, enabling hardware RTC or system tick timer, and establishing a system time base with microsecond-level precision; if the LED driver initialization fails, it will quickly blink 100ms on / 100ms off to report an error, and if the network fails to obtain an IP address within 10 seconds, it will enter standby mode.
[0020] In the above scheme, step S2 specifically includes: initiating synchronization requests sequentially according to the preset NTP server pool, calculating time offset and round-trip delay according to the RFC5905 protocol to complete calibration; retrying according to the exponential backoff strategy if synchronization fails, and compensating the local clock based on the local crystal oscillator drift rate; successful NTP synchronization requires that the time offset |θ| ≤ 5 seconds, server stratum ≤ 5, round-trip delay δ ≤ 500ms, and synchronization timeout ≤ 3 seconds, and drift compensation is stopped if synchronization is not achieved for more than 24 hours.
[0021] In the above scheme, the device discovery process in step S3 includes: using a custom UDP broadcast protocol, sending a discovery message carrying the unique identifier of the device once per second for three consecutive times, and the device randomly delays the start of sending and receiving by 0 to 2 seconds to avoid conflicts; if it does not hear the master device announcement, it becomes the master device; if it hears it, it completes the master-slave election according to priority and the dictionary order of the device ID; if the slave device does not receive the master device broadcast for 5 seconds, it is determined to be offline and triggers a re-election.
[0022] In the above scheme, in step S3, the master device maintains the online list of slave devices and the heartbeat mechanism. The slave device sends a heartbeat every 2 seconds. If the master device does not receive a heartbeat for more than 5 seconds, it marks the corresponding slave device as offline and removes it from the list. The offline device can be rebroadcast and added back.
[0023] In the above scheme, in step S4, the brightness of the breathing operation is calculated using a sine curve, an exponential pulse curve, or a triangular wave curve, and a 128-point brightness lookup table is supported. Gamma correction is performed before output. The breathing operation is linked with the charging status, and the breathing cycle and brightness range are matched according to different power ranges. When fully charged, it turns into constant brightness, and the parameters are automatically adjusted in high temperature or discharge mode.
[0024] In the above scheme, step S5 specifically includes: the slave device calculates the phase difference based on the master-slave timestamps and performs surround correction and network latency compensation; a positional PID control algorithm is used to smoothly correct the phase, with PID parameters Kp=0.8-1.2, Ki=0.05-0.2, Kd=0.2-0.5, integral limit |integral|≤0.1, phase difference dead zone |error|<0.005, and the maximum adjustment amount per cycle is limited to ±0.02 seconds.
[0025] In the above scheme, in step S5, the PID parameters are adaptively adjusted according to the breathing cycle. If synchronization fails 5 times in a row, the device enters the local free operation mode and attempts to rediscover the master device every 10 seconds.
[0026] In the above scheme, the mode switching in step S6 is triggered by pressing and holding the button for 2 seconds, UART command, or UDP network command. The master device broadcasts a mode change message, and the slave device synchronously updates the breathing parameters. If the switching fails, the previous mode is rolled back and the log is recorded.
[0027] In the above scheme, the system shutdown in step S6 sequentially executes the following steps: stop the breathing thread, shut down the network, set PWM to 0, release GPIO, and save the running state to non-volatile memory. When the system receives a shutdown, low battery, or over-temperature protection signal, it directly enters the shutdown process and executes the corresponding protection action. When power is lost, the LED is safely shut down by power supply from a large capacitor.
[0028] Example: A method for synchronous gradual change control of charging indicator lights for multiple devices based on NTP time calibration This embodiment uses the ESP32-WROOM-32 as the main control chip, adopts 2.4GHz WiFi local area network communication, and is equipped with a single-channel RGBLED as a charging indicator to build a multi-device synchronous control system consisting of 1 master device and 4 slave devices, so as to realize the charging status indication and the phase of the entire network in a breathing-gradual manner. This embodiment has low hardware cost, high synchronization accuracy, and stable operation, and is suitable for scenarios such as shared charging cabinets, multi-port charging stations, and smart home charging panels.
[0029] 1. System Initialization After the system is powered on, the CPU starts from the reset state and first performs four steps: hardware initialization, network initialization, clock initialization, and configuration loading.
[0030] 1.1 LED Driver Module Initialization: The driving method uses GPIO18 pin in conjunction with the ESP32's built-in LEDC hardware PWM output, without using a dedicated driver chip; the PWM frequency is set to 500Hz, the resolution is 10-bit (0–1023), and the initial duty cycle is 0 (all LEDs are off); after initialization and configuration, the LEDC register status is read to confirm that the duty cycle can be written and read normally. If three consecutive read / write failures occur, the initialization is considered abnormal; the fault indication is that the LED flashes rapidly for 100ms on and 100ms off for 10 seconds. If it still does not recover, the system enters a shutdown protection state; this embodiment uses a single-color warm white LED, with independent control of a single channel. If it is an RGB LED, it can be expanded to three LEDC synchronous outputs.
[0031] 1.2 Network Module Initialization: The network type configuration file specifies net_type="wifi" to connect to a home 2.4GHz wireless router; IP Acquisition: Enable DHCP to automatically obtain an IP address. If a valid IP address is not obtained within 10 seconds, it will directly enter standalone mode, without performing device discovery, and will only use the local clock to run the breathing light; UDP Initialization: Create a UDP socket, bind port 55555, enable broadcast permission, set the send timeout to 1 second, the receive timeout to 0.5 seconds, and TTL=1 to ensure communication only within the same subnet; Network Disconnection Handling: Enable network monitoring. After disconnection, it will reconnect every 5 seconds, with a maximum of 3 retries. If it fails, it will remain in standalone mode, waiting for manual reset or network recovery.
[0032] 1.3 Clock module initialization: Enable the ESP32 built-in RTC and simultaneously enable the esp_timer microsecond-level timer with an accuracy of 1μs to meet the 16ms refresh requirement of the breathing light; when there is no external RTC chip, the system clock starts counting from 0 upon power-on and waits for NTP synchronization before updating the absolute time; after initialization, a system timestamp interface is created for use in breathing calculation, NTP compensation, and synchronization phase calculation.
[0033] 2. NTP network time synchronization After initialization, NTP synchronization is performed immediately to establish a unified time base for the entire network.
[0034] 2.1 NTP Synchronization Process: The server order is pool.ntp.org, ntp.aliyun.com, time.cloudflare.com, time.google.com; the protocol standard is strictly implemented in accordance with RFC5905, sending NTPv4 request messages and parsing the returned timestamps; successful synchronization is determined by simultaneously satisfying the following conditions: time offset |θ|≤5 seconds, server stratum≤5, round-trip delay δ≤500ms, and a valid response is received within 3 seconds of the request.
[0035] 2.2 Retry and Time Compensation: The retry strategy employs exponential backoff, with a 5-second interval for the first failure, 15 seconds for the second, 45 seconds for the third, and every 300 seconds thereafter. Crystal oscillator drift compensation involves recording T_ntp and T_local each time NTP succeeds, calculating the drift rate (drift), and saving it to drift.json. The compensation formula is T_compensated = T_last_sync_ntp + (T_local_now - T_last_sync_local) × (1 + drift). Compensation is stopped after 24 consecutive hours of unsuccessful synchronization to prevent error accumulation.
[0036] 2.3 No network / No NTP processing: Without WiFi, the system timer is used directly for relative time, which only ensures the stability of the local breathing cycle and does not participate in network synchronization; without RTC or NTP, the CPU tick count is used as the time reference, which is only used for phase period calculation and does not provide absolute time.
[0037] 3. Device discovery and master-slave election After NTP synchronization is completed, the device discovery and master-slave role assignment process will be entered automatically.
[0038] 3.1 Device discovery broadcast: The broadcast method is UDP subnet broadcast, the target IP is 192.168.x.255, and the port is 55555; the sending rule is once per second, and three consecutive times to reduce the probability of packet loss; the anti-collision mechanism is to randomly delay 0 to 2 seconds after the device is powered on before starting the broadcast to avoid collisions caused by multiple devices sending at the same time; the deduplication mechanism is based on the packet ID (millisecond-level timestamp) to deduplicate packets, and packets with the same ID within 5 seconds are directly discarded.
[0039] 3.2 Master-Slave Election Rules: If a device listens for 5 seconds and does not receive a master device announcement message, it automatically becomes the master device. If a master device is detected, the lower the priority number, the higher the priority (default is 0). If priorities are the same, the lexicographical order of the MAC address string is compared, and the one with the smaller priority becomes the master device. If the master device goes offline, it is determined that the master device is offline if the slave device does not receive a master device broadcast for 5 seconds, triggering a re-election. For dual-master arbitration, if a message from another master device is received, the priority and MAC are compared. If the local device has a lower priority or a larger ID, it immediately exits master mode and becomes a slave device.
[0040] 3.3 Master Device Management and Heartbeat: The master device maintains the slave device list, supporting a maximum of 256 slave devices; the heartbeat mechanism is that the slave device sends a heartbeat packet every 2 seconds. If the master device does not receive a heartbeat for more than 5 seconds, it marks the slave device as offline and removes it from the list; the re-entry mechanism is that the offline slave device resends the discovery broadcast, and the master device can directly re-join it after verification without restarting.
[0041] 4. Breathing light operation Once the master and slave devices are determined, all devices enter a synchronized breathing operation state, and the brightness is calculated using a unified timestamp.
[0042] 4.1 Brightness Calculation and Smoothing Output: The waveform model uses a sine wave by default and supports a configurable 128-point custom LUT lookup table; the brightness range is min_brightness=10, max_brightness=255. Gamma correction is brightness_out=255×(brightness_in / 255)^2.2, making the human eye perceive a more linear and smooth output; the refresh rate is 60Hz (updating approximately once every 16.7ms), the thread priority is lower than the network synchronization thread, and mutexes are used to protect shared variables such as phase and period.
[0043] 4.2 Linked to charging status: 0%~20% battery level: rapid breathing, cycle 1.0s, brightness 20~255; 20%~80% battery level: normal breathing, cycle 2.0s, brightness 10~255; 80%~99% battery level: slow breathing, cycle 4.0s, brightness 10~200; 100% battery level: constant light, breathing stops; charging temperature >50℃: maximum brightness drops to 150, cycle shortens to 1.5s; discharging (not charging): cycle extends to 5s, minimum brightness drops to 5, enters power saving mode.
[0044] 5. Phase synchronization adjustment The device continuously receives synchronization messages from the master device, quickly achieving complete phase alignment.
[0045] 5.1 Phase difference calculation: The formula is Δphase = phase_master − phase_slave; the surround correction is Δphase > 0.5, then Δphase -= 1.0, and Δphase < -0.5, then Δphase += 1.0; the network delay compensation estimates the one-way delay based on the reception time T4, and compensates the master device phase forward to improve synchronization accuracy.
[0046] 5.2 PID Synchronization Control: PID parameters are Kp=1.0, Ki=0.1, Kd=0.3; protection is set to integral limiting |integral|≤0.1, dead zone |error|<0.005 (no adjustment if phase difference <0.5%), maximum single adjustment ±0.02 seconds to prevent sudden brightness changes; periodic adaptation means that as the breathing cycle increases, Kp and Ki decrease proportionally to ensure synchronization consistency at different speeds. Jitter suppression applies a first-order low-pass filter to the phase difference: error_filtered=0.7×error_last+0.3×error_new.
[0047] 5.3 Synchronization anomaly handling: If the synchronization signal from the master device is not received for 5 consecutive times, the slave device enters local free operation, stops phase correction, and rescans the master device every 10 seconds; after the network is restored, it will automatically resynchronize, and the phase will be quickly aligned within 1 to 2 cycles.
[0048] 6. Mode switching and system shutdown 6.1 Mode Switching: Triggering methods include pressing and holding a button for 2 seconds to switch modes, with 50ms anti-shake functionality; UART commands such as UART commands such as It includes CRC8 verification; UDP broadcasts JSON commands to the master device, and the slave device updates synchronously; if the switch protection parameter is invalid, it automatically rolls back to the previous mode and outputs logs via serial port.
[0049] 6.2 System Shutdown and Protection: The normal shutdown process is as follows: stop the breathing control thread, shut down the UDP service and WiFi, set the PWM output to 0, turn off the LED, release the GPIO, and save the mode, period, phase, offset, role, etc. to state.json; the power failure protection uses a 1000μF large capacitor to provide a backup power of about 50ms. When a power failure interruption is detected, the LED is immediately turned off to avoid abnormal lighting and turning off; the protection trigger directly enters the shutdown process. If the battery voltage is <3.3V, the brightness is limited and network synchronization is stopped; if the voltage is <3.0V, the system shuts down immediately; if the temperature is >70℃, the LED is immediately turned off, while the network alarm function is retained.
[0050] In this embodiment, the indicator lights of the five devices can achieve millisecond-level synchronization with a phase synchronization error of ≤0.5%, smooth breathing without jumps or flickering; they can operate stably on their own when there is no network; the charging status linkage is clear and intuitive, and they have a complete abnormal protection and power failure safety mechanism, which fully meets the engineering requirements for synchronous and gradual control of multi-device charging indicator lights.
[0051] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention.
Claims
1. A method for synchronizing charging indicator lights of multiple devices based on NTP time calibration, characterized in that, Includes the following steps: Step S1: Power on the system and initialize the hardware, network, clock, and configuration files; Step S2: After initialization, perform NTP network time synchronization to obtain a unified time base; Step S3: After NTP synchronization succeeds or fails, the device discovery process is initiated, and the device role is determined through network broadcast and master-slave election; Step S4: The device enters the breathing operation state according to the determined role and performs LED brightness gradual change based on a unified time reference; Step S5: Receive the synchronization signal from the master device from the device, enter synchronization adjustment to correct the breathing phase, and return to breathing operation after phase alignment; Step S6: Respond to the mode switching command to update the breathing gradient parameters, or respond to the shutdown command to perform system shutdown and resource release.
2. The method for synchronous control of multi-device charging indicator lights based on NTP time calibration according to claim 1, characterized in that, Step S1 specifically includes: initializing the LED driver module with PWM, using ordinary GPIO in conjunction with hardware LEDC or TIM timer to drive the LED, setting the PWM operating frequency and initial duty cycle, and completing the GPIO pin multiplexing configuration; initializing the network module, prioritizing WiFi or Ethernet connection, obtaining a valid IP address via DHCP or static method, establishing a UDP socket and enabling the broadcast option; initializing the clock module, enabling hardware RTC or system tick timer, and establishing a system time base with microsecond-level precision; if the LED driver initialization fails, it will quickly blink 100ms on / 100ms off to report an error, and if the network fails to obtain an IP address within 10 seconds, it will enter standby mode.
3. The method for synchronous control of multi-device charging indicator lights based on NTP time calibration according to claim 1, characterized in that, Step S2 specifically includes: initiating synchronization requests sequentially according to the preset NTP server pool, calculating time offset and round-trip delay according to the RFC5905 protocol to complete calibration; retrying according to the exponential backoff strategy if synchronization fails, and compensating the local clock based on the local crystal oscillator drift rate; successful NTP synchronization requires that the time offset |θ| ≤ 5 seconds, server stratum ≤ 5, round-trip delay δ ≤ 500ms, and synchronization timeout ≤ 3 seconds, and drift compensation is stopped if synchronization is not achieved for more than 24 hours.
4. The method for synchronous control of multi-device charging indicator lights based on NTP time calibration according to claim 1, characterized in that, The device discovery process in step S3 includes: using a custom UDP broadcast protocol, sending a discovery message carrying the unique identifier of the device once per second for three consecutive times, with the device randomly delayed by 0 to 2 seconds to start sending and receiving to avoid conflicts; if it does not hear the master device announcement, it becomes the master device; if it does hear it, it completes the master-slave election according to priority and the dictionary order of the device ID; if the slave device does not receive the master device broadcast for 5 seconds, it is determined to be offline and triggers a re-election.
5. The method for synchronous control of multi-device charging indicator lights based on NTP time calibration according to claim 4, characterized in that, In step S3, the master device maintains the online list of slave devices and the heartbeat mechanism. The slave device sends a heartbeat every 2 seconds. If the master device does not receive a heartbeat for more than 5 seconds, it marks the corresponding slave device as offline and removes it from the list. Offline devices can be rebroadcast and added back.
6. The method for synchronous control of multi-device charging indicator lights based on NTP time calibration according to claim 1, characterized in that, In step S4, the respiratory operation brightness is calculated using a sine curve, an exponential pulse curve, or a triangular wave curve, and a 128-point brightness lookup table is supported. Gamma correction is performed before output. The breathing operation is linked to the charging status, matching the breathing cycle and brightness range according to different power ranges. When fully charged, it turns into constant light, and the parameters are automatically adjusted in high temperature or discharge mode.
7. The method for synchronous control of multi-device charging indicator lights based on NTP time calibration according to claim 1, characterized in that, Step S5 specifically includes: the slave device calculates the phase difference based on the master-slave timestamps and performs surround correction and network latency compensation; a positional PID control algorithm is used to smoothly correct the phase, with PID parameters Kp=0.8-1.2, Ki=0.05-0.2, Kd=0.2-0.5, integral limit |integral|≤0.1, phase difference dead zone |error|<0.005, and the maximum adjustment amount per cycle is limited to ±0.02 seconds.
8. The method for synchronous control of multi-device charging indicator lights based on NTP time calibration according to claim 7, characterized in that, In step S5, the PID parameters are adaptively adjusted according to the breathing cycle. If synchronization fails 5 times in a row, the device enters the local free operation mode and attempts to rediscover the master device every 10 seconds.
9. The method for synchronous control of multi-device charging indicator lights based on NTP time calibration according to claim 1, characterized in that, The mode switching in step S6 is triggered by pressing and holding a button for 2 seconds, a UART command, or a UDP network command. The master device broadcasts a mode change message, and the slave device synchronously updates the breathing parameters. If the switching fails, the previous mode is rolled back and the log is recorded.
10. The method for synchronous control of multi-device charging indicator lights based on NTP time calibration according to claim 1, characterized in that, In step S6, the system shutdown process sequentially executes the following steps: stopping the breathing thread, shutting down the network, setting the PWM to 0, releasing the GPIO, and saving the running state to non-volatile memory. When the system receives a shutdown, low battery, or over-temperature protection signal, it directly enters the shutdown process and executes the corresponding protection action. In the event of a power failure, the LED is safely shut down by power supply from the large capacitor.