Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <esp_now.h>
- #include <WiFi.h>
- uint8_t broadcastAddress[] = {0x24, 0x0A, 0xC4, 0x35, 0x3A, 0x90}; // MAC address of the receiver
- void setup() {
- Serial.begin(115200);
- WiFi.mode(WIFI_STA);
- if (esp_now_init() != ESP_OK) {
- Serial.println("Error initializing ESP-NOW");
- return;
- }
- esp_now_peer_info_t peerInfo;
- memcpy(peerInfo.peer_addr, broadcastAddress, 6);
- peerInfo.channel = 0;
- peerInfo.encrypt = false;
- if (esp_now_add_peer(&peerInfo) != ESP_OK) {
- Serial.println("Failed to add peer");
- return;
- }
- }
- void loop() {
- const char *message = "Hello, ESP-NOW!";
- esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *)message, strlen(message));
- if (result == ESP_OK) {
- Serial.println("Message sent successfully");
- } else {
- Serial.println("Error sending message");
- }
- delay(1000); // Send message every second
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement