Last Updated on : 2024-11-20 08:51:44download
Zigbee device creation depends on the network connection so dev_power_on_init()
must be implemented.
The following code block uses the relay switch as an example to describe the process of creating Zigbee router devices.
const attr_t g_group_attr_list[] = {
GROUP_ATTR_LIST
};
const attr_t g_scene_attr_list[] = {
SCENE_ATTR_LIST
};
#define ON_OFF_PRIVATE_ATTR_LIST \
{ 0x0000, ATTR_BOOLEAN_ATTRIBUTE_TYPE, 1, (ATTR_MASK_TOKEN_FAST), (uint8_t*)0x00 }, \
const attr_t g_light_attr_list[] = {
ON_OFF_PRIVATE_ATTR_LIST
};
const cluster_t g_server_cluster_id[] = {
DEF_CLUSTER_GROUPS_CLUSTER_ID(g_group_attr_list)
DEF_CLUSTER_SCENES_CLUSTER_ID(g_scene_attr_list)
DEF_CLUSTER_ON_OFF_CLUSTER_ID(g_light_attr_list)
};
#define SERVER_CLUSTER_LEN get_array_len(g_server_cluster_id)
/**
* @note Represents one `ON_OFF_LIGHT` device, one endpoint.
* Support group, scene, and on/off cluster on the server.
* Correspond to attributes `GROUP_ATTR_LIST`, `SCENE_ATTR_LIST`, and `ON_OFF_PRIVATE_ATTR_LIST` respectively.
*/
const dev_description_t g_dev_des[] = {
{ 0x01, ZHA_PROFILE_ID, ZG_DEVICE_ID_ON_OFF_LIGHT, SERVER_CLUSTER_LEN, (cluster_t *)&g_server_cluster_id[0], 0, NULL},
};
void dev_power_on_init(void)
{
zg_dev_config_t g_zg_dev_config;
join_config_t cfg;
/**
* @note Describe a device in terms of the number of endpoints and the associated clusters and attributes of each endpoint.
*/
dev_register_zg_ep_infor((dev_description_t *)g_dev_des, EP_SUMS);
/**
* @note Configure the Zigbee device as a router device.
*/
memset(&g_zg_dev_config, 0, sizeof(zg_dev_config_t));
g_zg_dev_config.dev_type = ZG_ROUTER;
dev_register_zg_dev_config(&g_zg_dev_config);
/**
* @note Configure auto networking after power on or remote deletion. The timeout period is one minute.
*/
memset(&cfg, 0, sizeof(cfg));
cfg.auto_join_power_on_flag = TRUE;
cfg.auto_join_remote_leave_flag = TRUE;
cfg.join_timeout = 60000;
dev_zg_join_config(&cfg);
return;
}
The following code block uses the smart switch (no neutral wire required) as an example to describe the process of creating Zigbee low power devices.
#define ON_OFF_PRIVATE_ATTR_LIST \
{ 0x0000, ATTR_BOOLEAN_ATTRIBUTE_TYPE, 1, (ATTR_MASK_TOKEN_FAST), (uint8_t*)0x00 }, \
const attr_t g_light_attr_list[] = {
ON_OFF_PRIVATE_ATTR_LIST
};
const cluster_t g_server_cluster_id[] = {
DEF_CLUSTER_ON_OFF_CLUSTER_ID(g_light_attr_list)
};
#define SERVER_CLUSTER_LEN get_array_len(g_server_cluster_id)
/**
* @note Represents one `ON_OFF_LIGHT` device, one endpoint.
* Support on/off cluster on the server. Correspond to the attribute `ON_OFF_PRIVATE_ATTR_LIST`.
*/
const dev_description_t g_dev_des[] = {
{ 0x01, ZHA_PROFILE_ID, ZG_DEVICE_ID_ON_OFF_LIGHT, SERVER_CLUSTER_LEN, (cluster_t *)&g_server_cluster_id[0], 0, NULL},
};
void dev_power_on_init(void)
{
zg_dev_config_t zg_dev_config;
join_config_t cfg;
/**
* @note Describe a device in terms of the number of endpoints and the associated clusters and attributes of each endpoint.
*/
dev_register_zg_ep_infor((dev_description_t *)g_dev_des, EP_SUMS);
/**
* @note Configure the Zigbee device as a router device.
*/
memset(&zg_dev_config, 0, sizeof(zg_dev_config_t));
zg_dev_config.dev_type = ZG_SLEEPY_END_DEVICE;
zg_dev_config.config.sleep_dev_cfg.poll_conifg.poll_failed_times = 3; /// The device enters `NET_LOST` state after three failed polling attempts. The connection to the parent node is lost.
zg_dev_config.config.sleep_dev_cfg.poll_conifg.poll_forever_flag = TRUE; /// The device continues polling.
zg_dev_config.config.sleep_dev_cfg.poll_conifg.poll_interval = 250; ///< The polling interval is 250 ms.
zg_dev_config.config.sleep_dev_cfg.poll_conifg.wait_app_ack_time = 1000; /// If `poll_forever_flag` is `FALSE`, sending application data is followed by total `(2+wait_app_ack_time/poll_interval)` polling operations.
zg_dev_config.config.sleep_dev_cfg.rejoin_config.auto_rejoin_send_data = TRUE; /// Auto rejoining is triggered in case of failed data sending.
zg_dev_config.config.sleep_dev_cfg.rejoin_config.next_rejoin_time = 5000; /// If this rejoining attempt failed, the next try starts in five seconds.
zg_dev_config.config.sleep_dev_cfg.rejoin_config.power_on_auto_rejoin_flag = TRUE; /// Rejoining is initiated automatically after programs are started.
zg_dev_config.config.sleep_dev_cfg.rejoin_config.rejoin_try_times = 5; /// The amount of beacon requests sent for one rejoining attempt.
zg_dev_config.config.sleep_dev_cfg.rejoin_config.wake_up_time_after_join = 30000; /// If `poll_forever_flag` is `FALSE`, the time represents the polling duration after successful networking.
zg_dev_config.config.sleep_dev_cfg.rejoin_config.wake_up_time_after_rejoin = 5000; ///< If `poll_forever_flag` is `FALSE`, the time represents the polling duration after successful rejoining.
zg_dev_config.beacon_send_interval_for_join = 300; ///< The interval of beacon requests for networking.
zg_dev_config.beacon_send_interval_for_rejoin = 300; /// The interval of beacon requests for rejoining attempts.
zg_dev_config.zb_scan_duration = ZB_SCAN_DURATION_3; /// The continuous reception time after beacon requests are sent.
dev_register_zg_dev_config(&zg_dev_config);
/**
* @note Configure auto networking after remote deletion only. The timeout period is one minute.
*/
memset(&cfg, 0, sizeof(cfg));
cfg.auto_join_power_on_flag = FALSE;
cfg.auto_join_remote_leave_flag = TRUE;
cfg.join_timeout = 60000;
dev_zg_join_config(&cfg);
return;
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback