diff --git a/ESP-IDF_Robot_RC/main/espnow_example_main.c b/ESP-IDF_Robot_RC/main/espnow_example_main.c index 2eb1c5998..3eac593ff 100755 --- a/ESP-IDF_Robot_RC/main/espnow_example_main.c +++ b/ESP-IDF_Robot_RC/main/espnow_example_main.c @@ -463,8 +463,33 @@ void sensors_data_prepare(espnow_data_packet_t *send_packet) void sendData (void) { // Send data, specify receiver MAC address, pointer to the data being sent, and length of data being sent. - //sensors_data_t *buffer; - buffer = malloc(sizeof(sensors_data_t)); + sensors_data_t buffer; + buffer.type = 1; + buffer.crc = 0; + buffer.x_axis = 240; + buffer.y_axis = 2040; + buffer.nav_bttn = 0; + buffer.motor1_rpm_pcm = 10; + buffer.motor2_rpm_pcm = 0; + buffer.motor3_rpm_pcm = 0; + buffer.motor4_rpm_pcm = 0; + ESP_LOGI(TAG, "x-axis: 0x%04X", (uint8_t)buffer.x_axis); + ESP_LOGI(TAG, "y-axis: 0x%04X", (uint8_t)buffer.y_axis); + ESP_LOGI(TAG, "pcm 1: 0x%04X", buffer.motor1_rpm_pcm); + ESP_LOGI(TAG, "pcm 2: 0x%04X", (uint8_t)buffer.motor2_rpm_pcm); + ESP_LOGI(TAG, "pcm 3: 0x%04X", (uint8_t)buffer.motor3_rpm_pcm); + ESP_LOGI(TAG, "pcm 4: 0x%04X", (uint8_t)buffer.motor4_rpm_pcm); + + //uint8_t result = esp_now_send(receiver_mac, &flagToSend, sizeof(flagToSend)); + uint8_t result = esp_now_send(receiver_mac, &buffer, sizeof(buffer)); + //uint8_t result = esp_now_send(receiver_mac, (sensors_data_t *)&buffer, sizeof(buffer)); + if (result != 0) { + ESP_LOGE("ESP-NOW", "Error sending data!"); + deletePeer(); + } + else + ESP_LOGW("ESP-NOW", "Data was sent."); + /*buffer = malloc(sizeof(sensors_data_t)); buffer->type = 1; buffer->crc = 0; buffer->x_axis = 240; @@ -489,7 +514,7 @@ void sendData (void) { deletePeer(); } else - ESP_LOGW("ESP-NOW", "Data was sent."); + ESP_LOGW("ESP-NOW", "Data was sent.");*/ } static void rc_send_data_task (void *arg) {