diff --git a/ESP-IDF_Robot/main/blink_example_main.c b/ESP-IDF_Robot/main/blink_example_main.c index a4493b0e5..5e1d8b044 100644 --- a/ESP-IDF_Robot/main/blink_example_main.c +++ b/ESP-IDF_Robot/main/blink_example_main.c @@ -241,6 +241,28 @@ static esp_err_t espnow_init(void) { ESP_LOGE(TAG, "Create ESP-NOW mutex failed."); return ESP_FAIL; } + + /* Initialize ESPNOW and register sending and receiving callback function. */ + ESP_ERROR_CHECK( esp_now_init() ); + ESP_ERROR_CHECK( esp_now_register_send_cb(espnow_send_cb) ); + ESP_ERROR_CHECK( esp_now_register_recv_cb(espnow_recv_cb) ); +#if CONFIG_ESPNOW_ENABLE_POWER_SAVE + ESP_ERROR_CHECK( esp_now_set_wake_window(CONFIG_ESPNOW_WAKE_WINDOW) ); + ESP_ERROR_CHECK( esp_wifi_connectionless_module_set_wake_interval(CONFIG_ESPNOW_WAKE_INTERVAL) ); +#endif + /* Set primary master key. */ + ESP_ERROR_CHECK( esp_now_set_pmk((uint8_t *)CONFIG_ESPNOW_PMK) ); + + /* Add broadcast peer information to peer list. */ + esp_now_peer_info_t *peer = malloc(sizeof(esp_now_peer_info_t)); + if (peer == NULL) { + ESP_LOGE(TAG, "Malloc peer information fail"); + vSemaphoreDelete(espnow_queue); + esp_now_deinit(); + return ESP_FAIL; + } + + return ESP_OK; }