{"id":97190,"date":"2020-06-01T10:55:28","date_gmt":"2020-06-01T10:55:28","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=97190"},"modified":"2020-07-30T14:01:16","modified_gmt":"2020-07-30T14:01:16","slug":"esp-now-two-way-communication-esp8266-nodemcu","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp-now-two-way-communication-esp8266-nodemcu\/","title":{"rendered":"ESP-NOW Two-Way Communication Between ESP8266 NodeMCU Boards"},"content":{"rendered":"\n<p>Learn how to establish a two-way communication between two ESP8266 NodeMCU boards using ESP-NOW communication protocol. As an example, two ESP8266 boards will exchange DHT sensor readings. We&#8217;ll use Arduino IDE.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP-NOW-ESP8266-NodeMCU-EXPLAINED-Easiest-Wireless-Communication-Between-ESP8266-Boards.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-NOW Two-Way Communication Between ESP8266 NodeMCU Boards\" class=\"wp-image-97249\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP-NOW-ESP8266-NodeMCU-EXPLAINED-Easiest-Wireless-Communication-Between-ESP8266-Boards.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP-NOW-ESP8266-NodeMCU-EXPLAINED-Easiest-Wireless-Communication-Between-ESP8266-Boards.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP-NOW-ESP8266-NodeMCU-EXPLAINED-Easiest-Wireless-Communication-Between-ESP8266-Boards.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP-NOW-ESP8266-NodeMCU-EXPLAINED-Easiest-Wireless-Communication-Between-ESP8266-Boards.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p>We have other tutorials about ESP-NOW with the ESP8266:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp-now-two-way-communication-esp8266-nodemcu\/\"><\/a><a href=\"https:\/\/randomnerdtutorials.com\/esp-now-esp8266-nodemcu-arduino-ide\/\">Getting Started with ESP-NOW (ESP8266 NodeMCU with Arduino IDE)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp-now-one-to-many-esp8266-nodemcu\/\">ESP-NOW with ESP8266: Send Data to Multiple Boards (one-to-many)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp-now-many-to-one-esp8266-nodemcu\/\">ESP-NOW with ESP8266: Receive Data from Multiple Boards (many-to-one)<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Introducing ESP-NOW<\/h2>\n\n\n\n<p><strong><a href=\"https:\/\/randomnerdtutorials.com\/esp-now-esp8266-nodemcu-arduino-ide\/\">ESP-NOW<\/a><\/strong>&nbsp;is a connectionless communication protocol developed by Espressif that features short packet transmission. This protocol enables multiple devices to talk to each other without using Wi-Fi.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/esp-now-logo.png?resize=244%2C61&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-NOW - ESP32 Logo\" class=\"wp-image-93360\" width=\"244\" height=\"61\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/esp-now-logo.png?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/esp-now-logo.png?resize=300%2C75&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/esp-now-logo.png?resize=1024%2C256&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/esp-now-logo.png?resize=768%2C192&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 244px) 100vw, 244px\" \/><\/figure><\/div>\n\n\n\n<p>This is a fast communication protocol that can be used to exchange small messages (up to 250 bytes) between ESP32 boards. ESP-NOW is very versatile and you can have one-way or two-way communication in different arrangements.<\/p>\n\n\n\n<p>In this tutorial, we\u2019ll show you how to establish a two-way communication between two ESP8266 boards.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"340\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/02\/ESP8266-ESP-NOW-Two-Way-Communication.png?resize=750%2C340&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-NOW ESP8266 Two-Way Communication\" class=\"wp-image-93802\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/02\/ESP8266-ESP-NOW-Two-Way-Communication.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/02\/ESP8266-ESP-NOW-Two-Way-Communication.png?resize=300%2C136&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Project Overview<\/h2>\n\n\n\n<p>The following diagram shows an overview of the project we&#8217;ll build:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"435\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP8266-ESP-NOW-Two-Way-DHT-Readings-Overview.png?resize=872%2C435&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 ESP-NOW Two-Way Communication Exchange DHT Sensor Readings\" class=\"wp-image-97194\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP8266-ESP-NOW-Two-Way-DHT-Readings-Overview.png?w=872&amp;quality=100&amp;strip=all&amp;ssl=1 872w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP8266-ESP-NOW-Two-Way-DHT-Readings-Overview.png?resize=300%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP8266-ESP-NOW-Two-Way-DHT-Readings-Overview.png?resize=768%2C383&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 872px) 100vw, 872px\" \/><\/figure><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>In this project we\u2019ll have two ESP8266 boards. Each board is connected to a DHT sensor;<\/li><li>Each board gets temperature and humidity readings from their corresponding sensors;<\/li><li>Each board sends its readings to the other board via ESP-NOW;<\/li><li>When a board receives the readings, it prints them on the Serial Monitor. You can connect an OLED display to visualize the readings, for example.<\/li><li>When a message is sent, a message is printed indicating if the packet was successfully delivered or not.<\/li><li>Each board needs to know the other board MAC address in order to send the message.<\/li><\/ul>\n\n\n\n<p>In this example, we\u2019re using a two-way communication between two boards, but you can add more boards to this setup, and having all boards communicating with each other.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Before proceeding with this project, make sure you check the following prerequisites.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ESP8266 add-on Arduino IDE<\/h3>\n\n\n\n<p>We\u2019ll program the ESP8266 using Arduino IDE, so before proceeding with this tutorial you should have the ESP8266 add-on installed in your Arduino IDE. Follow the next guide:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/how-to-install-esp8266-board-arduino-ide\/\">Installing the ESP8266 Board in Arduino IDE (Windows, Mac OS X, and Linux)<\/a><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Installing DHT Libraries<\/h3>\n\n\n\n<p>To read from the DHT sensor, we\u2019ll use the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/adafruit\/DHT-sensor-library\" target=\"_blank\">DHT library from Adafruit<\/a>. To use this library you also need to install the&nbsp;<a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit Unified Sensor library<\/a>. Follow the next steps to install those libraries.<\/p>\n\n\n\n<p>1. Open your Arduino IDE and go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong>. The Library Manager should open.<\/p>\n\n\n\n<p>2. Search for \u201c<strong>DHT<\/strong>\u201d on the Search box and install the DHT library from Adafruit.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/adafruit_dht_library.png?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing Adafruit DHT library\" class=\"wp-image-84293\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/adafruit_dht_library.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/adafruit_dht_library.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>3. After installing the DHT library from Adafruit, type \u201c<strong>Adafruit Unified Sensor<\/strong>\u201d in the search box. Scroll all the way down to find the library and install it.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/adafruit_unified_sensor_library.png?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing Adafruit Unified Sensor driver library\" class=\"wp-image-84295\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/adafruit_unified_sensor_library.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/adafruit_unified_sensor_library.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>After installing the libraries, restart your Arduino IDE.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Parts Required<\/h3>\n\n\n\n<p>For this tutorial you need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>2x <a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\" target=\"_blank\">ESP8266 development board<\/a>&nbsp;(read&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/best-esp8266-wi-fi-development-board\/\" target=\"_blank\">ESP8266 development boards comparison<\/a>)<\/li><li>2x <a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/dht22-temperature-humidity-sensor\/\" target=\"_blank\">DHT22<\/a>&nbsp;or&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/dht11-temperature-humidity-sensor\/\" target=\"_blank\">DHT11<\/a>&nbsp;Temperature and Humidity Sensor<\/li><li>2x <a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\">4.7k Ohm Resistor<\/a><\/li><li>2x <a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\">Breadboard<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\">Jumper wires<\/a><\/li><\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting the Boards MAC Address<\/h2>\n\n\n\n<p>To send messages between each board, we need to know&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/get-change-esp32-esp8266-mac-address-arduino\/\">their MAC address<\/a>. Each board has a unique MAC address (learn how to&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/get-change-esp32-esp8266-mac-address-arduino\/\">Get and Change the ESP32 MAC Address<\/a>).<\/p>\n\n\n\n<p>Upload the following code to each of your boards to get their MAC address.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/get-change-esp32-esp8266-mac-address-arduino\/\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.  \n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*\/\n#include &lt;WiFi.h&gt;\n#include &lt;esp_wifi.h&gt;\n\nvoid readMacAddress(){\n  uint8_t baseMac[6];\n  esp_err_t ret = esp_wifi_get_mac(WIFI_IF_STA, baseMac);\n  if (ret == ESP_OK) {\n    Serial.printf(&quot;%02x:%02x:%02x:%02x:%02x:%02x\\n&quot;,\n                  baseMac[0], baseMac[1], baseMac[2],\n                  baseMac[3], baseMac[4], baseMac[5]);\n  } else {\n    Serial.println(&quot;Failed to read MAC address&quot;);\n  }\n}\n\nvoid setup(){\n  Serial.begin(115200);\n\n  WiFi.mode(WIFI_STA);\n  WiFi.STA.begin();\n\n  Serial.print(&quot;[DEFAULT] ESP32 Board MAC Address: &quot;);\n  readMacAddress();\n}\n \nvoid loop(){\n\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/ESP32_Get_MAC_Address.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>After uploading the code, press the RST\/EN button, and the MAC address should be displayed on the Serial Monitor.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"320\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/Get-ESP8266-MAC-Address-Serial-Monitor.jpg?resize=666%2C320&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Get ESP8266 MAC Address Serial Monitor\" class=\"wp-image-97196\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/Get-ESP8266-MAC-Address-Serial-Monitor.jpg?w=666&amp;quality=100&amp;strip=all&amp;ssl=1 666w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/Get-ESP8266-MAC-Address-Serial-Monitor.jpg?resize=300%2C144&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/figure><\/div>\n\n\n\n<p>Write down the MAC address of each board to clearly identify them.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP8266-NodeMCU-board-MAC-Address.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU board Get MAC Address\" class=\"wp-image-97272\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP8266-NodeMCU-board-MAC-Address.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP8266-NodeMCU-board-MAC-Address.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">ESP8266 and DHT11\/DHT22 Schematic Diagram<\/h2>\n\n\n\n<p>Before proceeding with the tutorial, wire the DHT11 or DHT22 temperature and humidity sensor to the ESP8266 as shown in the following schematic diagram.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/esp8266-dht.png?resize=482%2C620&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 DHT11 DHT22 Schematic Diagram Circuit\" class=\"wp-image-86097\" width=\"482\" height=\"620\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/esp8266-dht.png?w=642&amp;quality=100&amp;strip=all&amp;ssl=1 642w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/esp8266-dht.png?resize=233%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 233w\" sizes=\"(max-width: 482px) 100vw, 482px\" \/><\/figure><\/div>\n\n\n\n<p>In this example, we\u2019re wiring the DHT data pin to&nbsp;GPIO5&nbsp;(D1), but you can use any other suitable GPIO. Read our&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/esp8266-pinout-reference-gpios\/\">ESP8266 GPIO Reference Guide<\/a>&nbsp;to learn more about the ESP8266 GPIOs.<\/p>\n\n\n\n<p class=\"rntbox rntclblue\">You might like: <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-dht11dht22-temperature-and-humidity-web-server-with-arduino-ide\/\">ESP8266 DHT11\/DHT22 Temperature and Humidity Web Server with Arduino IDE<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ESP8266 Two-Way Communication ESP-NOW Code<\/h2>\n\n\n\n<p>Upload the following code to each of your boards. Before uploading the code, you need to enter the MAC address of the other board (the board you\u2019re sending data to).<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp-now-two-way-communication-esp8266-nodemcu\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files.\n  \n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n*\/\n\n#include &lt;ESP8266WiFi.h&gt;\n#include &lt;espnow.h&gt;\n\n#include &lt;Adafruit_Sensor.h&gt;\n#include &lt;DHT.h&gt;\n\n\/\/ REPLACE WITH THE MAC Address of your receiver \nuint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};\n\n\/\/ Digital pin connected to the DHT sensor\n#define DHTPIN 5    \n\n\/\/ Uncomment the type of sensor in use:\n\/\/#define DHTTYPE    DHT11     \/\/ DHT 11\n#define DHTTYPE    DHT22     \/\/ DHT 22 (AM2302)\n\/\/#define DHTTYPE    DHT21     \/\/ DHT 21 (AM2301)\n\nDHT dht(DHTPIN, DHTTYPE);\n\n\/\/ Define variables to store DHT readings to be sent\nfloat temperature;\nfloat humidity;\n\n\/\/ Define variables to store incoming readings\nfloat incomingTemp;\nfloat incomingHum;\n\n\/\/ Updates DHT readings every 10 seconds\nconst long interval = 10000; \nunsigned long previousMillis = 0;    \/\/ will store last time DHT was updated \n\n\/\/ Variable to store if sending data was successful\nString success;\n\n\/\/Structure example to send data\n\/\/Must match the receiver structure\ntypedef struct struct_message {\n    float temp;\n    float hum;\n} struct_message;\n\n\/\/ Create a struct_message called DHTReadings to hold sensor readings\nstruct_message DHTReadings;\n\n\/\/ Create a struct_message to hold incoming sensor readings\nstruct_message incomingReadings;\n\n\/\/ Callback when data is sent\nvoid OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {\n  Serial.print(&quot;Last Packet Send Status: &quot;);\n  if (sendStatus == 0){\n    Serial.println(&quot;Delivery success&quot;);\n  }\n  else{\n    Serial.println(&quot;Delivery fail&quot;);\n  }\n}\n\n\/\/ Callback when data is received\nvoid OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {\n  memcpy(&amp;incomingReadings, incomingData, sizeof(incomingReadings));\n  Serial.print(&quot;Bytes received: &quot;);\n  Serial.println(len);\n  incomingTemp = incomingReadings.temp;\n  incomingHum = incomingReadings.hum;\n}\n\nvoid getReadings(){\n  \/\/ Read Temperature\n  temperature = dht.readTemperature();\n  \/\/ Read temperature as Fahrenheit (isFahrenheit = true)\n  \/\/float t = dht.readTemperature(true);\n  if (isnan(temperature)){\n    Serial.println(&quot;Failed to read from DHT&quot;);\n    temperature = 0.0;\n  }\n  humidity = dht.readHumidity();\n  if (isnan(humidity)){\n    Serial.println(&quot;Failed to read from DHT&quot;);\n    humidity = 0.0;\n  }\n}\n\nvoid printIncomingReadings(){\n  \/\/ Display Readings in Serial Monitor\n  Serial.println(&quot;INCOMING READINGS&quot;);\n  Serial.print(&quot;Temperature: &quot;);\n  Serial.print(incomingTemp);\n  Serial.println(&quot; \u00baC&quot;);\n  Serial.print(&quot;Humidity: &quot;);\n  Serial.print(incomingHum);\n  Serial.println(&quot; %&quot;);\n}\n \nvoid setup() {\n  \/\/ Init Serial Monitor\n  Serial.begin(115200);\n\n  \/\/ Init DHT sensor\n  dht.begin();\n \n  \/\/ Set device as a Wi-Fi Station\n  WiFi.mode(WIFI_STA);\n  WiFi.disconnect();\n\n  \/\/ Init ESP-NOW\n  if (esp_now_init() != 0) {\n    Serial.println(&quot;Error initializing ESP-NOW&quot;);\n    return;\n  }\n\n  \/\/ Set ESP-NOW Role\n  esp_now_set_self_role(ESP_NOW_ROLE_COMBO);\n\n  \/\/ Once ESPNow is successfully Init, we will register for Send CB to\n  \/\/ get the status of Trasnmitted packet\n  esp_now_register_send_cb(OnDataSent);\n  \n  \/\/ Register peer\n  esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 1, NULL, 0);\n  \n  \/\/ Register for a callback function that will be called when data is received\n  esp_now_register_recv_cb(OnDataRecv);\n}\n \nvoid loop() {\n  unsigned long currentMillis = millis();\n  if (currentMillis - previousMillis &gt;= interval) {\n    \/\/ save the last time you updated the DHT values\n    previousMillis = currentMillis;\n\n    \/\/Get DHT readings\n    getReadings();\n\n    \/\/Set values to send\n    DHTReadings.temp = temperature;\n    DHTReadings.hum = humidity;\n\n    \/\/ Send message via ESP-NOW\n    esp_now_send(broadcastAddress, (uint8_t *) &amp;DHTReadings, sizeof(DHTReadings));\n\n    \/\/ Print incoming readings\n    printIncomingReadings();\n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266\/ESP_NOW\/ESP_NOW_Two_Way.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Code Works<\/h2>\n\n\n\n<p>Keep reading to learn how the code works, or skip to the Demonstration section.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Import libraries<\/h3>\n\n\n\n<p>Start by importing the required libraries.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;ESP8266WiFi.h>\n#include &lt;espnow.h><\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">espnow.h<\/span> library comes installed by default when you install the ESP8266 board. When compiling the code, make sure you have an ESP8266 board selected in the Boards menu.<\/p>\n\n\n\n<p>Include the DHT libraries to read from the DHT sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;Adafruit_Sensor.h>\n#include &lt;DHT.h><\/code><\/pre>\n\n\n\n<p>In the next line, insert the MAC address of the receiver board:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>uint8_t broadcastAddress&#091;] = {0x2C, 0x3A, 0xE8, 0x0E, 0xBB, 0xED};<\/code><\/pre>\n\n\n\n<p>Define the GPIO the DHT pin is connected to. In this case, it is connected to <span class=\"rnthl rntcblue\">GPIO 5<\/span> (D1).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define DHTPIN 5    <\/code><\/pre>\n\n\n\n<p>Then, select the DHT sensor type you\u2019re using. In our example, we\u2019re using the DHT22. If you\u2019re using another type, you just need to uncomment your sensor and comment all the others.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/#define DHTTYPE    DHT11     \/\/ DHT 11\n#define DHTTYPE    DHT22     \/\/ DHT 22 (AM2302)\n\/\/#define DHTTYPE    DHT21     \/\/ DHT 21 (AM2301)<\/code><\/pre>\n\n\n\n<p>Instantiate a&nbsp;<span class=\"rnthl rntliteral\">DHT<\/span> object with the type and pin defined earlier.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>DHT dht(DHTPIN, DHTTYPE);<\/code><\/pre>\n\n\n\n<p>Define variables to store the DHT readings to be sent:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float temperature;\nfloat humidity;<\/code><\/pre>\n\n\n\n<p>Define more two variables to store incoming readings:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float incomingTemp;\nfloat incomingHum;<\/code><\/pre>\n\n\n\n<p>We&#8217;ll send DHT readings via ESP-NOW every 10 seconds. That period of time is defined in the <span class=\"rnthl rntliteral\">interval<\/span> variable. You can change that interval.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const long interval = 10000; \nunsigned long previousMillis = 0;    \/\/ will store last time DHT was updated <\/code><\/pre>\n\n\n\n<p>The following variable will store a success message if the readings are delivered successfully to the other board.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Variable to store if sending data was successful\nString success;<\/code><\/pre>\n\n\n\n<p>Create a structure that stores temperature and humidity readings.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>typedef struct struct_message {\n    float temp;\n    float hum;\n} struct_message;<\/code><\/pre>\n\n\n\n<p>Then, you need to create two instances of that structure. One to receive the readings and another to store the readings to be sent.<\/p>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">DHTReadings<\/span> will store the readings to be sent.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>struct_message DHTReadings;<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">incomingReadings<\/span> will store the data coming from the other board.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>struct_message incomingReadings;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">OnDataSent() callback function<\/h3>\n\n\n\n<p>The&nbsp;<span class=\"rnthl rntliteral\">OnDataSent()<\/span>&nbsp;function will be called when new data is sent. This function simply prints if the message was successfully delivered or not. <\/p>\n\n\n\n<p>If the message is delivered successfully, the status variable returns <span class=\"rnthl rntliteral\">0<\/span>, so we can set our success message to&nbsp;<span class=\"rnthl rntliteral\">\u201cDelivery Success\u201d<\/span>:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {\n  Serial.print(\"Last Packet Send Status: \");\n  if (sendStatus == 0){\n    Serial.println(\"Delivery success\");\n  }<\/code><\/pre>\n\n\n\n<p>If the success message returns <span class=\"rnthl rntliteral\">1<\/span>, it means the delivery failed:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>else {\n  success = \"Delivery Fail :(\";\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">OnDataRecv() callback function<\/h3>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">OnDataRecv()<\/span> function is executed when a new packet arrives.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {<\/code><\/pre>\n\n\n\n<p>We save the new packet in the <span class=\"rnthl rntliteral\">incomingReadings<\/span> structure we\u2019ve created previously:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>memcpy(&amp;incomingReadings, incomingData, sizeof(incomingReadings));<\/code><\/pre>\n\n\n\n<p>We print the message length on the serial monitor. You can only send 250 bytes in each packet.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.print(\"Bytes received: \");\nSerial.println(len);<\/code><\/pre>\n\n\n\n<p>Then, store the incoming readings in their corresponding variables. To access the <span class=\"rnthl rntliteral\">temperature<\/span> variable inside <span class=\"rnthl rntliteral\">incomingReadings<\/span>structure, you just need to do call <span class=\"rnthl rntliteral\">incomingReadings.temp<\/span> as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>incomingTemp = incomingReadings.temp;<\/code><\/pre>\n\n\n\n<p>The same process is done for the humidity:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>incomingHum = incomingReadings.hum;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">getReadings()<\/h3>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">getReadings()<\/span> function gets temperature and humidity from the DHT sensor. The following line gets the current temperature and saves it in the <span class=\"rnthl rntliteral\">temperature<\/span> variable:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>temperature = dht.readTemperature();<\/code><\/pre>\n\n\n\n<p>This previous line returns the temperature in Celsius degrees. To get the temperature in Fahrenheit, comment the previous line and uncomment the following:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/float t = dht.readTemperature(true);<\/code><\/pre>\n\n\n\n<p>Sometimes, you&#8217;re not able to get readings from the sensor. When that happens the sensor returns <span class=\"rnthl rntliteral\">nan<\/span>. If that&#8217;s the case, we set the <span class=\"rnthl rntliteral\">temperature<\/span> to <span class=\"rnthl rntliteral\">0.0<\/span>.<\/p>\n\n\n\n<p>A similar process is done to get the humdity readings. The current humidity value is saved on the <span class=\"rnthl rntliteral\">humidity<\/span> variable:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>humidity = dht.readHumidity();\nif (isnan(humidity)){\n  Serial.println(\"Failed to read from DHT\");\n  humidity = 0.0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">printIncomingReadings()<\/h3>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">printIncomingReadings()<\/span> function simply prints the received readings on the Serial Monitor.<\/p>\n\n\n\n<p>The received temperature in saved on the <span class=\"rnthl rntliteral\">incomingTemp<\/span> variable and the received humidity is saved on the <span class=\"rnthl rntliteral\">incomingHum<\/span> variable as we&#8217;ll see in a moment.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void printIncomingReadings(){\n  \/\/ Display Readings in Serial Monitor\n  Serial.println(\"INCOMING READINGS\");\n  Serial.print(\"Temperature: \");\n  Serial.print(incomingTemp);\n  Serial.println(\" \u00baC\");\n  Serial.print(\"Humidity: \");\n  Serial.print(incomingHum);\n  Serial.println(\" %\");\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">setup()<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<p>Initialize the DHT sensor:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>dht.begin();<\/code><\/pre>\n\n\n\n<p class=\"language-c\">Set the ESP8266 as a station:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>WiFi.mode(WIFI_STA);\nWiFi.disconnect();<\/code><\/pre>\n\n\n\n<p>Initialize ESP-NOW:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (esp_now_init() != 0) {\n  Serial.println(\"Error initializing ESP-NOW\");\n  return;\n}<\/code><\/pre>\n\n\n\n<p>Set the ESP8266 ESP-NOW role. In this example, the ESP8266 receives and sends readings via ESP-NOW, so set the role to <span class=\"rnthl rntliteral\">ESP_NOW_ROLE_COMBO<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_now_set_self_role(ESP_NOW_ROLE_COMBO);<\/code><\/pre>\n\n\n\n<p>Then, register for the <span class=\"rnthl rntliteral\">OnDataSent<\/span> callback function.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code> esp_now_register_send_cb(OnDataSent);<\/code><\/pre>\n\n\n\n<p>In order to send data to another board, you need to pair it as a peer. The following line add a new peer.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 1, NULL, 0);<\/code><\/pre>\n\n\n\n<p>The&nbsp;<span class=\"rnthl rntliteral\">esp_now_add_peer()<\/span> function&nbsp;accepts the following arguments, in this order: mac address, peer role, wi-fi channel, key, and key length.<\/p>\n\n\n\n<p>Finally, register for the <span class=\"rnthl rntliteral\">OnDataRecv<\/span> callback function.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_now_register_recv_cb(OnDataRecv);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">loop()<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, check if it is time to get new readings:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>unsigned long currentMillis = millis();\nif (currentMillis - previousMillis >= interval) {\n  \/\/ save the last time you updated the DHT values\n  previousMillis = currentMillis;<\/code><\/pre>\n\n\n\n<p>If it is, call the <span class=\"rnthl rntliteral\">getReadings<\/span> function to read the current temperature and humidity.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>getReadings();<\/code><\/pre>\n\n\n\n<p>Then, update the <span class=\"rnthl rntliteral\">DHTReadings<\/span> structure with the new temperature and humidity values:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>DHTReadings.temp = temperature;\nDHTReadings.hum = humidity;<\/code><\/pre>\n\n\n\n<p>Send the structure via ESP-NOW:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_now_send(broadcastAddress, (uint8_t *) &amp;DHTReadings, sizeof(DHTReadings));<\/code><\/pre>\n\n\n\n<p>Finally, call the <span class=\"rnthl rntliteral\">printIncomingReadings()<\/span> function to print the incoming readings on the Serial Monitor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>printIncomingReadings();<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>After uploading the code to each board, open an Arduino IDE Serial Monitor window. Alternatively, you can open two different serial connections (using <a rel=\"noreferrer noopener\" href=\"https:\/\/www.putty.org\/\" target=\"_blank\">PuTTY<\/a>) to see the two boards interacting simultaneously.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"506\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP-NOW-ESP8266-NodeMCU-Board-Exchange-Sensor-Readings.jpg?resize=900%2C506&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-NOW ESP8266 NodeMCU Board Exchange Sensor Readings Arduino IDE\" class=\"wp-image-97273\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP-NOW-ESP8266-NodeMCU-Board-Exchange-Sensor-Readings.jpg?w=900&amp;quality=100&amp;strip=all&amp;ssl=1 900w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP-NOW-ESP8266-NodeMCU-Board-Exchange-Sensor-Readings.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP-NOW-ESP8266-NodeMCU-Board-Exchange-Sensor-Readings.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<p>As you can see, it is working as expected. Each board is printing the other board&#8217;s readings.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"825\" height=\"308\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP8266-ESP-NOW-Two-Way-Communication-exchange-sensor-readings.jpg?resize=825%2C308&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU board ESP-NOW Two-Way Communication exchange temperature humidity sensor readings\" class=\"wp-image-97277\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP8266-ESP-NOW-Two-Way-Communication-exchange-sensor-readings.jpg?w=825&amp;quality=100&amp;strip=all&amp;ssl=1 825w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP8266-ESP-NOW-Two-Way-Communication-exchange-sensor-readings.jpg?resize=300%2C112&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP8266-ESP-NOW-Two-Way-Communication-exchange-sensor-readings.jpg?resize=768%2C287&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial we\u2019ve shown you how to establish a two-way communication with two ESP8266 board using ESP-NOW. This is a very versatile communication protocol that can be used to send packets with up to 250 bytes. ESP-NOW communication protocol can also be used with ESP32 boards:&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/esp-now-esp32-arduino-ide\/\">Getting Started with ESP-NOW (ESP32 with Arduino IDE)<\/a>.<\/p>\n\n\n\n<p>As an example, we\u2019ve shown you the interaction between two boards, but you can add many boards to your setup. You just need to know the MAC address of the board you\u2019re sending data to. We&#8217;ll be publishing more tutorials about <a href=\"https:\/\/randomnerdtutorials.com\/esp-now-esp8266-nodemcu-arduino-ide\/\"><strong>ESP-NOW<\/strong><\/a>, so stay tuned.<\/p>\n\n\n\n<p>We hope you\u2019ve found this tutorial useful. To learn more about the ESP8266 board, make sure you take a look at our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\">Home Automation with ESP8266<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/micropython-programming-with-esp32-and-esp8266\/\">MicroPython Programming with ESP32 and ESP8266<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp8266\/\">More ESP8266 NodeMCU Projects<\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to establish a two-way communication between two ESP8266 NodeMCU boards using ESP-NOW communication protocol. As an example, two ESP8266 boards will exchange DHT sensor readings. We&#8217;ll use Arduino &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP-NOW Two-Way Communication Between ESP8266 NodeMCU Boards\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp-now-two-way-communication-esp8266-nodemcu\/#more-97190\" aria-label=\"Read more about ESP-NOW Two-Way Communication Between ESP8266 NodeMCU Boards\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":97249,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[265,214,246,300,240,264],"tags":[],"class_list":["post-97190","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp8266-project","category-esp8266","category-esp8266-arduino-ide","category-0-esp8266","category-esp8266-projects","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP-NOW-ESP8266-NodeMCU-EXPLAINED-Easiest-Wireless-Communication-Between-ESP8266-Boards.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/97190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=97190"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/97190\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/97249"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=97190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=97190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=97190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}