Skip to content
We have moved: pcb.esp32s.com → pcb32.comSame store. Existing accounts, orders and affiliate commission records are unchanged.
Номер заказа: USD
Номер заказа: USD
pcb32.com
Cart 0

Учебное пособие по ESP-NOW: простое подключение ESP32 к ESP32

Учебное пособие по ESP-NOW: простое подключение ESP32 к ESP32

ESP32 to ESP32 over WiFi can be made remarkably efficient through the use of ESP-NOW, a wireless communication protocol developed by Espressif Systems. Designed to enable robust and low-latency communication between ESP32 devices, ESP-NOW facilitates a seamless mesh-like network that supports multiple nodes. This has proven to be an invaluable tool for a wide range of applications, from IoT devices to remote sensors.

Understanding ESP-NOW

ESP-NOW is a wireless communication protocol that allows multiple ESP32 devices to exchange data directly without the need for a central WiFi network or router. This protocol operates on the 2.4 GHz frequency, allowing devices to communicate over relatively long distances with minimal power consumption.

Key features of ESP-NOW include:

– Низкое энергопотребление: Ideal for battery-powered devices.
– Низкая задержка: Faster than traditional WiFi, reducing the delay in data transmission.
– Масштабируемость: Multiple devices can be interconnected, forming a mesh network.

Setting Up ESP32 to ESP32 Over WiFi

Before diving into coding, ensure you have the necessary hardware and software. You’ll need at least two ESP32 modules and the Arduino IDE installed on your computer.

1. Install ESP32 Board in Arduino IDE:
– Open Arduino IDE and go to Файл > Настройки.
– Enter `https://dl.espressif.com/dl/package_esp32_index.json` in the “Additional Board Manager URLs” field.
– Go to Tools > Board > Boards Manager and install the “ESP32” package.

2. Connect ESP32 Devices:
– Use USB cables to connect each ESP32 module to your computer.
– Select the correct port and board from the Tools menu in Arduino IDE.

Coding Your First ESP-NOW Project

Let’s set up a basic project where one ESP32 acts as a transmitter and another as a receiver. The transmitter will send a simple message to the receiver using ESP-NOW.

Transmitter Code

Start by programming the ESP32 that will send the data:

“`cpp
#include
#include

// MAC address of the receiver
uint8_t broadcastAddress[] = {/ insert MAC address here /};

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 sendData() {
const char message = “Hello ESP-NOW!”;
esp_now_send(broadcastAddress, (uint8_t
)message, strlen(message));
}

void loop() {
sendData();
задержка(2000);
}
“`

Receiver Code

Next, set up the ESP32 that will receive the data:

“`cpp
#include
#include

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 onReceive(const uint8_t mac_addr, const uint8_t data, int data_len) {
Serial.print(“Received Data: “);
Serial.println((char *)data);
}

void loop() {
// No code required here
}
“`

Advantages of Using ESP-NOW

– Direct Communication: Bypasses the need for a central router, facilitating more straightforward setups.
– Battery Efficiency: With lower power requirements, ESP-NOW is suitable for IoT devices where battery life is crucial.
– Flexible Topology: Supports communication in star, peer-to-peer, or mesh network configurations.

Applications of ESP32 to ESP32 Over WiFi

ESP-NOW has opened pathways to innovative applications such as:

– Home Automation: Wirelessly control lights, appliances, and thermostats.
– Remote Sensing: Deploy sensors in agriculture, monitoring environmental conditions.
– Системы безопасности: Create robust, scalable networks for alarms and surveillance.

Заключение

Embarking on an ESP-NOW project allows developers to explore the full potential of ESP32 devices. By mastering this communication protocol, you can craft sophisticated, wireless networks that are energy-efficient and highly responsive. This ESP-NOW tutorial provides a foundational understanding, enabling you to develop solutions tailored to a diverse set of needs. Whether you’re automating your home or setting up remote sensors, ESP-NOW offers a flexible and reliable platform.

======================================

О сайте ESP32S.com

С 2016 года, ESP32S.com Наша компания превратилась в полноценного партнера по экосистеме для вашего развития в сфере Интернета вещей. Расположенная в Шэньчжэне, глобальном центре инноваций в электронике, мы помогли сотням разработчиков и компаний реализовать свои проекты. ESP32Воплощаем идеи в жизнь. Наша команда стремится оказывать исключительную поддержку и предлагать инновационные решения, которые помогут вам достичь ваших целей в области Интернета вещей.
В ESP32S.com, мы осваиваем тонкости разработки ESP32Разработка продукта, основанного на концепции, включает в себя множество этапов, от разработки до вывода на рынок. Именно поэтому мы предлагаем комплексные решения, охватывающие весь жизненный цикл продукта. ESP32Устройства на базе [технологии]. Независимо от того, нужна ли вам помощь в проектировании печатных плат, создании прототипов, производстве или даже маркетинге и доставке, мы вам поможем.

Свяжитесь с нами

Готовы вывести свой IoT-проект на новый уровень? Свяжитесь с ESP32S.com Узнайте больше о наших комплексных решениях уже сегодня! ESP32Устройства на базе [технологии]. Позвольте нам стать вашим надежным партнером в воплощении ваших инновационных идей в жизнь. Свяжитесь с нами прямо сейчас для начала.