Upload files to "espnow_receiver_code"
This commit is contained in:
parent
e8bb0a36f3
commit
65e45bd7c3
38
espnow_receiver_code/espnow_receiver_code.ino
Normal file
38
espnow_receiver_code/espnow_receiver_code.ino
Normal file
@ -0,0 +1,38 @@
|
||||
#include <esp_now.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
// 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user