Merge pull request 'Fixed errors' (#3) from josh_desktop into main
Reviewed-on: #3
This commit is contained in:
20
main/main.c
20
main/main.c
@@ -14,6 +14,11 @@ static const char *TAG = "SIMPLE_LIGHT_CONTROLLER";
|
|||||||
static bool led_is_on = false;
|
static bool led_is_on = false;
|
||||||
static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, const void *message);
|
static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, const void *message);
|
||||||
|
|
||||||
|
// Helper function for scheduler callback
|
||||||
|
static void commissioning_restart_cb(uint8_t param) {
|
||||||
|
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
|
||||||
|
}
|
||||||
|
|
||||||
static void led_task(void *pvParameters) {
|
static void led_task(void *pvParameters) {
|
||||||
|
|
||||||
gpio_reset_pin(LED_PIN); // Reset pin to default state (clean slate)
|
gpio_reset_pin(LED_PIN); // Reset pin to default state (clean slate)
|
||||||
@@ -115,15 +120,11 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
|
|||||||
|
|
||||||
// === NETWORK JOINING ATTEMPT RESULT ===
|
// === NETWORK JOINING ATTEMPT RESULT ===
|
||||||
case ESP_ZB_BDB_SIGNAL_STEERING:
|
case ESP_ZB_BDB_SIGNAL_STEERING:
|
||||||
// Check if joining was successful
|
|
||||||
if (signal_struct->esp_err_status == ESP_OK) {
|
if (signal_struct->esp_err_status == ESP_OK) {
|
||||||
ESP_LOGI(TAG, "Successfully joined Zigbee network!");
|
ESP_LOGI(TAG, "Successfully joined Zigbee network!");
|
||||||
ESP_LOGI(TAG, "Your device should now appear in Home Assistant");
|
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "Failed to join network, retrying in 5 seconds...");
|
ESP_LOGI(TAG, "Failed to join network, retrying in 5 seconds...");
|
||||||
// Retry joining after 5 second delay
|
esp_zb_scheduler_alarm((esp_zb_callback_t)commissioning_restart_cb, 0, 5000);
|
||||||
esp_zb_scheduler_alarm((esp_zb_callback_t)esp_zb_bdb_start_top_level_commissioning,
|
|
||||||
ESP_ZB_BDB_MODE_NETWORK_STEERING, 5000);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -143,12 +144,8 @@ void app_main(void)
|
|||||||
// Saves Zigbee network info so device remembers which network it joined
|
// Saves Zigbee network info so device remembers which network it joined
|
||||||
ESP_ERROR_CHECK(nvs_flash_init()); // ESP_ERROR_CHECK = crash if this fails
|
ESP_ERROR_CHECK(nvs_flash_init()); // ESP_ERROR_CHECK = crash if this fails
|
||||||
|
|
||||||
esp_zb_platform_config_t config = {
|
// Use default platform configuration (simpler approach)
|
||||||
.radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(), // Set up 2.4GHz radio settings
|
ESP_ERROR_CHECK(esp_zb_platform_config(NULL)); // NULL = use defaults
|
||||||
.host_config = ESP_ZB_DEFAULT_HOST_CONFIG(), // Set up processor settings
|
|
||||||
};
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_zb_platform_config(&config)); // Apply the configuration to board
|
|
||||||
|
|
||||||
// xTaskCreate = create a new task (mini-program that runs independently)
|
// xTaskCreate = create a new task (mini-program that runs independently)
|
||||||
xTaskCreate(led_task, // Function to run (defined above)
|
xTaskCreate(led_task, // Function to run (defined above)
|
||||||
@@ -166,5 +163,4 @@ void app_main(void)
|
|||||||
NULL); // No handle needed
|
NULL); // No handle needed
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Both tasks started - LED and Zigbee running independently!");
|
ESP_LOGI(TAG, "Both tasks started - LED and Zigbee running independently!");
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user