Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » ESP8266 to ESP8266 Communication : Ad hoc Networking
ESP8266 Projects IoT Projects

ESP8266 to ESP8266 Communication : Ad hoc Networking

Mamtaz AlamBy Mamtaz AlamUpdated:August 21, 20226 Comments4 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
esp8266 to esp8266 communication
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview: ESP8266 to ESP8266 communication

In this article, we are going to learn about ESP8266 to ESP8266 Communication using Ad hoc Networking. We will be sending data from one ESP8266 to another ESP8266 over Wi-Fi using an ad-hoc, device to device network, without using any WiFi Router. The concept is similar to the ESP8266 Mesh Networking.

On the Sender/Transmitter Side, we will interface DS18B20 Waterproof Temperature Sensor with NodeMCU ESP8266 12E Board. We will measure the surrounding temperature and send it to the Receiver Side. The Receiver Side consists of NodeMCU ESP8266 Board along with SSD1306 0.96″ I2C OLED Display. The OLED Display will display the received temperature on OLED Screen.

To run an Ad hoc Network we need a Web Server Library. The ESP8266WebServer library allows us to run an ESP8266 as a web server and also an access point. The webserver can process data received from a remote sensor over Wi-Fi without connecting the devices to a network or router. Thus using WeServer we can have ESP8266 to ESP8266 Communication.


Required Components

Following are the components required for making this project. All the components can be easily purchased from Amazon. The component purchase link is given below.

S.N.Components NameQuantityPurchase Links
1NodeMCU ESP82662Amazon | AliExpress
2DS18B20 Temperature Sensor1Amazon | AliExpress
30.96" I2C OLED Display1Amazon | AliExpress
4Resistor 4.7K1Amazon | AliExpress
5Connecting Wires10Amazon | AliExpress
6Breadboard2Amazon | AliExpress




What is Ad hoc Networking?

An ad hoc networking is a network that is composed of individual devices (ESP8266 in our cases) communicating with each other directly. Ad hoc networks are created between two or more wireless Nodemcu ESP8266 together, without the use of a wireless router or an access point. The multiple ESP8266 communicate directly with each other.

Ad hoc Networking

Ad hoc networks can be very helpful during meetings or in any location where a network doesn’t exist and where people need to share files. An ad hoc network can also be useful in situations where only one PC has Internet access and that access needs to be shared.


Ciruit Diagram & Connections

The ESP8266 to ESP8266 communication requires two or more circuits. In this example, we will use only two circuits. One circuit will be the sender or transmitter Circuit whereas the other circuit will be the Receiver Circuit.


Sender Circuit

ESP8266 Ad hoc Networking

On the sender side we have connected a DS18B20 Waterproof Temperature Sensor to NodeMCU ESP8266 Board. Connect its VCC to 3.3V & GND to GND. Similarly, connect its digital pin to the NodeMCU D2 pin. Connect a 4.7K Pull-up Resistor between digital pin & VCC Pin as shown in the image below.


Receiver Circuit

On the receiver side we have just connected 0.96″ SSD1306 I2C OLED Display with NodeMCU ESP8266 Board. Connect its VCC to 3.3V & GND to GND. Connect its SDA & SCL pin to D2 & D1 of NodeMCU.




Source Code/Program: ESP8266 to ESP8266 communication

Let us see the code for both the sender and receiver part. We will work on esp8266 mesh networking by creating ESP8266 access point and client.

First the code will require few Libraries. So download the libraries from the following links:

1. Adafruit_SSD1306 : https://github.com/adafruit/Adafruit_SSD1306
2. Adafruit_GFX : https://github.com/adafruit/Adafruit-GFX-Library
3. One Wire Library: https://github.com/PaulStoffregen/OneWire
4. Dallas Temperature Library: https://github.com/milesburton/Arduino-Temperature-Control-Library


Sender Code

1
2
const char *ssid = "Alexahome";
const char *password = "loranthus";

Make sure to change the WiFi SSID & Password in the above line.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
 
#define DS18B20 D2
 
OneWire ourWire(DS18B20);
DallasTemperature sensor(&ourWire);
 
const char *ssid = "Alexahome";
const char *password = "loranthus";
 
int temp = 0;        // value read from the DS18B20
 
