Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <esp_now.h>
- #include <WiFi.h>
- void onReceive(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
- char message[data_len + 1];
- memcpy(message, data, data_len);
- message[data_len] = '\0';
- Serial.print("Message received: ");
- Serial.println(message);
- }
- void setup() {
- Serial.begin(115200);
- WiFi.mode(WIFI_STA);
- if (esp_now_init() != ESP_OK) {
- Serial.println("Error initializing ESP-NOW");
- return;
- }
- esp_now_register_recv_cb(onReceive);
- }
- void loop() {
- // Nothing to do here, everything is handled in the callback
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement