ESP-Brookesia SNTP Service
Overview
brookesia_service_sntp is an SNTP (Simple Network Time Protocol) service for the ESP-Brookesia ecosystem, providing:
- NTP Server Management: Supports configuring multiple NTP servers and automatically selects available servers from the server list for time synchronization
- Timezone Settings: Supports setting system timezone and automatically applies timezone offset
- Automatic Time Synchronization: Automatically detects network connection status and starts time synchronization when network is available
- Status Query: Supports querying time synchronization status, currently configured server list, and timezone information
- Persistent Storage: Optionally works with
brookesia_service_nvsservice to persistently save NTP server list and timezone information
Table of Contents
Features
NTP Server Management
The SNTP service supports configuring multiple NTP servers:
- Default Server: Uses
"pool.ntp.org"as the default NTP server - Multiple Server Support: Can configure multiple NTP servers, and the service will automatically select available servers
- Server List: Supports getting the list of all currently configured NTP servers
Timezone Settings
The SNTP service supports setting system timezone:
- Default Timezone: Default timezone is
"CST-8"(China Standard Time, UTC+8) - Timezone Format: Supports standard timezone string formats (such as
"UTC","CST-8","EST-5", etc.) - Automatic Application: Automatically applies to system time after setting timezone
Core Functions
- Set NTP Servers: Supports setting one or multiple NTP servers
- Set Timezone: Supports setting system timezone
- Start Service: Starts the SNTP service and begins time synchronization
- Stop Service: Stops the SNTP service and stops time synchronization
- Get Server List: Gets the list of currently configured NTP servers
- Get Timezone: Gets the currently configured timezone
- Check Sync Status: Checks whether system time has been synchronized with NTP servers
- Reset Data: Resets all configuration data to default values
Automatic Management
- Automatic Configuration Loading: Automatically loads saved configuration from NVS when service starts
- Automatic Configuration Saving: Automatically saves configuration to NVS after configuration changes
- Network Detection: Automatically detects network connection status and starts time synchronization when network is available
- Status Monitoring: Automatically monitors time synchronization status and updates sync flag
Development Environment Requirements
Before using this library, please ensure the following SDK development environment is installed:
- ESP-IDF:
>=5.5,<6
Note
For SDK installation instructions, please refer to ESP-IDF Programming Guide - Installation
Adding to Project
brookesia_service_sntp has been uploaded to the Espressif Component Registry. You can add it to your project in the following ways:
-
Using Command Line
Run the following command in your project directory:
idf.py add-dependency "espressif/brookesia_service_sntp" -
Modify Configuration File
Create or modify the idf_component.yml file in your project directory:
dependencies: espressif/brookesia_service_sntp: "*"
For detailed instructions, please refer to Espressif Documentation - IDF Component Manager.