void setup() {
  Serial.begin(115200);
  delay(10);
 
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}
 
void loop()
{
  // read the temperature value:
  sensor.requestTemperatures();
  temp = sensor.getTempCByIndex(0);
 
  Serial.print("Temperature: ");
  Serial.print(temp);
  Serial.println(" °C");
 
  char intToPrint[5];
  itoa(temp, intToPrint, 10); //integer to string conversion for OLED library
 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const char * host = "192.168.4.1";
  const int httpPort = 80;
 
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
 
  // We now create a URI for the request
  String url = "/data/";
  url += "?sensor_reading=";
  url += intToPrint;
 
  Serial.print("Requesting URL: ");
  Serial.println(url);
 
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }
 
  Serial.println();
  Serial.println("Closing connection");
  Serial.println();
  Serial.println();
  Serial.println();
 
  delay(500);
}


Receiver Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <U8g2lib.h>
 
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 5, /* data=*/ 4);
 
const char *ssid = "Alexahome";
const char *password = "loranthus";
 
ESP8266WebServer server(80);
 
void handleSentVar() {
  Serial.println("handleSentVar function called...");
  if (server.hasArg("sensor_reading")) { // this is the variable sent from the client
    Serial.println("Sensor reading received...");
 
    int readingInt = server.arg("sensor_reading").toInt();
    char readingToPrint[5];
    itoa(readingInt, readingToPrint, 10); //integer to string conversion for OLED library
    u8g2.firstPage();
    u8g2.drawUTF8(0, 64, readingToPrint);
    u8g2.nextPage();
 
    Serial.print("Reading: ");
    Serial.println(readingToPrint);
    Serial.println();
    server.send(200, "text/html", "Data received");
  }
}
 
void setup()
{
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");
 
  u8g2.begin();
  u8g2.setFont(u8g2_font_logisoso62_tn);
  u8g2.setFontMode(0);    // enable transparent mode, which is faster
 
  WiFi.softAP(ssid, password);
 
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/data/", HTTP_GET, handleSentVar);
  server.begin();
  Serial.println("HTTP server started");
 
}
 
void loop() {
  server.handleClient();
}



Result & Observations

Once the code is uploaded on the both sender and receiver circuit, press the rest button on both the ESP8266. Once rest button is pressed the Serial Monitor will show something like this.

esp8266 mesh networking

On both the section the ESP8266 will connect to the wifi Network & creates Access Point. The data is then transferred wirelessly via the same Web Server.

Now the temperature data is sent from one device to another device using ESP8266 Ad hoc Networking. You can check the temperature data on OLED Display.

esp8266 access point and client Network

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleNordic nRF52840 Advanced Bluetooth 5 with Arduino IDE – Getting Started
Next Article Gas Leakage Detector with Email Alert Notification using ESP32

Related Posts

ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

Updated:June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

Updated:June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

Updated:May 10, 20262K
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

Updated:May 2, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

Updated:April 27, 20261K
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

Updated:April 27, 20262K
View 6 Comments

6 Comments

  1. Ulrich Engel on June 29, 2022 8:44 PM

    What is the range between transmitter and receiver?

    Reply
  2. Ulrich Engel on July 20, 2022 6:08 PM

    Hello, I have one problem with the OLED. I do not see the temp on the OLED. I used yout libs.
    Sender and receiver works great. I controlled this with each serial monitor.

    Reply
  3. mohammad zarkasi on July 11, 2023 8:03 PM

    so, one node act as access point and one node act as client connected to it. what if there is another node as intermediate node that can forward data from sender to server? is it possible?

    Reply
  4. mohammad zarkasi on July 11, 2023 8:04 PM

    so, one node act as access point or web server, and one node act as client/sender. what if there is another node that act as intermediate node that forward data sent from client to server, is it possible?

    Reply
    • Admin on July 11, 2023 8:13 PM

      Yes it is possible.

      Reply
  5. Surya on July 19, 2023 2:04 PM

    I believe that this isn’t ad-hoc mode. Since one device is operating as AP and other as STA, it is clear that they are connected in infrastructure mode.

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
    IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • Half Wave Rectifier Basics, Circuit, Working & Applications
    Half Wave Rectifier Basics, Circuit, Working & Applications
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.