Zigbee examples: help understanding how they work
Posted: Wed May 29, 2024 7:03 pm
I'm looking at the example here: examples/esp_zigbee_HA_sample/HA_on_off_light
It works fine but I'm having trouble understanding the code. In particular, I don't see how the main loop runs.
This is called as a task from app_main:
It looks to me that esp_zb_main_loop_iteration() is only run once. Shouldn't it be inside a while(true) loop?
The documentation says "Must be called after esp_zb_int() and esp_zb_start() inside the application’s main cycle. ". This implies it is called repeatedly but the documentation for xTaskCreate implies that you need a loop, for(;;) in the example:
https://www.freertos.org/a00125.html
It works fine but I'm having trouble understanding the code. In particular, I don't see how the main loop runs.
Code: Select all
static void esp_zb_task(void *pvParameters)
{
/* initialize Zigbee stack */
esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZED_CONFIG();
esp_zb_init(&zb_nwk_cfg);
esp_zb_on_off_light_cfg_t light_cfg = ESP_ZB_DEFAULT_ON_OFF_LIGHT_CONFIG();
esp_zb_ep_list_t *esp_zb_on_off_light_ep = esp_zb_on_off_light_ep_create(HA_ESP_LIGHT_ENDPOINT, &light_cfg);
esp_zb_device_register(esp_zb_on_off_light_ep);
esp_zb_core_action_handler_register(zb_action_handler);
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
ESP_ERROR_CHECK(esp_zb_start(false));
esp_zb_main_loop_iteration();
}
Code: Select all
xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL);
The documentation says "Must be called after esp_zb_int() and esp_zb_start() inside the application’s main cycle. ". This implies it is called repeatedly but the documentation for xTaskCreate implies that you need a loop, for(;;) in the example:
https://www.freertos.org/a00125.html