Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Revija za univerzalno odličnost / Journal of Universal Excellence, Članek / Article

Februar / February 2021, leto / year 6, številka / number 1, str. / pp. 53-60.

DOI: 10.37886/ip.2021.019

ESP-NOW communication protocol with ESP32

Roberto Pasic*
Faculty of Technical Sciences Bitola, Makedonska falanga no. 37, Bitola, North Macedonia
[email protected]

Ivo Kuzmanov
Faculty of Technical Sciences Bitola, Makedonska falanga no. 37, Bitola, North Macedonia
[email protected]

Kokan Atanasovski
Faculty of Technical Sciences Bitola, Makedonska falanga 37, 7000, Bitola, North Macedonia
[email protected]

Abstract:
Purpose and Originality: The main problem in data acquisition from different sensor nodes is the
lack of access to a local wireless network. The purpose of this paper is to present the possibilities
offered by the ESP-NOW communication protocol on the development board ESP32 from
Espressif (1).
Method: For this paper we used quantitative method. 3 wireless communication modules are used
that exchange information from 3 different sensor nodes.
Results: The used system provides data retrieval from sensor nodes in conditions of non-existence
of local internet network, with satisfactory communication distance (190m).
Society: Тhis type of devices is especially useful for use in systems for measurement of data
acquisition from environmental protection systems.
Limitations / further research: Direction for further research: a system change is recommended
in order to increase the achieved distances of Wi-Fi information exchange

Keywords: Data acquisition, Measurement, Development board, MCU, ESP32, ESP-NOW.

1 Introduction
Today's measuring and acquisition systems are in widespread use, for example measuring
systems for process control in various production plants, measuring systems for measuring air
quality, measuring systems for traffic management…Characteristic problem for all of them is
the storage of the measured data, especially when there is a need for real time measurements
and display data. Wireless communication offers almost unlimited possibilities for collecting
measured data.

* Korespondenčni avtor / Correspondence author 53


Prejeto: 15. september 2020; revidirano: 22. oktober 2020; sprejeto: 1. december 2020. /
Received: 15th September 2020; revised: 22nd October 2020; accepted: 1st December 2020.
Revija za univerzalno odličnost / Journal of Universal Excellence, Članek / Article
Februar / February 2021, leto / year 6, številka / number 1, str. / pp. 53-60.

2 Theoretical framework
Espressif Systems (688018.SH) is a public multinational, fabless semiconductor company
established in 2008, with offices in China, the Czech Republic, India, Singapore and Brazil,
with team of engineers and scientists from all over the world, focused on developing cutting-
edge Wi-Fi-and-Bluetooth, low-power, AIoT solutions. They created the popular ESP8266,
ESP32 and ESP32-S series of chips, modules and development boards. Published papers
covering this area are rare worldwide.

3 Method
For this paper we used quantitative method. 3 wireless communication modules are used that
exchange information from 3 different sensor nodes. ESP-NOW is a connectionless Wi-Fi
communication protocol that is defined by Espressif [1]. Application data in ESP-NOW is
encapsulated in a specific action frame and then transmitted from one Wi-Fi device to another
without connection. CTR with CBC-MAC Protocol (CCMP) is used to protect the action
frame for security. ESP-NOW supports the following features (2):
- Encrypted and unencrypted unicast communication,
- Mixed encrypted and unencrypted peer devices,
- Up to 250-byte payload can be carried,
- The sending callback function that can be set to inform the application layer of
transmission success or failure.

ESP-NOW technology also has the following limitations:


- Broadcast is not supported,
- Limited encrypted peers. 10 encrypted peers at the most are supported in Station
mode; 6 at the most in SoftAP or SoftAP + Station mode. Multiple unencrypted peers
are supported, however, their total number should be less than 20, including encrypted
peers,
- Payload is limited to 250 bytes.

The default ESP-NOW bit rate is 1 Mbps. The format of the vendor-specific action frame is
as follows:

Figure 1. Format of the specific action frame

- Category Code: The Category Code field is set to the value (127) indicating the
vendor-specific category.

54
Revija za univerzalno odličnost / Journal of Universal Excellence, Članek / Article
Februar / February 2021, leto / year 6, številka / number 1, str. / pp. 53-60.

- Organization Identifier: The Organization Identifier contains a unique identifier


(0x18fe34), which is the first three bytes of MAC address applied by Espressif.
- Random Value: The Random Value filed is used to prevents relay attacks.
- Vendor Specific Content: The Vendor Specific Content contains vendor-specific
fields as follows:

Figure 2. Vendor-specific fields

- Element ID: The Element ID field is set to the value (221), indicating the vendor-
specific element.
- Length: The length is the total length of Organization Identifier, Type, Version and
Body.
- Organization Identifier: The Organization Identifier contains a unique
identifier(0x18fe34), which is the first three bytes of MAC address applied by
Espressif.
- Type: The Type field is set to the value (4) indicating ESP-NOW.
- Version: The Version field is set to the version of ESP-NOW.
- Body: The Body contains the ESP-NOW data.

As ESP-NOW is connectionless, the MAC header is a little different from that of standard
frames. The FromDS and ToDS bits of FrameControl field are both 0. The first address field
is set to the destination address. The second address field is set to the source address. The
third address field is set to broadcast address (0xff:0xff:0xff:0xff:0xff:0xff). ESP-NOW uses
the CCMP method, which is described in IEEE Std. 802.11-2012, to protect the vendor-
specific action frame. The Wi-Fi device maintains a Primary Master Key (PMK) and several
Local Master Keys (LMK). The lengths of both PMK and LMk are 16 bytes.
ESP-NOW allows to exchange data between several ESP32 boards programmed with
Arduono IDE. Multiple devices can tock to each other in an easy way.

