Time Handling#

The Zigbee Application Framework provides a single API for accessing the current time on the system, int32u sl_zigbee_af_get_current_time(), which is described in app/framework/util/time-util.h. This section describes how the function is implemented in app/framework/util/time-util.c.

If the ZCL time cluster server is implemented on the system, then this function retrieves the time from the server through the function call int32u sli_zigbee_af_time_cluster_server_set_current_time(). In this case, the time is read from the time cluster server’s time attribute and returned. If the time cluster server is not implemented, then sl_zigbee_af_get_current_time calls sl_zigbee_af_get_current_time_cb.

If your device needs to know the current time but does not implement the time cluster server component, it is responsible for maintaining its own time somewhere on the system and returning that time through the sl_zigbee_af_get_current_time_cb when it is requested. This is especially important for SE devices that do not implement the time cluster server like an In-Premise Display (IPD). Essentially the IPD is on its own when it comes to time management. It would be outside the ZCL specification (as currently interpreted) for a non-Energy Service Portal to implement the time cluster server. Therefore, the IPD must maintain its own knowledge of time and provide it to the Zigbee Application Framework when requested through the sl_zigbee_af_get_current_time_cb.

If your application includes the time cluster server, the time cluster server code always tries to initialize and update the time server’s time attribute through the sl_zigbee_af_get_current_time_cb. If the sl_zigbee_af_get_current_time_cb returns 0, then the time cluster server increments the stored attribute once per second. Thus, you can use the time cluster server to store and maintain real time on the system without implementing the sl_zigbee_af_get_current_time_cb, if the actual time value can be synced from another device on the system and written into the time server’s time attribute. For more information on how time is handled by the bundled implementation of the time cluster server, see app/framework/plugin/time-server/time-server.c.