0

My understanding of the CSA Matter (aka project CHIP) spec (11.16) seems to indicate that nodes on the Matter fabric will sync the current time using the TimeSync cluster service.

If true, it seems like there should be a way to use Matter to get the current real time from within my app code. The Matter SDK includes various headers and functions for dealing with time. SystemClock().GetClock_RealTime() seems promising, but when I call it I only seem to get the number of microseconds since device boot rather than the real time. ToTimeval() in the same header also seems promising to convert to a timeval, but that declaration is not defined on ESP32, at least on my version.

I'm using the jakubdybczak/esp32-arduino-matter Arduino port of the Espressif Matter SDK.

I also tried accessing the time service on Node 0, but the returned attribute is always null:

  endpoint_t *root_endpoint = endpoint::get(node,0);
  esp_matter::cluster_t *time_cluster = cluster::create(root_endpoint,TimeSynchronization::Id, CLUSTER_FLAG_CLIENT);
  // in this example I'm looking at timezone, but the same thing happens for LocalTime::Id
  attribute_t *timezone_attribute = attribute::get(time_cluster,TimeSynchronization::Attributes::TimeZone::Id); // always NULL
  esp_matter_attr_val_t timezone_value = esp_matter_invalid(NULL);
  attribute::get_val(timezone_attribute, &timezone_value);

What is the proper way to use Matter to get the current real time?

Tarlog
  • 10,024
  • 2
  • 43
  • 67
emmby
  • 99,783
  • 65
  • 191
  • 249
  • The system clock is a monotonic clock, it won't be adjust by the calendar time. The calendar implementation is heavily depends on the platform, I'm not clear whether the your platform supports calendar time. You can check whether your platform have defined MBEDTLS_HAVE_TIME_DATE, and if it is set, try following the code to find where time is stored. – Zang MingJie Feb 16 '23 at 08:08
  • Thank you for your note. This suggestion seems to be independent of Matter, is that right? I'm looking for a solution that gets the time from Matter. – emmby Feb 16 '23 at 17:01

1 Answers1

0

You can try making use of the NTP protocol to keep track of the current date and time. Also, you can refer to the time synchronization cluster in the matter specification documentation for understanding the mechanism how the nodes try to achieve and maintain time synchronization.

There are also a bunch of implementation guidance that can be found here.