55
Revija za univerzalno odličnost / Journal of Universal Excellence, Članek / Article
Februar / February 2021, leto / year 6, številka / number 1, str. / pp. 53-60.

Figure 3. ESP-NOW one-way communication protocol

After pairing a device with each other, the connection is persistent. It very important to know,
if suddenly one of your boards loses power or resets, when it restarts, it will automatically
connect to its peer to continue the communication.

Figure 4. ESP-NOW two-way communication protocol

4 Results
In order to be able to communicate between multiple ESP32 via ESP-NOW, it is essential to
know the ESP32 receiver MAC address. In this way it is determined which ESP32 node will
receive the data. Each ESP32 board has unique MAC address.

Sender sketch must include:


- Initialize ESP-NOW;
- Register a callback function upon sending data;
- Add a peer device (the receiver with MAC address);
- Send a message to the peer device.

Receiver sketch must include:


- Initialize ESP-NOW;
- Register for a receive callback function.
-
Inside that callback function save the message into a variable to execute any task with that
information.

In our case, we test communication range between ESP32 boards, and we have stable
communication up to 190 meters in open field.

56
Revija za univerzalno odličnost / Journal of Universal Excellence, Članek / Article
Februar / February 2021, leto / year 6, številka / number 1, str. / pp. 53-60.

Figure 5. ESP-NOW communication range

5 Discussion
In our case, it has been tested ESP-NOW one-way communication protocol between two
senders and one receiver ESP32 boards. Each sender has a combined sensor for measuring
temperature and relative humidity based on AM2301.

Figure 6. AM2301 temp/hum sensor

In order to be able to communicate between multiple ESP32 via ESP-NOW, it is essential to


know the ESP32 receiver MAC address.

57
Revija za univerzalno odličnost / Journal of Universal Excellence, Članek / Article
Februar / February 2021, leto / year 6, številka / number 1, str. / pp. 53-60.

Figure 7. Two senders and on receiver ESP32 boards in one-way ESP-NOW comm. protocol

Figure.8. Arduino IDE serial monitor from receiver ESP32 board

58
Revija za univerzalno odličnost / Journal of Universal Excellence, Članek / Article
Februar / February 2021, leto / year 6, številka / number 1, str. / pp. 53-60.

6 Conclusion
ESP-NOW communication protocol from Espressif will greatly alleviate the problems of
retrieving the measured data from sensor nodes placed in environments where there is no
possibility to connect to a local wireless network. Robust design, ultra-low power
consuptation, high level of integration and hibrid wifi and bluetooth chip on ESP32 MCU are
ideal features of a platform for solving complex problems in real measurement systems and
data acquisition from sensor node groups.

References
1. Espressif (homepage). Retrieved from espressif.com/en
2. ESP-IDF Programming Guide - ESP32. ESP-IDF Programming Guide latest documentation.
Retrieved from https://docs.espressif.com/projects/esp-idf/en/latest/esp32/
3. Getting Started with ESP-NOW (ESP32 with Arduino IDE). Random Nerd Tutorials. Retrieved
from https://randomnerdtutorials.com/esp-now-esp32-arduino-ide/
4. HM2301 Digital-output humidity and temperature sensor. Temperature / Humidity module
AM2301. Retrieved from https://mikroshop.ch/pdf/DHT21.pdf
5. Kuzmanov, I., & Pasic, R. (2019). Real impact of the microclima changes to workers wo circulate
from hot to cold chambers – a part from an extensive research into industrial entity. Temel
International Journal, Vol.3., Iss.2.

***
Roberto Pasic is Associate Professor, Faculty of Technical Sciences Bitola, Head of Mechatronics Department.
Area of interest: MCU based sensor systems, data analysis and environmental protection.

***
Ivo Kuzmanov is Associate Professor, Faculty of Technical Sciences Bitola, Head of Industrial Engineering and
Management Department. Area of interest: Quality control, FMEA, data analysis, environmental protection.

***
Kokan Atanasovski is BSc. student, Faculty of Technical Sciences Bitola, Mechatronics Department. Area of
interest: Robotics, PLC, MCU based sensor systems, data analysis and environmental protection.

***

Povzetek:
ESP-ZDAJ komunikacijski protokol z ESP32

Namen in izvirnost: Glavna težava pri pridobivanju podatkov iz različnih vozlišč senzorjev je
pomanjkanje dostopa do lokalnega brezžičnega omrežja. Namen tega prispevka je predstaviti
možnosti, ki jih ponuja komunikacijski protokol ESP-NOW na razvojni plošči ESP32 podjetja
Espressif.
Metoda: V prispevku smo uporabili kvantitativno metodo. Uporabljajo se trije brezžični
komunikacijski moduli, ki si izmenjujejo informacije iz treh različnih vozlišč senzorjev.
Rezultati: Uporabljeni sistem omogoča pridobivanje podatkov s senzorskih vozlišč v pogojih
neobstoja lokalnega internetnega omrežja z zadovoljivo komunikacijsko razdaljo (190 m).

59
Revija za univerzalno odličnost / Journal of Universal Excellence, Članek / Article
Februar / February 2021, leto / year 6, številka / number 1, str. / pp. 53-60.

Družba: Ta vrsta naprav je še posebej uporabna za uporabo v sistemih za merjenje pridobivanja


podatkov iz sistemov za varstvo okolja.
Omejitve / nadaljnje raziskave: Za povečanje dosežene razdalje izmenjave informacij Wi-Fi je
priporočljiva sistemska sprememba.

Ključne besede: zajem podatkov, merjenje, razvojna plošča, MCU, ESP32, ESP-ZDAJ.

Copyright (c) Roberto PASIC, Ivo KUZMANOV, Kokan ATANASOVSKI

Creative Commons License


This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

60

You might also like