51 lines
1.3 KiB
C
51 lines
1.3 KiB
C
#pragma once
|
|
|
|
#include "esp_err.h"
|
|
|
|
/**
|
|
* Initialize SNTP time synchronization.
|
|
* Should be called after WiFi is connected.
|
|
* Automatically applies timezone from NVS and loads custom NTP server from NVS.
|
|
*/
|
|
esp_err_t time_sync_init(void);
|
|
|
|
/**
|
|
* Get current SNTP sync status.
|
|
* @return true if time has been synchronized, false otherwise
|
|
*/
|
|
bool time_sync_is_synced(void);
|
|
|
|
/**
|
|
* Get a human-readable sync status string.
|
|
* @return "synced", "syncing", or "not_synced"
|
|
*/
|
|
const char *time_sync_status_str(void);
|
|
|
|
/**
|
|
* Get the last synchronized time as a formatted string.
|
|
* @param out buffer to write the formatted time string
|
|
* @param out_size size of the output buffer
|
|
* @return true if a sync time is recorded, false otherwise
|
|
*/
|
|
bool time_sync_get_last_synced(char *out, size_t out_size);
|
|
|
|
/**
|
|
* Get the current NTP server (custom from NVS or default).
|
|
* @return NTP server hostname
|
|
*/
|
|
const char *time_sync_get_server(void);
|
|
|
|
/**
|
|
* Set a custom NTP server and save to NVS.
|
|
* Takes effect on next time_sync_init() or time_sync_restart().
|
|
* @param server NTP server hostname
|
|
* @return ESP_OK on success
|
|
*/
|
|
esp_err_t time_sync_set_server(const char *server);
|
|
|
|
/**
|
|
* Restart SNTP with the current server configuration.
|
|
* Useful for applying a newly set NTP server without rebooting.
|
|
*/
|
|
esp_err_t time_sync_restart(void);
|