diff --git a/espnow_receiver_code/espnow_receiver_code.ino b/espnow_receiver_code/espnow_receiver_code.ino new file mode 100644 index 0000000..c9bba32 --- /dev/null +++ b/espnow_receiver_code/espnow_receiver_code.ino @@ -0,0 +1,38 @@ +#include +#include + +// Structure to receive data +typedef struct struct_message { + int a0; + int a1; + int a2; +} struct_message; + +// Create a struct_message instance +struct_message myData; + +// Callback function when data is received +void OnDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) { + memcpy(&myData, incomingData, sizeof(myData)); + Serial.printf("%lu Analog_in A0: %4d, A1: %4d, A2: %4d\n", micros(), myData.a0, myData.a1, myData.a2); +} + +void setup() { + Serial.begin(115200); + + // Set device as a Wi-Fi Station + WiFi.mode(WIFI_STA); + + // Init ESP-NOW + if (esp_now_init() != ESP_OK) { + Serial.println("Error initializing ESP-NOW"); + return; + } + + // Register callback function to receive data + esp_now_register_recv_cb(OnDataRecv); +} + +void loop() { + // Data is received via callback, nothing needed here +}