Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to use TimeSynchronizationCluster (CON-1501) #1233

Open
bnadim opened this issue Jan 7, 2025 · 8 comments
Open

Trying to use TimeSynchronizationCluster (CON-1501) #1233

bnadim opened this issue Jan 7, 2025 · 8 comments

Comments

@bnadim
Copy link

bnadim commented Jan 7, 2025

Describe the question/query that you have
Hi, i am currently trying to use the TimeSynchronizationCluster to get time.
I am using a device connected to a HomePod which should support time synchronization.

So far i have tried to add this code based on light switch example:

#ifdef CONFIG_ENABLE_SNTP_TIME_SYNC
    endpoint_t *root_node_ep = endpoint::get_first(node);
    ABORT_APP_ON_FAILURE(root_node_ep != nullptr, ESP_LOGE(TAG, "Failed to find root node endpoint"));

    cluster::time_synchronization::config_t time_sync_cfg;
    static chip::app::Clusters::TimeSynchronization::DefaultTimeSyncDelegate time_sync_delegate;
    time_sync_cfg.delegate = &time_sync_delegate;
    time_sync_cluster = cluster::time_synchronization::create(root_node_ep, &time_sync_cfg, CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT);
    ABORT_APP_ON_FAILURE(time_sync_cluster != nullptr, ESP_LOGE(TAG, "Failed to create time_sync_cluster"));

    cluster::time_synchronization::feature::time_sync_client::add(time_sync_cluster);
    /*cluster::time_synchronization::feature::time_zone::config_t tz_cfg;
    cluster::time_synchronization::feature::time_zone::add(time_sync_cluster, &tz_cfg);*/
#endif

And i try to read the value using:

attribute_t *utc_time = attribute::get(time_sync_cluster,TimeSynchronization::Attributes::UTCTime::Id);
    if (utc_time == nullptr) {
        ESP_LOGI(TAG, "utc_time attribute is null");
    } else {
        esp_matter_attr_val_t val = esp_matter_invalid(nullptr);
        attribute::get_val(utc_time, &val);

        ESP_LOGI(TAG, "TIME IS: %lli", val.val.u64);
    }

which throw an error esp_matter_core: get_val(1144): Attribute is not managed by esp matter data model

So i am pretty sure i am not using properly.
I wanted to use CLUSTER_FLAG_CLIENT flag only on the cluster, but i saw in code that it doesn't create in this case utc_time and granularity attributes which are mandatory based on matter spec 1.3.

Who can i get synchronized time ? I think it's missing an example.

Thank you for your kind help.

Additional context
...

@github-actions github-actions bot changed the title Trying to use TimeSynchronizationCluster Trying to use TimeSynchronizationCluster (CON-1501) Jan 7, 2025
@wqx6
Copy link
Contributor

wqx6 commented Jan 8, 2025

The UTCTime attribute is managed by AttributeAccessInterface instead of esp-matter data model so you cannot get its value with the APIs provided in esp-matter component, Please refer to this, the unix UTC time can be get System::SystemClock().GetClock_RealTime().

@bnadim
Copy link
Author

bnadim commented Jan 10, 2025

Hey wqx6,

Thank you for you feedback. I tried, but my time doesn't get synced. I can't find what i am missing. Do you have a "full example" please ? I believe it would make a very good example.
Thank you very much for your help.

Regards

@jonsmirl
Copy link
Contributor

Using this cluster is very painful. Just turn on the standard NTP client via menuconfig which is 1000 times easier.

@wqx6
Copy link
Contributor

wqx6 commented Jan 16, 2025

Thank you for you feedback. I tried, but my time doesn't get synced. I can't find what i am missing. Do you have a "full example" please ? I believe it would make a very good example.
Thank you very much for your help.

What commissioner are you using? I tested the time-sync cluster with the following steps:

  • Commission the device with chip-tool and then open a commissioning window.
  • Use Apple home app to commission the device, the Apple home app will set the UTC time and time zone during commissioning
  • Read the UTC time with chip-tool.

@bnadim
Copy link
Author

bnadim commented Jan 17, 2025

Hey,

thank you for your feedback. @wqx6 indeed i finally managed to get time at commissioning. My issue is after restart i lose time and i didn't find to request it unless i recommission the device. Apple set the utc time at commissioning but not trusted source.
Do you have any idea on how to "continuously" sync with an apple device ?

@jonsmirl i tried standard ntp, but it doesn't get sync if connected to thread/matter network of apple. I juste get timeouts. Have you done it with apple ?

Thank you

@jonsmirl
Copy link
Contributor

jonsmirl commented Jan 18, 2025

Standard NTP will ignore Matter and use the existing NTP protocol. Use pool.ntp.org which will attach to the nearest public server. Of course this only works from a network with Internet connectivity. If you have an Apple Home device you have to have Internet connectivity since it also needs it.

This might be a thread problem, does thread route onto the Internet by default? For sure it is possible for Thread to route onto the Internet but I don't know if that is capability is turned on. All of the Matter devices I work with are wifi based.

@jonsmirl
Copy link
Contributor

jonsmirl commented Jan 18, 2025

Since thread is IPv6 only I believe you need to use 2.pool.ntp.org or time.google.com. pool.ntp.org is timing out because it does not support IPv6 clients.

jonsmirl@ares:~$ nslookup pool.ntp.org
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
Name:	pool.ntp.org
Address: 38.81.211.177
Name:	pool.ntp.org
Address: 172.235.32.243
Name:	pool.ntp.org
Address: 198.60.22.240
Name:	pool.ntp.org
Address: 107.172.16.131

jonsmirl@ares:~$ nslookup 2.pool.ntp.org
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
Name:	2.pool.ntp.org
Address: 173.71.68.71
Name:	2.pool.ntp.org
Address: 66.244.16.123
Name:	2.pool.ntp.org
Address: 74.208.72.129
Name:	2.pool.ntp.org
Address: 69.164.213.136
Name:	2.pool.ntp.org
Address: 2606:82c0:21::e
Name:	2.pool.ntp.org
Address: 2600:1700:3d24:740f:9524:529a:6489:d48f
Name:	2.pool.ntp.org
Address: 2001:470:e8dc:10::123
Name:	2.pool.ntp.org
Address: 2600:4040:e0da:f000::cbb9:201a

jonsmirl@ares:~$ nslookup time.google.com
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
Name:	time.google.com
Address: 216.239.35.12
Name:	time.google.com
Address: 216.239.35.8
Name:	time.google.com
Address: 216.239.35.0
Name:	time.google.com
Address: 216.239.35.4
Name:	time.google.com
Address: 2001:4860:4806:c::
Name:	time.google.com
Address: 2001:4860:4806:4::
Name:	time.google.com
Address: 2001:4860:4806::
Name:	time.google.com
Address: 2001:4860:4806:8::

@caipiblack
Copy link

caipiblack commented Feb 6, 2025

Hello,

If you need help to use the time synchronization cluster, take a look here: #1269

I made it working.

There is just a little bug but it is not very important:

  • Most of the logs display the correct date/time
  • One line of logs display the wrong date/time
  • In the code when I use chip::System::SystemClock().GetClock_RealTime() i get the correct time (this is the most important).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants