ESP-NOW
by Edi · 06/05/2024
The ESP-NOW network
ESP-NOW is a connectionless communication protocol developed by Espressif that enables short packet transmission using the 2.4 GHz band. With this protocol, up to twenty ESP8266 or ESP32 can easily communicate with each other and exchange messages of up to 250 bytes. Each board can be used with ESP-NOW as a receiver, transmitter or trans-receiver and ranges of up to 400 meters can be achieved with antennas. With the built-in antennas, communication in a medium-sized house should be possible without any problems.
Pairing is required before communication between the devices. After pairing, the connection is secure without the need for a handshake. If one of the boards suddenly loses power or is reset, it will automatically connect to its counterpart after restarting to continue communication.
The data can be unidirectional or bidirectional, i.e. single-duplex or full-duplex, and most data types are supported.
Data can be transmitted encrypted or unencrypted and no external Wi-Fi source or router is required.
Der IC besteht aus einer Widerstandsreihe mit 99 temperaturkompensierte resistor elements and a wiper switching network. There are contact points between the individual elements and at both ends, which are accessible for the wiper connection. The position of the wiper element is controlled by the CS, U/D and INC inputs.
The position of the slider can be stored in a non-volatile memory and recalled at a later switch-on process.
There are four different types, which differ in their resistance value.
The digital potentiometer is used to regulate voltages, settings and trimming in various circuits.
ESP-NOW network modes
We have the possibility to set up the ESP-NOW network in many configurations and can mix ESP8266 and ESP32 in it.
Each device that participates in an ESP-NOW network can be operated in one of two modes.
Initiator – dieses Gerät initiiert die Übertragung. Dazu benötigt es die MAC-Adresse des empfangenden Geräts.
Responder - This device receives the transmission.
In unidirectional (half-duplex) mode, the sending device is the initiator and the receiving device is the responder.
In a 2-way communication mode (full duplex), each device is both initiator and responder.
Let's now take a closer look at the possible networks.
One-way communication
The simplest communication topology is one-way, unidirectional communication. In this arrangement, the initiator (sender) sends data to the responder (receiver).
One transmitter and multiple receivers
In this setup, the sender can send data directly to a receiver or send a broadcast message to all receivers.
One receiver and multiple transmitters
In this network, we have several transmitters, such as sensors, which send data to a receiver.
Two-way network
In this bidirectional or full-duplex network, each module can send and receive data.
The MAC address
The MAC address, also known as the Media Access Control address, is a unique identifier that is assigned to network devices. It consists of a 48-bit number and is usually represented in 6-digit hexadecimal form. The MAC address is defined at the hardware level of a network device and uniquely identifies this device in a network. However, we can also set the MAC address on the software side.
To be able to read the MAC address of our microcontrollers, this short sketch is used, which writes the MAC address to the serial monitor.
#include // for ESP32 boards
//#include // for ESP8266 boards
void setup(){
Serial.begin(115200);
delay(1000);
Serial.print("MAC-Address: ");
Serial.println(WiFi.macAddress());
}
void loop(){}
Practice example
In the first example, we use an Arduino Nano ESP32 to send a signal when the button is pressed. In the second ESP, we then switch the LED on as long as the button is pressed. When the button is released, the LED is also switched off again. Of course, we use the ESP-NOW protocol to transmit the data.