ZCL Commands#

API for runtime subscription to ZCL commands.

Following a brief usage example that demonstrate how to subscribe to the ZCL "Level Control" cluster commands, client side, with no manufacturer ID. In this example we only handle only "Stop" command. The subscribed callback must return a value of:

void my_zcl_command_handler(sl_service_opcode_t opcode,
                            sl_service_function_context_t *context)
{
  assert(opcode == SL_SERVICE_FUNCTION_TYPE_ZCL_COMMAND);

  EmberAfClusterCommand *cmd = (EmberAfClusterCommand *)context->data;

  switch (cmd->commandId) {
    case ZCL_STOP_COMMAND_ID:
    {
      // ZCL command structs and parsing functions are implemented in the
      // generated zap-cluster-command-parser.[c,h] files.
      sl_zcl_level_control_cluster_stop_command_t cmd_data;

      if (zcl_decode_level_control_cluster_stop_command(cmd, &cmd_data)
          != EMBER_ZCL_STATUS_SUCCESS) {
        return EMBER_ZCL_STATUS_UNSUP_COMMAND;
      }

      // Handle the command here

      // Send a default response back to the client
      emberAfSendDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);

      return EMBER_ZCL_STATUS_SUCCESS;
    }
  }

  return EMBER_ZCL_STATUS_UNSUP_COMMAND;
}

void app_init(void)
{
  sl_zigbee_subscribe_to_zcl_commands(ZCL_LEVEL_CONTROL_CLUSTER_ID,
                                      0xFFFF, // not manufacturer specific
                                      ZCL_DIRECTION_SERVER_TO_CLIENT,
                                      my_zcl_command_handler);
}

API#

sl_zigbee_subscribe_to_zcl_commands(uint16_t cluster_id, uint16_t manufacturer_id, uint8_t direction, sl_service_function_t service_function)

Runtime subscription to specific incoming ZCL commands.

API Documentation#

sl_zigbee_subscribe_to_zcl_commands#

sl_status_t sl_zigbee_subscribe_to_zcl_commands (uint16_t cluster_id, uint16_t manufacturer_id, uint8_t direction, sl_service_function_t service_function)

Runtime subscription to specific incoming ZCL commands.

Parameters
N/Acluster_id

The cluster ID of the ZCL messages to subscribe to.

N/Amanufacturer_id

The manufacturer ID if any. If not set, a value of 0xFFFF should be passed in.

N/Adirection

A value of ZCL_DIRECTION_CLIENT_TO_SERVER or ZCL_DIRECTION_SERVER_TO_CLIENT specifying the side (client or server) of the ZCL messages to subscribe to.

N/Aservice_function

A sl_service_function_t function pointer specifying the function to be invoked when an incoming ZCL command matches the criteria specified in this API.

Returns


Definition at line 2054 of file app/framework/include/af.h