ESP32 Learn

ESP-NOW Basics

2025-09-18 路 ~1 min read
Table of contents
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <esp_now.h>

#include <WiFi.h>

uint8_t peer[] = {
  0x24,
  0x6F,
  0x28,
  0xAA,
  0xBB,
  0xCC
};
void onSent(const uint8_t * , esp_now_send_status_t s) {
  Serial.printf("Send: %d\n", s);
}
void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  esp_now_init();
  esp_now_register_send_cb(onSent);
  esp_now_peer_info_t p = {};
  memcpy(p.peer_addr, peer, 6);
  esp_now_add_peer( & p);
  const char * msg = "hello";
  esp_now_send(peer, (uint8_t * ) msg, strlen(msg));
}
void loop() {}

馃敄 #esp-now #p2p #wireless