IoT/ESP32 B.Tech/Diploma Beginner

ESP32 Client-Server Wi-Fi Communication Between Two Boards

Create an HTTP communication between two ESP32 boards to exchange data via Wi-Fi without an internet connection. You'll program your ESP32 boards with Arduino IDE.

  • Suitable forB.Tech/Diploma IoT/ESP32 students
  • Build time1-2 weeks
  • LevelBeginner
  • Available atAjvika Labs, Kakinada

About this project

This guide shows how to setup an HTTP communication between two ESP32 boards to exchange data via Wi-Fi without an internet connection (router). In simple words, you’ll learn how to send data from one board to the other using HTTP requests. The ESP32 boards will be programmed using Arduino IDE.
For demonstration purposes, we’ll send
BME280 sensor readings
from one board to the other. The receiver will
display the readings on an OLED display
If you have an ESP8266 board, you can read this dedicated guide:
ESP8266 NodeMCU Client-Server Wi-Fi Communication
Project Overview
One ESP32 board will act as a server and the other ESP32 board will act as a client. The following diagram shows an overview of how everything works.
The ESP32 server creates its own wireless network (
ESP32 Soft-Access Point
). So, other Wi-Fi devices can connect to that network (
SSID:
ESP32-Access-Point,
Password:
123456789).
The ESP32 client is set as a station. So, it can connect to the ESP32 server wireless network.
The client can make HTTP GET requests to the server to request sensor data or any other information. It just needs to use the IP address of the server to make a request on a certain route:
/temperature
/humidity
or
/pressure
The server listens for incoming requests and sends an appropriate response with the readings.
The client receives the readings and displays them on the OLED display.
As an example, the ESP32 client requests temperature, humidity and pressure to the server by making requests on the server IP address followed by
/temperature
/humidity
and
/pressure
, respectively.
The ESP32 server is listening on those routes and when a request is made, it sends the corresponding sensor readings via HTTP response.
Parts Required
For this tutorial, you need the following parts:
2x ESP32 Development boards
– read
Best ESP32 Boards Review
BME280 sensor
I2C SSD1306 OLED display
Jumper Wires
Breaboard
You can use the preceding links or go directly to
MakerAdvisor.com/tools
to find all the parts for your projects at the best price!
Installing Libraries
For this tutorial you need to install the following libraries:
Asynchronous Web Server Libraries
We’ll use the following libraries to handle HTTP request:
ESPAsyncWebServer
by ESP32Async
AsyncTCP
by ESP32Async
You can install those libraries in the Arduino IDE Library Manager. Go to
Sketch
>
Include Library
>
Manage Libraries
and search for the libraries’ names.
Build an Asynchronous Web Server with the ESP32
BME280 Libraries
The following libraries can be installed through the Arduino Library Manager. Go to
Sketch
>
Include Library
>
Manage Libraries
and search for the library name.
Adafruit_BME280 library
Adafruit unified sensor library
Interface BME280 with ESP32 (Guide)
I2C SSD1306 OLED Libraries
To interface with the OLED display you need the following libraries. These can be installed through the Arduino Library Manager. Go to
Sketch
>
Include Library
>
Manage Libraries
and search for the library name.
Adafruit SSD1306
Adafruit GFX Library
I2C SSD1306 OLED Display with ESP32 (Guide)
#1 ESP32 Server (Access Point)
The ESP32 server is an
Access Point (AP)
, that listens for requests on the
/temperature
/humidity
and
/pressure
URLs. When it gets requests on those URLs, it sends the latest BME280 sensor readings.
For demonstration purposes, we’re using a BME280 sensor, but you can use any other sensor by modifying a few lines of code.
Schematic Diagram
Wire the
ESP32 to the BME280 sensor
as shown in the following schematic diagram.
BME280
ESP32
VIN/VCC
3.3V
GND
GND
SCL
GPIO 22
SDA
GPIO 21
Arduino Sketch for #1 ESP32 Server
Upload the following code to your board.
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/

// Import required libraries
#include "WiFi.h"
#include "ESPAsyncWebServer.h"

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

// Set your access point network credentials
const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";

/*#include <SPI.h>
#define BME_SCK 18
#define BME_MISO 19
#define BME_MOSI 23
#define BME_CS 5*/

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

String readTemp() {
return String(bme.readTemperature());
//return String(1.8 * bme.readTemperature() + 32);
}

String readHumi() {
return String(bme.readHumidity());
}

String readPres() {
return String(bme.readPressure() / 100.0F);
}

void setup(){
// Serial port for debugging purposes
Serial.begin(115200);
Serial.println();

// Setting the ESP as an access point
Serial.print("Setting AP (Access Point)…");
// Remove the password parameter, if you want the AP (Access Point) to be open
WiFi.softAP(ssid, password);

IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);

server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/plain", readTemp().c_str());
});
server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/plain", readHumi().c_str());
});
server.on("/pressure", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/plain", readPres().c_str());
});

bool status;

// default settings
// (you can also pass in a Wire library object like &Wire2)
status = bme.begin(0x76);
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}

// Start server
server.begin();
}

void loop(){

}
How the code works
Start by including the necessary libraries. Include the
WiFi.h
library and the
ESPAsyncWebServer.h
library to handle incoming HTTP requests.
#include "WiFi.h"
#include "ESPAsyncWebServer.h"
Include the following libraries to interface with the BME280 sensor.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
In the following variables, define your access point network credentials:
const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";
We’re setting the SSID to
ESP32-Access-Point
, but you can give it any other name. You can also change the password. By default, its set to
123456789
Create an instance for the BME280 sensor called
bme
Adafruit_BME280 bme;
Create an asynchronous web server on port 80.
AsyncWebServer server(80);
Then, create three functions that return the temperature, humidity, and pressure as String variables.
String readTemp() {
return String(bme.readTemperature());
//return String(1.8 * bme.readTemperature() + 32);
}

String readHumi() {
return String(bme.readHumidity());
}

String readPres() {
return String(bme.readPressure() / 100.0F);
}
In the
setup()
, initialize the Serial Monitor for demonstration purposes.
Serial.begin(115200);
Set your ESP32 as an access point with the SSID name and password defined earlier.
WiFi.softAP(ssid, password);
Then, handle the routes where the ESP32 will be listening for incoming requests.
For example, when the ESP32 server receives a request on the
/temperature
URL, it sends the temperature returned by the
readTemp()
function as a char (that’s why we use the
c_str()
method.
server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/

Technologies used

ESP32ESP8266ArduinoWiFiBLEBME280SSD1306OLEDI2CSPIArduino IDE

Hardware components

  • ESP32
  • ESP8266
  • Arduino
  • BME280
  • SSD1306
  • OLED

Software & tools

  • Arduino IDE

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.