ESP-IDF Robot ESP NOW

This commit is contained in:
2024-12-24 12:01:37 -05:00
parent 1dab8b65be
commit f7248e365b

View File

@@ -241,6 +241,28 @@ static esp_err_t espnow_init(void) {
ESP_LOGE(TAG, "Create ESP-NOW mutex failed."); ESP_LOGE(TAG, "Create ESP-NOW mutex failed.");
return ESP_FAIL; 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; return ESP_OK;
} }