mirror of
https://github.com/alexandrebobkov/ESP-Nodes.git
synced 2025-08-10 05:23:22 +00:00
ESP-IDF Robot ESP NOW
This commit is contained in:
@@ -262,6 +262,42 @@ static esp_err_t espnow_init(void) {
|
|||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(peer, 0, sizeof(esp_now_peer_info_t));
|
||||||
|
peer->channel = CONFIG_ESPNOW_CHANNEL;
|
||||||
|
peer->ifidx = ESPNOW_WIFI_IF;
|
||||||
|
peer->encrypt = false;
|
||||||
|
memcpy(peer->peer_addr, broadcast_mac, ESP_NOW_ETH_ALEN);
|
||||||
|
ESP_ERROR_CHECK( esp_now_add_peer(peer) );
|
||||||
|
free(peer);
|
||||||
|
|
||||||
|
/* Initialize sending parameters. */
|
||||||
|
send_param = malloc(sizeof(espnow_send_param_t));
|
||||||
|
if (send_param == NULL) {
|
||||||
|
ESP_LOGE(TAG, "Malloc send parameter fail");
|
||||||
|
vSemaphoreDelete(espnow_queue);
|
||||||
|
esp_now_deinit();
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
memset(send_param, 0, sizeof(espnow_send_param_t));
|
||||||
|
send_param->unicast = false;
|
||||||
|
send_param->broadcast = true;
|
||||||
|
send_param->state = 0;
|
||||||
|
send_param->magic = esp_random();
|
||||||
|
send_param->count = CONFIG_ESPNOW_SEND_COUNT;
|
||||||
|
send_param->delay = CONFIG_ESPNOW_SEND_DELAY;
|
||||||
|
send_param->len = CONFIG_ESPNOW_SEND_LEN;
|
||||||
|
send_param->buffer = malloc(CONFIG_ESPNOW_SEND_LEN);
|
||||||
|
if (send_param->buffer == NULL) {
|
||||||
|
ESP_LOGE(TAG, "Malloc send buffer fail");
|
||||||
|
free(send_param);
|
||||||
|
vSemaphoreDelete(espnow_queue);
|
||||||
|
esp_now_deinit();
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
memcpy(send_param->dest_mac, broadcast_mac, ESP_NOW_ETH_ALEN);
|
||||||
|
example_espnow_data_prepare(send_param);
|
||||||
|
|
||||||
|
xTaskCreate(espnow_task, "example_espnow_task", 2048, send_param, 4, NULL);
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user