Accessing Attributes
This section describes the processes of reading and writing cluster attributes on a remote node. For the attribute access function descriptions, refer to Section 5.2.
Attribute Access Permissions
For each attribute of a cluster, access permissions should be defined for the different types of access to the attribute. These permissions are configured using control flags, with one flag for each access type, as follows:
Access Type |
Flag |
Description |
---|---|---|
Read |
E_ZCL_AF_RD |
Global commands can read the attribute value |
Write |
E_ZCL_AF_WR |
Global commands can write a new value to the attribute |
Report |
E_ZCL_AF_RP |
Global commands can report the value of the attribute or configure the attribute for default reporting |
Scene |
E_ZCL_AF_SE |
The attribute can be accessed through a scene (if the Scenes cluster is implemented on the same endpoint) |
If a particular access type is required for an individual attribute, the corresponding flag must be defined for that attribute. This is done in the C header file for the cluster. For example, in the case of the On/Off cluster, the required flags must be defined for each attribute in the following structure in the OnOff.c file:
const tsZCL_AttributeDefinition asCLD_OnOffClusterAttributeDefinitions[] = {
#ifdef ONOFF_SERVER
{E_CLD_ONOFF_ATTR_ID_ONOFF, (E_ZCL_AF_RD|E_ZCL_AF_SE|E_ZCL_AF_RP), E_ZCL_BOOL,
(uint32)(&((tsCLD_OnOff*)(0))->bOnOff),0}, /* Mandatory */
#ifdef CLD_ONOFF_ATTR_GLOBAL_SCENE_CONTROL
{E_CLD_ONOFF_ATTR_ID_GLOBAL_SCENE_CONTROL, (E_ZCL_AF_RD), _ZCL_BOOL,
(uint32)(&((tsCLD_OnOff*)(0))->bGlobalSceneControl),0}, /* Optional */
#endif
#ifdef CLD_ONOFF_ATTR_ON_TIME
{E_CLD_ONOFF_ATTR_ID_ON_TIME, E_ZCL_AF_RD|E_ZCL_AF_WR), E_ZCL_UINT16,
(uint32)(&((tsCLD_OnOff*)(0))->u16OnTime),0}, /* Optional */
#endif
#ifdef CLD_ONOFF_ATTR_OFF_WAIT_TIME
{E_CLD_ONOFF_ATTR_ID_OFF_WAIT_TIME, (E_ZCL_AF_RD|E_ZCL_AF_WR), E_ZCL_UINT16,
(uint32)(&((tsCLD_OnOff*)(0))->u16OffWaitTime),0}, /* Optional */
#endif
#ifdef CLD_ONOFF_ATTR_STARTUP_ONOFF
/* ZLO extension for OnOff Cluster */
{E_CLD_ONOFF_ATTR_ID_STARTUP_ONOFF, E_ZCL_AF_RD|E_ZCL_AF_WR), E_ZCL_ENUM8,
(uint32)(&((tsCLD_OnOff*)(0))->eStartUpOnOff),0}, /* Optional */
#endif
#endif
{E_CLD_GLOBAL_ATTR_ID_CLUSTER_REVISION, (E_ZCL_AF_RD|E_ZCL_AF_GA), E_ZCL_UINT16,
(uint32)(&((tsCLD_OnOff*)(0))->u16ClusterRevision),0}, /* Mandatory */
#if (defined ONOFF_SERVER) && (defined CLD_ONOFF_ATTR_ATTRIBUTE_REPORTING_STATUS)
{E_CLD_GLOBAL_ATTR_ID_ATTRIBUTE_REPORTING_STATUS,(E_ZCL_AF_RD|E_ZCL_AF_GA), E_ZCL_ENUM8,
(uint32)(&((tsCLD_OnOff*)(0))->u8AttributeReportingStatus),0}, /* Optional */
#endif
};
Note: The flag E_ZCL_AF_GA indicates a global attribute.
Parent topic:Accessing Attributes
Reading Attributes
A ZigBee 3.0 application might require to read attribute values from a remote device. Attributes are read by sending a ‘read attributes’ request, normally from a client cluster to a server cluster. This request can be sent using a general ZCL function (see below) or using a function which is specific to the target cluster. The cluster-specific functions for reading attributes are covered in the chapters of this manual that describe the supported clusters.
Note: Users should enable read access to cluster attributes explicitly at compile-time as described in Section 1.3.
A ZCL function is provided for reading a set of attributes of a remote cluster instance, as described in Section 2.3.2.1. A function is also provided for reading a local cluster attribute value, as described in Section 2.3.2.2.
Reading a set of attributes of a remote cluster
This section describes the use of the function eZCL_SendReadAttributesRequest() to send a ‘read attributes’ request to a remote cluster in order to obtain the values of selected attributes. The resulting activities on the source and destination nodes are outlined below and illustrated in the figure ‘Write Attributes’ Request and Response below. The events generated from a ‘read attributes’ request are further described in Chapter 3.
Note: The described sequence is similar when using the cluster-specific ‘read attributes’ functions.
1. On Source Node
The function eZCL_SendReadAttributesRequest() is called to submit a request to read one or more attributes on a cluster on a remote node. The information required by this function includes the following:
Source endpoint (from which the read request is to be sent)
Address of destination node for request
Destination endpoint (on destination node)
Identifier of the cluster containing the attributes [enumerations provided]
Number of attributes to be read
Array of identifiers of attributes to be read [enumerations provided]
2. On Destination Node
On receiving the ‘read attributes’ request, the ZCL software on the destination node performs the following steps:
Generates an
E_ZCL_CBET_READ_REQUEST
event for the destination endpoint callback function which, if required, can update the shared device structure that contains the attributes to be read, before the read takes place.If tasks within the application are not cooperative, the ZCL generates an
E_ZCL_CBET_LOCK_MUTEX
event for the endpoint callback function, which should lock the mutex that protects the shared device structure - for information on mutexes, refer to Appendix A.Reads the relevant attribute values from the shared device structure and creates a ‘read attributes’ response message containing the read values.
If tasks within the application are not cooperative, the ZCL generates an
E_ZCL_CBET_UNLOCK_MUTEX
event for the endpoint callback function, which should now unlock the mutex that protects the shared device structure (other application tasks can now access the structure).Sends the ‘read attributes’ response to the source node of the request.
3. On Source Node
On receiving the ‘read attributes’ response, the ZCL software on the source node performs the following steps:
For each attribute listed in the ‘read attributes’ response, it generates an
E_ZCL_CBET_READ_INDIVIDUAL_ATTRIBUTE_RESPONSE
message for the source endpoint callback function, which may or may not take action on this message.On completion of the parsing of the ‘read attributes’ response, it generates a single
E_ZCL_CBET_READ_ATTRIBUTES_RESPONSE
message for the source endpoint callback function, which may or may not take action on this message. ‘Read Attributes’ Request and Response ||
Note: The ‘read attributes’ requests and responses arrive at their destinations as data messages. Such a message triggers a stack event of the type ZPS_EVENT_APS_DATA_INDICATION, which is handled as described in Section 3.2.
Parent topic:Reading Attributes
Reading an Attribute of a Local Cluster
An individual attribute of a cluster on the local node can be read using the function eZCL_ReadLocalAttributeValue(). The read value is returned by the function (in a memory location for which a pointer must be provided).
Parent topic:Reading Attributes
Parent topic:Accessing Attributes
Writing Attributes
The ZCL provides functions for writing attribute values to both remote and local clusters, as described in Section 2.3.3.1 and Section 2.3.3.2 respectively.
Writing to Attributes of a Remote Cluster
A ZigBee 3.0 application might require to write attribute values to a remote device. Attribute values are written by sending a ‘write attributes’ request, normally from a client cluster to a server cluster, where the relevant attributes in the shared device structure are updated. Write access to cluster attributes must be explicitly enabled at compile time as described in Section 1.3.
Three ‘write attributes’ functions are provided in the ZCL:
eZCL_SendWriteAttributesRequest(): This function sends a ‘write attributes’ request to a remote device, which attempts to update the attributes in its shared structure. The remote device generates a ‘write attributes’ response to the source device, indicating success or listing error codes for any attributes that it could not update.
eZCL_SendWriteAttributesNoResponseRequest(): This function sends a ‘write attributes’ request to a remote device, which attempts to update the attributes in its shared structure. However, the remote device does not generate a ‘write attributes’ response, regardless of whether there are errors.
eZCL_SendWriteAttributesUndividedRequest(): This function sends a ‘write attributes’ request to a remote device, which checks that all the attributes can be written to without error:
If all attributes can be written without error, all the attributes are updated.
If any attribute is in error, all the attributes are left at their existing values.
The remote device generates a ‘write attributes’ response to the source device, indicating success or listing error codes for attributes that are in error.
The activities surrounding a ‘write attributes’ request on the source and destination nodes are outlined below and illustrated in 1](reading_a_set_of_attributes_of_a_remote_cluster.md#fig2). The events generated from a ‘write attributes’ request are further described in Chapter 3.
1. On Source Node
In order to send a ‘write attributes’ request, the application on the source node calls one of the above ZCL ‘write attributes’ functions to submit a request to update the relevant attributes on a cluster on a remote node. The information required by this function includes the following:
Source endpoint (from which the write request is to be sent)
Address of destination node for request
Destination endpoint (on destination node)
Identifier of the cluster containing the attributes [enumerations provided]
Number of attributes to be written
Array of identifiers of attributes to be written [enumerations provided]
2. On Destination Node
On receiving the ‘write attributes’ request, the ZCL software on the destination node performs the following steps:
For each attribute to be written, generates an E_ZCL_CBET_CHECK_ATTRIBUTE_RANGE event for the destination endpoint callback function.
If required, the callback function can do either or both of the following:
Check that the new attribute value is in the correct range - if the value is out-of-range, the function should set the
eAttributeStatus
field of the event to E_ZCL_ERR_ATTRIBUTE RANGEBlock the write by setting the the
eAttributeStatus
field of the event to E_ZCL_DENY_ATTRIBUTE_ACCESS
In the case of an out-of-range value or a blocked write, there is no further processing for that particular attribute following the ‘write attributes’ request.
If tasks within the application are not cooperative, the ZCL generates an E_ZCL_CBET_LOCK_MUTEX event for the endpoint callback function, which should lock the mutex that protects the relevant shared device structure - for information on mutexes, refer to Appendix A.
Writes the relevant attribute values to the shared device structure - an E_ZCL_CBET_WRITE_INDIVIDUAL_ATTRIBUTE event is generated for each individual attempt to write an attribute value, which the endpoint callback function can use to keep track of the successful and unsuccessful writes.
Note: If an ‘undivided write attributes’ request is received, an individual failed write would render the whole update process unsuccessful.
Generates an E_ZCL_CBET_WRITE_ATTRIBUTES event to indicate that all relevant attributes have been processed and, if required, creates a ‘write attributes’ response message for the source node.
If tasks within the application are not cooperative, the ZCL generates an E_ZCL_CBET_UNLOCK_MUTEX event for the endpoint callback function, which should now unlock the mutex that protects the shared device structure (other application tasks can now access the structure).
If required, sends a ‘write attributes’ response to the source node of the request.
3. On Source Node
On receiving an optional ‘write attributes’ response, the ZCL software on the source node performs the following steps:
For each attribute listed in the ‘write attributes’ response, it generates an E_ZCL_CBET_WRITE_INDIVIDUAL_ATTRIBUTE_RESPONSE message for the source endpoint callback function, which may or may not take action on this message. Only attributes for which the write has failed are included in the response and will therefore result in one of these events.
On completion of the parsing of the ‘write attributes’ response, it generates a single E_ZCL_CBET_WRITE_ATTRIBUTES_RESPONSE message for the source endpoint callback function, which may or may not take action on this message.
||
Note: The ‘write attributes’ requests and responses arrive at their destinations as data messages. Such a message triggers a stack event of the type ZPS_EVENT_APS_DATA_INDICATION, which is handled as described in Chapter 3.
Parent topic:Writing Attributes
Writing an Attribute Value to a Local Cluster
An individual attribute of a cluster on the local node can be written to using the function eZCL_WriteLocalAttributeValue(). The function is blocking, returning only once the value has been written.
Parent topic:Writing Attributes
Parent topic:Accessing Attributes
Attribute Discovery
A ZigBee cluster may have mandatory and/or optional attributes. The desired optional attributes are enabled in the cluster structure. An application running on a cluster client may need to discover which optional attributes are supported by the cluster server.
The ZCL provides functionality to perform the necessary ‘attribute discovery’, as described in the rest of this section.
Note:
‘Extended’ attribute discovery is also available. When this optional attribute is used, the accessibility of each reported attribute is also indicated. This is described in Appendix C.
Alternatively, the application on a cluster client can check whether a particular attribute exists on the cluster server by attempting to read the attribute (see Section 2.3.2) - if the attribute does not exist on the server, an error is returned.
Compile-time Options
If required, the attribute discovery feature must be explicitly enabled on the cluster server and client at compile time by including the relevant defines, from those below, in the zcl_options.h files:
#define ZCL_ATTRIBUTE_DISCOVERY_SERVER_SUPPORTED
#define ZCL_ATTRIBUTE_DISCOVERY_EXTENDED_SERVER_SUPPORTED
#define ZCL_ATTRIBUTE_DISCOVERY_CLIENT_SUPPORTED
#define ZCL_ATTRIBUTE_DISCOVERY_EXTENDED_CLIENT_SUPPORTED
Application Coding
The application on a cluster client can initiate a discovery of the attributes on the cluster server by calling the function eZCL_SendDiscoverAttributesRequest(), which sends a ‘discover attributes’ request to the server. This function allows a range of attributes to be searched for, defined by:
The ‘start’ attribute in the range (the attribute identifier must be specified)
The number of attributes in the range
Initially, the start attribute should be set to the first attribute of the cluster. If the discovery request does not return all the attributes used on the cluster server, the above function should be called again with the start attribute set to the next ‘undiscovered’ attribute. Multiple function calls may be required to discover all of the attributes used on the server.
On receiving a discover attributes request, the server handles the request automatically (provided that attribute discovery has been enabled in the compile-time options - see above) and replies with a ‘discover attributes’ response containing the requested information.
The arrival of this response at the client results in an E_ZCL_CBET_DISCOVER_INDIVIDUAL_ATTRIBUTE_RESPONSE event for each attribute reported in the response. Therefore, multiple events normally result from a single discover attributes request. This event contains details of the reported attribute in a tsZCL_AttributeDiscoveryResponse
structure (see Section 6.1.10).
Following the event for the final attribute reported, the event E_ZCL_CBET_DISCOVER_ATTRIBUTES_RESPONSE is generated to indicate that all attributes from the discover attributes response have been reported.
Parent topic:Accessing Attributes
Attribute Reporting
A cluster client can poll the value of an attribute on the cluster server by sending a ‘read attributes’ request, as described in Section 2.3.2. Alternatively, the server can issue unsolicited attribute reports to the client using the ‘attribute reporting’ feature (in which case there is no need for the client to request attribute values).
The attribute reporting mechanism reduces network traffic compared with the polling method. It also allows a sleeping server to report its attribute values while it is awake. Attribute reporting is an optional feature and is not supported by all devices.
An ‘attribute report’ (from server to client) can be triggered in one of the following ways:
by the user application (on the server device)
automatically (triggered by a change in the attribute value or periodically)
Automatic attribute reporting for an attribute can be enabled and configured remotely from the client or, for some attributes, locally on the server (see below). If it is required, automatic attribute reporting must be enabled at compile-time on both the cluster server and client. Automatic attribute reporting is more fully described in Appendix B.1 and the configuration of attribute reporting is detailed in Appendix B.3.
The ZCL specification states that certain attributes of a cluster must be reportable. Attribute reporting for these attributes remains optional but can be enabled for the individual attributes using a flag (E_ZCL_AF_RP) in the attribute definition structure - see the example code for the On/Off cluster in Section 2.3.1. This defines those attributes that the cluster server will report by default, known as ‘default reporting’, but reports on other attributes can be requested/configured by the cluster client.
Note: Attribute reporting configuration data should be preserved in Non-Volatile Memory (NVM) to allow automatic attribute reporting to resume following a reset of the server device. Persisting this data in NVM is described in Appendix B.7.
An attribute report can be issued directly by the server application as follows:
For all reportable attributes using the function eZCL_ReportAllAttributes()
For an individual reportable attribute using the function eZCL_ReportAttribute()
Only standard attributes can be reported (this does not include manufacturer-specific attributes) and only those attributes for which reporting has been enabled. This method of attribute reporting does not require any configuration, apart from enabling reports for the desired attributes. In this case, attribute reporting does not need to be enabled at compile-time on the server, but it still needs to be enabled at compile-time on the client to allow the client to receive attribute reports.
Sending an attribute report from the server is further described in Appendix B.4 and receiving an attribute report on the client is described in Appendix B.5.
Parent topic:Accessing Attributes
Parent topic:ZCL Fundamentals and Features