2#if defined(USE_ZIGBEE) && defined(USE_ESP32) && defined(USE_TIME)
8static const char *
const TAG =
"zigbee.time";
26 ezb_zcl_time_interface_t time_interface = {
31 if (!esp_zigbee_lock_acquire(10 / portTICK_PERIOD_MS)) {
35 ret = ezb_zcl_time_server_interface_register(this->
endpoint_, time_interface);
36 esp_zigbee_lock_release();
37 if (
ret != EZB_ERR_NONE) {
38 ESP_LOGW(TAG,
"Setup failed: %d",
ret);
50 if (
status == EZB_ERR_NONE) {
51 ESP_LOGV(TAG,
"Time synchronization successful");
52 }
else if (
status == EZB_ERR_TIMEOUT) {
53 ESP_LOGW(TAG,
"Time synchronization timed out");
55 ESP_LOGW(TAG,
"Time synchronization failed with error: %d",
status);
61 if (esp_zigbee_lock_acquire(10 / portTICK_PERIOD_MS)) {
62 ESP_LOGV(TAG,
"Updating time sync from Zigbee network...");
64 EZB_ZCL_TIME_SERVER_RANK_MASTER);
65 esp_zigbee_lock_release();
69 ESP_LOGW(TAG,
"Could not acquire Zigbee lock to synchronize time, will retry maximum 3 times");
75 ESP_LOGW(TAG,
"Could not acquire Zigbee lock to synchronize time");
80 ESP_LOGD(TAG,
"Not connected to Zigbee network, cannot synchronize time");
94 if (utc <= (std::numeric_limits<uint32_t>::max() -
EPOCH_2000)) {
101 this->
defer([
this, utc]() {
102 ESP_LOGV(TAG,
"Setting device time to UTC: %u",
static_cast<unsigned>(utc));
113 RealTimeClock::dump_config();
void wake_loop_threadsafe()
Wake the main event loop from another thread or callback.
void mark_failed()
Mark this component as failed.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void defer(const char *name, std::function< void()> &&f)
Defer a callback to the next loop() call with a const char* name.
time_t timestamp_now()
Get the current time as the UTC epoch since January 1st 1970.
ESPTime now()
Get the time in the currently defined timezone.
void synchronize_epoch_(uint32_t epoch)
Report a unix epoch as current time.
void add_on_start_callback(F &&cb)
void add_on_join_callback(F &&cb)
void set_epoch_time(uint32_t utc)
static void status_cb(ezb_err_t status)
ZigbeeComponent * parent_
static void set_utc_time(uint32_t utc)
static uint32_t get_utc_time()
void dump_config() override
constexpr time_t EPOCH_2000
Application App
Global storage of Application pointer - only one Application can exist.