void onDataReceived (const uint8_t *mac_addr, const uint8_t *data, uint8_t data_len) {
+
+ ... ... ...
+ ... ... ...
+
ESP_LOGI(TAG, "Data received from: %02x:%02x:%02x:%02x:%02x:%02x, len=%d", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5], data_len);
memcpy(&buf, data, sizeof(buf));
x_axis = buf.x_axis;
- y_axis = buf.y_axis
+ y_axis = buf.y_axis;
+
+ ... ... ...
+ ... ... ...
}
@@ -60,7 +78,14 @@
uint8_t transmitter_mac[ESP_NOW_ETH_ALEN] = {0x9C, 0x9E, 0x6E, 0x14, 0xB5, 0x54};
+
+typedef struct {
+ int x_axis; // Joystick x-position
+ int y_axis; // Joystick y-position
+ bool nav_bttn; // Joystick push button
+ bool led; // LED ON/OFF state
+ uint8_t motor1_rpm_pwm; // PWMs for 4 DC motors
+ uint8_t motor2_rpm_pwm;
+ uint8_t motor3_rpm_pwm;
+ uint8_t motor4_rpm_pwm;
+} __attribute__((packed)) sensors_data_t;
@@ -891,11 +912,18 @@ This enables fine-grained speed control, supports differential drive configurati
void onDataReceived (const uint8_t *mac_addr, const uint8_t *data, uint8_t data_len) {
+
+ ... ... ...
+ ... ... ...
+
ESP_LOGI(TAG, "Data received from: %02x:%02x:%02x:%02x:%02x:%02x, len=%d", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5], data_len);
memcpy(&buf, data, sizeof(buf));
x_axis = buf.x_axis;
- y_axis = buf.y_axis
+ y_axis = buf.y_axis;
+
+ ... ... ...
+ ... ... ...
}
@@ -915,7 +943,14 @@ This enables fine-grained speed control, supports differential drive configurati
#include "nvs_flash.h"
#include "esp_err.h"
-
void app_main(void) {
+
... ... ...
+
... ... ...
+
+
void app_main(void) {
+
+
... ... ...
+
... ... ...
+
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@@ -936,6 +971,9 @@ This enables fine-grained speed control, supports differential drive configurati
ESP_ERROR_CHECK(esp_now_register_recv_cb((void*)onDataReceived));
system_led_init();
+
+
... ... ...
+
... ... ...
}
diff --git a/ESP-IDF_Robot/tutorial/docs/source/receiver.rst b/ESP-IDF_Robot/tutorial/docs/source/receiver.rst
index caed557f2..a91b8d5d0 100644
--- a/ESP-IDF_Robot/tutorial/docs/source/receiver.rst
+++ b/ESP-IDF_Robot/tutorial/docs/source/receiver.rst
@@ -8,17 +8,35 @@ Configuration Variables
uint8_t transmitter_mac[ESP_NOW_ETH_ALEN] = {0x9C, 0x9E, 0x6E, 0x14, 0xB5, 0x54};
+ typedef struct {
+ int x_axis; // Joystick x-position
+ int y_axis; // Joystick y-position
+ bool nav_bttn; // Joystick push button
+ bool led; // LED ON/OFF state
+ uint8_t motor1_rpm_pwm; // PWMs for 4 DC motors
+ uint8_t motor2_rpm_pwm;
+ uint8_t motor3_rpm_pwm;
+ uint8_t motor4_rpm_pwm;
+ } __attribute__((packed)) sensors_data_t;
+
Receiving & De-Ecapsulating Data
--------------------------------
.. code-block:: c
void onDataReceived (const uint8_t *mac_addr, const uint8_t *data, uint8_t data_len) {
+
+ ... ... ...
+ ... ... ...
+
ESP_LOGI(TAG, "Data received from: %02x:%02x:%02x:%02x:%02x:%02x, len=%d", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5], data_len);
memcpy(&buf, data, sizeof(buf));
x_axis = buf.x_axis;
- y_axis = buf.y_axis
+ y_axis = buf.y_axis;
+
+ ... ... ...
+ ... ... ...
}
Main Function
@@ -31,7 +49,14 @@ Main Function
#include "nvs_flash.h"
#include "esp_err.h"
+ ... ... ...
+ ... ... ...
+
void app_main(void) {
+
+ ... ... ...
+ ... ... ...
+
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@@ -52,4 +77,7 @@ Main Function
ESP_ERROR_CHECK(esp_now_register_recv_cb((void*)onDataReceived));
system_led_init();
+
+ ... ... ...
+ ... ... ...
}
\ No newline at end of file