For a typical ZCL application developed from the samples, what is the recommended way to send a ZCL command from the application to a local endpoint?
For example, consider an application with a single OnOff output endpoint. Such a device will typically have a manual operation switch on it. Pressing this switch toggles the output.
When the output is toggled, there are various attributes that must be adjusted on the endpoint (onOff, global scene etc.) as well as potentially change notifications and messages sent to other bound devices. All of this logic is taken care of by the ZCL SDK layer, but it's necessary to trigger it.
If there is only a single endpoint, then sending a ZCL command with eCLD_OnOffCommandSend won't work as there is no source endpoint. There are internal commands in the ZCL (e.g. eCLD_OnOffHandleOnCommand), but these are internal.
Additionally, if there is a second endpoint on the device that can send a eCLD_OnOffCommandSend message, then what needs to be done to have the device respond to it? We have a device with onOff client and onOff server, and sending this command doesn't work. The cause seems to be because when sending from the local application to a local endpoint, then the message is sent with no security, which causes it be ignored. The sending code is as follows:
uint8 u8Seq;
tsZCL_Address sAddress;
sAddress.eAddressMode = E_ZCL_AM_SHORT_NO_ACK;
sAddress.uAddress.u16DestinationAddress = ZPS_u16AplZdoGetNwkAddr();
status = eCLD_OnOffCommandSend(
ROUTER_SWITCH_ENDPOINT,
ROUTER_RELAY_ENDPOINT,
&sAddress,
&u8Seq,
E_CLD_ONOFF_CMD_TOGGLE);
This returns success, and a ZPS_EVENT_APS_DATA_INDICATION event is generated, which is received by the app and then dispatched to the stack with vZCL_EventHandler. The stack does no further processing.
In the case of receiving a toggle command from an external node, the same ZPS_EVENT_APS_DATA_INDICATION message is received and dispatched, but the stack responds as it should to the command.
Looking at the details of the message in both scenarios, the only difference is that the eSecurityStatus field of the event is 0xAC (secured with network key) when received from en external node, and 0xAF (unsecured) when generated locally with the above command.
If we change the value of eSecurityStatus in the event to 0xAC before sending it to the stack with vZCL_EventHandler, then the stack responds as expected.
So two questions:
1) What is the recommended method when there is no additional endpoint to send a message?
2) How can a local message like this be sent with the correct security settings?
Thanks,