Add time synchronization example for ESP32#103
Merged
IvanArkhipov1999 merged 33 commits intomainfrom Oct 8, 2025
Merged
Conversation
- Introduced a new `time-sync` example demonstrating time synchronization using ESP-NOW. - Updated GitHub Actions workflow to include tests for the new example. - Added necessary configuration files and README documentation for the example. - Implemented core synchronization logic in the `time_sync` module, including dynamic time adjustment and peer management. - Added tests for the synchronization algorithm and overall time synchronization functionality.
…modules - Rearranged import statements for consistency across `time_sync` and `timer` modules. - Enhanced code readability by adjusting formatting and spacing in various functions. - Ensured that the `timer` module is now consistently included in the library structure. - Cleaned up unnecessary whitespace in multiple files to adhere to coding standards.
- Upgraded `esp-backtrace` to version 0.14.1 with additional features for ESP32 support. - Updated `esp-println` to version 0.11.0 to enhance printing capabilities. - Introduced a new `[features]` section to manage default features for the example, improving modularity and configuration.
…ests - Simplified the initialization of the sync algorithm in `TimeSyncManager`. - Updated methods for handling sync requests, responses, and broadcasts to use `_message` parameters, indicating unimplemented functionality. - Refactored the `send_periodic_sync_requests` method to streamline message processing. - Enhanced the `EspNow` mock implementation for better testing and compatibility with the network feature. - Adjusted tests to verify peer quality management and synchronization workflow without crashing.
…stency - Enhanced formatting and spacing in `TimeSyncManager` and `EspNow` implementations for better code clarity. - Adjusted function signatures in the `utils` module to improve readability. - Removed unnecessary whitespace to adhere to coding standards across multiple files.
…djustments - Updated `Cargo.toml` to include `esp-wifi` and `static_cell` dependencies, enhancing functionality for ESP32. - Modified type definitions in `main.rs` and `time_sync.rs` to use `u32` instead of `u64` for time-related variables, improving compatibility and reducing memory usage. - Refactored `EspNow` and `TimeSyncManager` structures to support the new type definitions, ensuring consistency across the synchronization logic.
- Added the "esp32" feature to the `esp-wifi` dependency in `Cargo.toml` to enhance compatibility. - Updated the linker flags in `.cargo/config.toml` to use `-Trom_functions.x`, improving the build configuration for the ESP32 target.
…example - Rearranged import statements in `main.rs` for better organization and consistency. - Enhanced code readability by adjusting formatting and removing unnecessary whitespace. - Updated comments for clarity and improved documentation within the example.
- Added "cfg-if" as a dependency in `Cargo.lock` to support conditional compilation. - Initialized `sync_offset_us` in the `Timer` structure within `c_api.rs` to ensure proper timer functionality.
- Updated the `get_synchronized_time` method in `timer.rs` to use `unsigned_abs()` for better clarity and correctness in handling sync offsets. - Removed outdated test files for time synchronization algorithms and time sync tests, streamlining the test suite and focusing on current implementations.
…s by removing unused system initialization code. This streamlines the workflow and improves code clarity in the time synchronization example.
…process and focus on relevant tests.
- Introduced a new `time-sync` example demonstrating time synchronization using ESP-NOW. - Created `Cargo.toml`, `README.md`, and necessary configuration files for the example. - Implemented main synchronization logic in `main.rs`, including setup, loop, and statistics reporting. - Configured build settings in `.cargo/config.toml` for RISC-V target compatibility. - Added detailed documentation in `README.md` outlining features, usage, and troubleshooting steps.
- Updated `main.rs` to streamline the setup and loop functions, enhancing clarity and organization. - Removed unused timer logic and global variables, simplifying the synchronization process. - Improved handling of ESP-NOW messages, including peer management and broadcast requests. - Enhanced `TimeSyncManager` to expose the `esp_now_protocol` for better integration. - Added detailed comments for improved documentation and understanding of the synchronization flow.
- Simplified the handling of broadcast messages in `main.rs` for both ESP32 and ESP32-C6. - Removed peer management and response sending logic, focusing solely on receiving broadcast messages. - Enhanced logging to provide clearer output of received messages and their source addresses.
- Improved message handling in `main.rs` to include parsing and processing of `SyncMessage` for time synchronization. - Added detailed logging for received messages and synchronization processing, enhancing visibility into the synchronization flow. - Streamlined the broadcast message sending logic to create and send `SyncMessage` with the current time, ensuring accurate synchronization requests. - Updated comments for clarity and better understanding of the synchronization process.
- Removed redundant logging statements in `main.rs` for both ESP32 and ESP32-C6 to streamline output. - Simplified the processing of received messages and synchronization logic, enhancing code clarity. - Updated comments to reflect changes and improve understanding of the synchronization flow.
- Updated synchronization configuration parameters to allow for higher correction thresholds and acceleration factors, improving responsiveness. - Refined message handling in `main.rs` to include corrected time calculations and detailed logging of time differences, enhancing visibility into synchronization accuracy. - Implemented Local Voting Protocol for time correction, allowing for more stable synchronization by adjusting time offsets based on peer feedback. - Improved peer management in `TimeSyncManager`, ensuring accurate tracking of synchronization quality and adjustments based on received messages.
- Streamlined message handling in `main.rs` by consolidating synchronization logic and improving logging for received timestamps and offsets. - Removed redundant comments and unnecessary sequence number validation in the ESP-NOW protocol. - Simplified the `TimeSyncManager` by eliminating unused methods and variables, enhancing code clarity and maintainability. - Updated synchronization algorithm to focus on essential calculations, improving overall performance and readability.
- Added comprehensive documentation to `main.rs` for both ESP32 and ESP32-C6 time synchronization examples, detailing the Local Voting Protocol and its implementation. - Improved comments throughout the code to clarify the setup, loop, and synchronization processes, enhancing code readability and maintainability. - Updated the `TimeSyncManager` and synchronization algorithm to better reflect the functionality and configuration options available for users. - Streamlined the handling of synchronization messages and peer management, ensuring a more robust and user-friendly experience.
- Improved code organization by rearranging imports and enhancing readability in `main.rs`. - Streamlined message handling and logging for synchronization processes, ensuring clearer output and better tracking of time differences. - Updated comments throughout the code to clarify functionality and improve maintainability. - Enhanced the `TimeSyncManager` and synchronization algorithm to better reflect the current implementation and configuration options.
- Enhanced README.md files for both ESP32 and ESP32-C6 examples to clarify the implementation of the Local Voting Protocol and its features. - Updated synchronization parameters, including sync interval and correction thresholds, to reflect improved performance and responsiveness. - Added cross-platform compatibility details, ensuring users understand the seamless operation between ESP32 and ESP32-C6. - Improved usage instructions and expected output sections for better clarity on synchronization processes and monitoring.
- Translated comments in `main.rs` from Russian to English for better accessibility and understanding. - Enhanced clarity of the synchronization process by improving comment descriptions throughout the code. - Maintained existing functionality while ensuring that the code remains comprehensible for a wider audience.
…ation. Update table of contents to reflect changes and improve organization of content.
…examples - Changed the synchronization message broadcast interval from 2000ms to 500ms in `main.rs` for both ESP32 and ESP32-C6. - Updated documentation to reflect the new synchronization interval in the `SyncConfig` and related comments. - Ensured consistency across examples by aligning the synchronization parameters and message transmission frequency.
…examples - Changed the synchronization message broadcast interval from 500ms to 100ms in `main.rs` for both ESP32 and ESP32-C6. - Updated documentation to reflect the new synchronization interval in the `SyncConfig` and related comments. - Ensured consistency across examples by aligning the synchronization parameters and message transmission frequency.
…xamples - Updated the synchronization message broadcast interval from 100ms to 10ms in `main.rs` for both ESP32 and ESP32-C6. - Adjusted the `sync_interval_ms` parameter in the `SyncConfig` to reflect the new interval. - Ensured consistency in timing across both examples to enhance responsiveness in time synchronization.
- Removed the `node_id` parameter from `SyncConfig` and `SyncPeer`, as peer management is no longer required in broadcast-only mode. - Updated synchronization message handling to eliminate source and target node IDs, simplifying the `SyncMessage` structure. - Adjusted documentation and examples to reflect the changes in peer management and configuration, ensuring clarity for users. - Enhanced the `TimeSyncManager` and related components to support the new broadcast-only functionality, improving overall code maintainability.
- Reformatted the `SyncMessage` struct initialization for better clarity and consistency. - Simplified the `send` and `receive` methods in the `EspNow` implementation to enhance code readability. - Updated the `get_local_mac` method to follow consistent formatting, improving overall code maintainability.
…dress parameter - Eliminated the local MAC address parameter from the `init_esp_now_protocol` method in `TimeSyncManager` and related components, simplifying the ESP-NOW protocol initialization. - Removed unused synchronization response message handling and related methods to streamline the codebase. - Updated synchronization message types and adjusted the `SyncMessage` structure to focus on broadcast functionality, enhancing clarity and maintainability.
…onfiguration values - Revised synchronization parameters in documentation to reflect updated default values: sync interval (500ms), max correction (1000μs), acceleration factor (0.1), and deceleration factor (0.05). - Simplified example code by initializing `TimeSyncManager` with default configuration instead of custom settings. - Updated comments and monitoring sections to enhance clarity on synchronization quality and offset reporting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
time-syncexample demonstrating time synchronization using ESP-NOW.time_syncmodule, including dynamic time adjustment and peer management.