ESP32 C6 Firebeetle Zigbee

userHead Greylie 2024-10-20 02:41:37 524 Views1 Replies

Hi

 

I need some help. I have a ESP32 C6 with built in Zigbee connectivity. I want to connect it to a Sonoff USB dongle. But I cannot get it working from the Arduino IDE.

Is the Arduino IDE fine to do this or should I use visual studios? Some example code and instructions would be appreciated.

2024-11-01 01:35:28

Hi,

For ESP32-C6 with Zigbee, I recommend using VS Code with the ESP-IDF extension instead of Arduino IDE, as it provides better support for ESP's Zigbee SDK.
Here's a basic example connecting to a Zigbee network (as an End Device):

#include <esp_zigbee_core.h>
#include <esp_log.h>

#define ENDPOINT_ID     1
#define TAG            "ZIGBEE_DEVICE"

// Device config
static esp_zb_cfg_t zb_cfg = {
   .esp_zb_role = ESP_ZB_DEVICE_TYPE_ED,  // End device
   .install_code_policy = false,
   .nwk_cfg = {
       .zed_cfg = {
           .ed_timeout = ESP_ZB_ED_AGING_TIMEOUT_64MIN,
           .keep_alive = 3000,
       }
   }
};

// Basic cluster config
static esp_zb_basic_cluster_cfg_t basic_cluster_cfg = {
   .zcl_version = 0x08,
   .power_source = ESP_ZB_ZCL_BASIC_POWER_SOURCE_DC_SOURCE,
};

// Callback when device joins network
static void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
{
   esp_err_t err_status = signal_struct->esp_err_status;
   esp_zb_app_signal_type_t type = signal_struct->type;
   
   switch (type) {
       case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP:
           ESP_LOGI(TAG, "Zigbee stack initialized");
           esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION);
           break;
       case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START:
           ESP_LOGI(TAG, "Start network steering");
           esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
           break;
       case ESP_ZB_BDB_SIGNAL_STEERING:
           if (err_status == ESP_OK) {
               ESP_LOGI(TAG, "Successfully joined Zigbee network!");
           } else {
               ESP_LOGW(TAG, "Failed to join network, retry...");
               esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
           }
           break;
       default:
           ESP_LOGI(TAG, "Signal: %d, status: %d", type, err_status);
           break;
   }
}

void app_main(void)
{
   esp_zb_platform_config_t config = {
       .radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(),
       .host_config = ESP_ZB_DEFAULT_HOST_CONFIG(),
   };
   
   // Initialize Zigbee stack
   ESP_ERROR_CHECK(esp_zb_platform_config(&config));
   
   // Create basic cluster
   esp_zb_attribute_list_t *basic_cluster = esp_zb_basic_cluster_create(&basic_cluster_cfg);
   esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create();
   esp_zb_cluster_list_add_basic_cluster(cluster_list, basic_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
   
   // Create endpoint
   esp_zb_ep_list_t *ep_list = esp_zb_ep_list_create();
   esp_zb_endpoint_config_t endpoint_config = {
       .endpoint = ENDPOINT_ID,
       .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID,
       .app_device_id = ESP_ZB_HA_ON_OFF_SWITCH_DEVICE_ID,
       .app_device_version = 0
   };
   esp_zb_ep_list_add_ep(ep_list, cluster_list, endpoint_config);
   
   // Register device
   esp_zb_device_register(ep_list);
   
   // Start Zigbee
   esp_zb_init(&zb_cfg);
   esp_zb_start(false);
   esp_zb_main_loop_iteration();
}

userHeadPic Richard_26cm