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.
Watch the Video Demonstration
To see how the project works, you can watch the following video demonstration:
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 library (download ESPAsyncWebServer library)
- Async TCP library (download AsyncTCP library)
These libraries are not available to install through the Library Manager. So, you need to unzip the libraries and move them to the Arduino IDE installation libraries folder.
Alternatively, you can go to Sketch > Include Library > Add .ZIP library… and select the libraries you’ve just downloaded.
You may also like: 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.
You may also like: 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.
You may also like: 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.
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-client-server-wi-fi/
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_P(200, "text/plain", readTemp().c_str());
});
server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readHumi().c_str());
});
server.on("/pressure", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(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/plain", readTemp().c_str());
});
The same happens when the ESP receives a request on the /humidity and /pressure URLs.
server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readHumi().c_str());
});
server.on("/pressure", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readPres().c_str());
});
The following lines initialize the BME280 sensor.
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);
}
Finally, start the server.
server.begin();
Because this is an asynchronous web server, there’s nothing in the loop().
void loop(){
}
Testing the ESP32 Server
Upload the code to your board and open the Serial Monitor. You should get something as follows:
This means that the access point was set successfully.
Now, to make sure it is listening for temperature, humidity and pressure requests, you need to connect to its network.
In your smartphone, go to the Wi-Fi settings and connect to the ESP32-Access-Point. The password is 123456789.
While connected to the access point, open your browser and type 192.168.4.1/temperature
You should get the temperature value in your browser:
Try this URL path for the humidity 192.168.4.1/humidity:
Finally, go to 192.168.4.1/pressure URL:
If you’re getting valid readings, it means that everything is working properly. Now, you need to prepare the other ESP32 board (client) to make those requests for you and display them on the OLED display.
#2 ESP32 Client (Station)
The ESP32 Client is a Wi-Fi station that is connected to the ESP32 Server. The client requests the temperature, humidity and pressure from the server by making HTTP GET requests on the /temperature, /humidity, and /pressure URL routes. Then, it displays the readings on an OLED display.
Schematic Diagram
Wire the ESP32 to the OLED display as shown in the following schematic diagram.
OLED | ESP32 |
VIN/VCC | VIN |
GND | GND |
SCL | GPIO 22 |
SDA | GPIO 21 |
Arduino Sketch for #2 ESP32 Client
Upload the following code to the other ESP32:
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-client-server-wi-fi/
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.
*/
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";
//Your IP address or domain name with URL path
const char* serverNameTemp = "http://192.168.4.1/temperature";
const char* serverNameHumi = "http://192.168.4.1/humidity";
const char* serverNamePres = "http://192.168.4.1/pressure";
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
String temperature;
String humidity;
String pressure;
unsigned long previousMillis = 0;
const long interval = 5000;
void setup() {
Serial.begin(115200);
// Address 0x3C for 128x64, you might need to change this value (use an I2C scanner)
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.clearDisplay();
display.setTextColor(WHITE);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
// Check WiFi connection status
if(WiFi.status()== WL_CONNECTED ){
temperature = httpGETRequest(serverNameTemp);
humidity = httpGETRequest(serverNameHumi);
pressure = httpGETRequest(serverNamePres);
Serial.println("Temperature: " + temperature + " *C - Humidity: " + humidity + " % - Pressure: " + pressure + " hPa");
display.clearDisplay();
// display temperature
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("T: ");
display.print(temperature);
display.print(" ");
display.setTextSize(1);
display.cp437(true);
display.write(248);
display.setTextSize(2);
display.print("C");
// display humidity
display.setTextSize(2);
display.setCursor(0, 25);
display.print("H: ");
display.print(humidity);
display.print(" %");
// display pressure
display.setTextSize(2);
display.setCursor(0, 50);
display.print("P:");
display.print(pressure);
display.setTextSize(1);
display.setCursor(110, 56);
display.print("hPa");
display.display();
// save the last HTTP GET Request
previousMillis = currentMillis;
}
else {
Serial.println("WiFi Disconnected");
}
}
}
String httpGETRequest(const char* serverName) {
WiFiClient client;
HTTPClient http;
// Your Domain name with URL path or IP address with path
http.begin(client, serverName);
// Send HTTP POST request
int httpResponseCode = http.GET();
String payload = "--";
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
return payload;
}
How the code works
Include the necessary libraries for the Wi-Fi connection and for making HTTP requests:
#include <WiFi.h>
#include <HTTPClient.h>
Insert the ESP32 server network credentials. If you’ve changed the default network credentials in the ESP32 server, you should change them here to match.
const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";
Then, save the URLs where the client will be making HTTP requests. The ESP32 server has the 192.168.4.1 IP address, and we’ll be making requests on the /temperature, /humidity and /pressure URLs.
const char* serverNameTemp = "http://192.168.4.1/temperature";
const char* serverNameHumi = "http://192.168.4.1/humidity";
const char* serverNamePres = "http://192.168.4.1/pressure";
Include the libraries to interface with the OLED display:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Set the OLED display size:
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Create a display object with the size you’ve defined earlier and with I2C communication protocol.
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Initialize string variables that will hold the temperature, humidity and pressure readings retrieved by the server.
String temperature;
String humidity;
String pressure;
Set the time interval between each request. By default, it’s set to 5 seconds, but you can change it to any other interval.
const long interval = 5000;
In the setup(), initialize the OLED display:
// Address 0x3C for 128x64, you might need to change this value (use an I2C scanner)
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.clearDisplay();
display.setTextColor(WHITE);
Note: if your OLED display is not working, check its I2C address using an I2C scanner sketch and change the code accordingly.
Connect the ESP32 client to the ESP32 server network.
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
In the loop() is where we make the HTTP GET requests. We’ve created a function called httpGETRequest() that accepts as argument the URL path where we want to make the request and returns the response as a String.
You can use the next function in your projects to simplify your code:
String httpGETRequest(const char* serverName) {
HTTPClient http;
// Your IP address with path or Domain name with URL path
http.begin(serverName);
// Send HTTP POST request
int httpResponseCode = http.GET();
String payload = "--";
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
return payload;
}
We use that function to get the temperature, humidity and pressure readings from the server.
temperature = httpGETRequest(serverNameTemp);
humidity = httpGETRequest(serverNameHumi);
pressure = httpGETRequest(serverNamePres);
Print those readings in the Serial Monitor for debugging.
Serial.println("Temperature: " + temperature + " *C - Humidity: " + humidity + " % - Pressure: " + pressure + " hPa");
Then, display the temperature in the OLED display:
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("T: ");
display.print(temperature);
display.print(" ");
display.setTextSize(1);
display.cp437(true);
display.write(248);
display.setTextSize(2);
display.print("C");
The humidity:
display.setTextSize(2);
display.setCursor(0, 25);
display.print("H: ");
display.print(humidity);
display.print(" %");
Finally, the pressure reading:
display.setTextSize(2);
display.setCursor(0, 50);
display.print("P:");
display.print(pressure);
display.setTextSize(1);
display.setCursor(110, 56);
display.print("hPa");
display.display();
We use timers instead of delays to make a request every x number of seconds. That’s why we have the previousMillis, currentMillis variables and use the millis() function. We have an article that shows the difference between timers and delays that you might find useful (or read ESP32 Timers).
Upload the sketch to #2 ESP32 (client) to test if everything is working properly.
Testing the ESP32 Client
Having both boards fairly close and powered, you’ll see that ESP #2 is receiving new temperature, humidity and pressure readings every 5 seconds from ESP #1.
This is what you should see on the ESP32 Client Serial Monitor.
The sensor readings are also displayed in the OLED.
That’s it! Your two boards are talking with each other.
Wrapping Up
In this tutorial you’ve learned how to send data from one ESP32 to another ESP32 board via Wi-Fi using HTTP requests without the need to connect to the internet. For demonstration purposes, we’ve shown how to send BME280 sensor readings, but you can use any other sensor or send any other data. Other recommended sensors:
We have a similar tutorial for the ESP8266 that you might find useful:
We hope you’ve found this tutorial useful. We’re preparing more tutorials like these. So, stay tuned and subscribe to our blog!
Thanks for reading.
Have you done anything that has successfully sets the host node name – I am having trouble setting the host on my project it seem to default to espessif when I look at my router and the devices connected. I have use the SetHostName in the Arduino IDE without success. I would like to “ping” the name of the devices… I am using the ESP-WROOM-32 chipset and Arduino IDE on a custom board. I would like unique names…
Gregg, I believe there is a bug in the ESP32 That causes it not to send the hostname correctly. There was some chat about this on the ESP32 Gitter forum
Hello Sarah and Ruis
Happy New Year from Paris..
This one article and also the one on SQL are so good i ‘d like to sand you some Euros to prove my satisfaction…
Tel me the way to do it
Have a great day!
Philippe Loutrel
http://www.loutrel.org
Hi Philippe.
Thank you for your nice words.
Read our about page, we show how you can support our work: https://randomnerdtutorials.com/about/
Regards,
Sara
Thanks Sara, i bought you a coffee on Paypal ( a few cups i hope!)
What should be a range between client and station?
Great project. Would you consider taking on a bit larger project sample?
I’d like to implement a network of several room temperature samplers around my house that would feed to (or be polled by) a central server that could then use logic to send to other ESP32s that control heating duct valves or fans to direct warm air to colder rooms. Taking this a step further would include maintaining a database of temperature samples to be able to report, room by room, heating requirements.
Such a system could also be adapted to sample soil dampness and intelligently control segmented sprinklers so as to avoid wasted watering during the summer. I’m sure it could be a generic control system for many applications.
Thanks…..Paul
Why are you using async webserver for synchronous communication?
In my projects.. for instance OPC UA protocol i am using normal synchronous webserver without any problem. I can read multiple values in POST or GET request without any problem, also send reply to client JSON or OPC UA (Soap) encoded.
I’ll be wanting to also access the web server with my phone, if I want the readings in a future projects.
Hello Rui thank you for your great work and help .. i have question if i have website and i want the webpage in my website controls my eap32 via websocket do you have any idea how is this could be possible ?
Hi Rui and Sara
Another great video .Do you have an idea baout the maximum distance possible between the two ESP’s ?
Rgds
Domingos
With this project using ESP32 boards and in open space (no obstacles) I was able to get up to 50 meters (164 feet) reliable communication.
Thanks!
Rui
Hi!
The project is very good, like. You’d be happy to see the data in a spreadsheet.
Thanks Péter
Hi Peter.
Thanks for the suggestion.
We have the following tutorials about data logging:
https://randomnerdtutorials.com/esp32-esp8266-publish-sensor-readings-to-google-sheets/
https://randomnerdtutorials.com/esp32-data-logging-temperature-to-microsd-card/
Regards,
Sara
Thanks for a nice tutorial. It would be interesting to implement this kind of project using the ESP-NOW protocol (and maybe also ESP-MESH), which is peer-peer (no access point required), lower power from wakeup, and supposedly longer distances. Maybe something for the future?
Hi Carl.
Thanks for the suggestion.
We’re currently working on some ESP-NOW tutorials.
Regards,
Sara
Love this project and would like to use it to measure tide in the salt water canal outside our home.
What is the expected nominal range between server and client?
I am struggling with what sensor to use to measure tidal height. A simple sonic range finder will measure distance to top of the water but it is not resistant to salt water micro spray in the atmosphere. Any housing seems to interfere with the sonic signal. Any ideas?
You two are great, keep it up.
What about car ultrasonic reversing trans/recieve sensors. They are surely designed for wet /salty enviroments ie. Road spray?
Hi Jim.
With the built-in ESP32 antenna, we got a stable communication between boards up to 52 meters (approximately 164ft) in open field without obstacles.
As for the sensor, you really have to experiment and see what’s the best sensor for your case.
Thank you for your nice words 😀
Regards,
Sara
Thanks, for the interesting post, it would be nice to have these tutorials downloadable as a PDF.
Thanks for the suggestion, we might try to implement that feature in the future.
Regards,
Rui
Hi, Ted.
Only pres Ctl+p and prit to PDF format.
Hi,
Thanks for this project. I can’t wait to try it. However, I have a few ESP01’s that are currently unused, is it possible to run this on an ESP8266 platform?
Thanks
Jos
Hi Jos.
There’s a tutorial like this dedicated to ESP8266: https://randomnerdtutorials.com/esp8266-nodemcu-client-server-wi-fi/
Regards,
Sara
Hello, This is very interesting, Congratuletion… another Question, can you tell me if you have any tutotial about IPS(Indoor position System).
Best Regards.
Ramón Reyes
Hi Ramón.
Unfortunately, we don’t have any tutorials about that subject.
Regards,
Sara
I get an error when I use the code…
xTaskCreateUniversal’ was not declared in this scope
Hi.
Did you install all the required libraries?
Regards,
Sara
Excellent project! Is it possible to have multiple clients attached to one ESP32 server?
I’m envisioning an application with multiple remote clients all connected to one server. 🙂
thanks much,
ben
Have you anything on e-paper & esp32 /esp8266
regards Bill
other projects work great
Hi Bill.
At the moment, we don’t have any tutorials about e-displays.
Regards,
Sara
Hello, I have a mistake whereby I cant view my access point in either laptop or mobile phone. May I know how to fix it? Even though my serial monitor has printed Setting AP (Access Point)…AP IP address: 192.168.4.1.
Hi.
If you search for nearby wi-fi networks, the “ESP32-Access-Point” doesn’t show up?
Regards,
Sara
Hello
I am facing the same problem
no nearby wi-fi networks
any suggestion
Can I mix server ESP32 and client ESP8266?
Yes, it doesn’t matter as long one ESP is set as a server and the other as a client.
Hello – thanks for this tutorial. I am “just” trying to transfer data backwards and forwards between the client and server which are both ESP8266 Arduino clones and establishing my own Access Point. So, I have deleted the display and temperature etc interfaces.
1. I cannot get the server.on step to work as it says it cannot find the .h file. Which .h file defines it?
2. I am trying to work out which are the send and which are the read functions?
Sorry, I am now rather confused.
Your site is amazing and the best of what I can find sharing this sort of information.
Did you ever do a tutorial of having multiple clients for the one server?
Thanks
Rob
Hello,
i’m trying to use the DHT22 instead of BME280, but i can’t get it to work,
i read the sensor, after i convert into string but shows 0,00
but when i put the code on loop than it works
Hey,
What a great write up these code really help me get the learning done much easier !!
Just one thing 🙂
Im using Platform IO and when i compile the Server i get the error
HttpGETReqest was not declared in this scope…
I have the #include “HTTPClient.h”
what have i missed ???
great job.
i am getting nan on 192.168.4.1/temperature !!!
any other got same?
why?
Hello there
I installed a client and sever with esp32.
There is an engine running on the client. I do the speed control just fine. I want the engine to stop immediately when the connection between the client and the server is interrupted or data cannot be received. I simply use a code like this for this. if (WiFi.status ()! = WL_CONNECTED) digitalWrite (RL_control, LOW);
else digitalWrite (RL_control, HIGH); But it takes 10 seconds for esp32 to figure this out. I want him to cut it right away. How can I do that. I wish you success in your work.
Hi.
You can try using Wi-Fi events.
Take a look at this tutorial: https://randomnerdtutorials.com/esp32-useful-wi-fi-functions-arduino/ and go to the Wi-Fi events section.
You can set the ESP32 to run a task as soon as the Wi-Fi connection is lost.
Regards,
Sara
Hi Sara
Thank you for your suggestion. I tried the functions in the lesson you recommended, but the result is the same. WL_CONNECTION_LOST etc. with “WiFiClientEvents”. I’ve tried all the functions. I want to describe exactly what I did so that the incident could be understood clearly. While Esp32 server and Esp32 client are in communication, I send power information from the Esp32 server to the engine installed on the Esp32 client. Motor Esp32 is activated with the data I send from the server. Esp32 server is battery powered in a box.
While Esp32 server and Esp32 client are communicating, the engine is active.
I suddenly removed the battery powering the Esp32 server.
It is as if the box was dropped and the battery was out of the box and the Esp32 likes were out of power.
For such a case, Esp client to disable the engine “if ((WiFi.status () == WL_CONNECTION_LOST)) digitalWrite (RL_control, LOW);” I use. However, the Esp32 client takes about 10 seconds to activate this. I want the Esp32 client to close Relay immediately. As I mentioned above, I tried the “event” functions, the result is the same. I need a data output that runs boolean with the receiver active and passive in all functions. What can I do. I could not solve this problem.
Thank you for your attention, best regards.
Hello Rui Santos,
i’m getting below error when i compling the code so please give me some suggestion:-
In file included from C:\Users\Design Engineer\Downloads\sketch_jun14a\sketch_jun14a.ino:14:0:
C:\Users\Design Engineer\Documents\Arduino\libraries\ESPAsyncWebServer-master\src/ESPAsyncWebServer.h:26:10: fatal error: functional: No such file or directory
#include
^~~~~~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Arduino Uno.
Hi.
Make sure you’ve installed the ESPAsyncWebServer library properly.
Regards,
Sara
Greetings, Very helpful website. This project is about as close tto the question I have. 802.11 has two protocols, WMM and PSM which saves packets at the AP if the that mode is requested. Client would wake up from sleep in time to receive a beacon and if a flag is set, the client would transmit a request to the AP requesting the saved packets. Has that been implemented in a ESP32 library? If not is it possible to access the raw received 802.11 data in order to implement either the WMM or PSM protocol?
The below has a better description of these modes.
Ref blog.voneicken.com/2018/lp-wifi-association/
Regards
Jerald English
Hello there,
I want to recieve the sensor readings which are in the esp32 to the mobile application , which is the best method to do that?
I want to do that without using internet.Please help
Hi.
The easiest way is to build a web server in access point.
For example, you can do this web server: https://randomnerdtutorials.com/esp32-web-server-with-bme280-mini-weather-station/
And then combine with the following example so that it doesn’t need internet: https://randomnerdtutorials.com/esp32-access-point-ap-web-server/
I hope this helps.
Regards,
Sara
Hi, Your excellent tutorials are great to implement in my projects. I tried to apply the current wifi P2P protocol to send sensor data in my appartment from one room to another where the laptop captures the data (Realterm) and plots this in real time (KST plot). The distance I can cover inside is about 10 m at most, beyond that the connection is lost. This is too short for me to establish a reliable connection. I have also tried to use the NOW protocol which coverage is even shorter, about a few meters.
I would like try to use a wifi connection via my home network router.
How could this program be changed to implement just that, or is a separate tutorial available?
Regards,
Kornelis
Hi,
I have been using these wifi routines on my esp32 (featheresp32) .
It works if I use the Espressif 32 version 3.1.1 library in platformio/visual studio code using the arduino framework. Today, the latest version is 3.4.0. That one does not work ie connection with my wifi accesspoint is never established. Actually, all higher than 3.1.1 do not work.
According to the changelogs, the only difference is the change in arduino framework to 1.0.6:
3.2.0 released 9 months ago
Updated Arduino framework to 1.0.6 (release notes)
3.1.1 released 9 months ago
Added new board Heltec Wifi Kit 32 V2 (Issue #513)
Updated default upload speed for m5stack-atom board (Issue #509)
Preparations for updated debug configuration process in upcoming PlatformIO Core 5.2+
Fixed variant name for the ttgo-t-beam board
Fixed buildfs target declaration to be used with pre/post actions
Minor fixes and improvements
I am not sure what has happened. Anyone any idea?
Thanks,
Nick
Hello.
Thanks for all the help you provide with videos and explanations.
As i am trying to make this project work. At first i started building the Server. But when i compile, i keep getting the same error:
“ESPAsyncWebServer.h: No such file or directory”
The whole error page is this:
Arduino: 1.8.16 (Windows 10), Board: “ESP32 Wrover Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), QIO, 80MHz, 115200, None”
SERVER:14:31: fatal error: ESPAsyncWebServer.h: No such file or directory
Multiple libraries were found for “WiFi.h”
compilation terminated.
Used: C:\Users\filip\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
ESPAsyncWebServer.h: No such file or directory
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
”
I have tried to include the library from .zip file as you mentioned before the server code
I have also tried to include all the .h files in the folder with the Server code. but same thing happens.
Do you have any idea what the problem might be?
Thanks
Filippos
Hi.
Delete all possible previous versions and files of the library and install it again exactly as described in the tutorial.
Regards,
Sara
Hi,
Thanks for this tutorial, but I am having an issue.
I have installed the required libraries, I believe but when I try to compile the code I get this error
exit status 1
‘class WiFiClass’ has no member named ‘softAP’
googling suggests I add in other libraries, but none seem to resolve the issue
I am using a Wemos D1 mini board and I am able to upload and run other sketches on it.
Thanks
Mel
Hi.
This tutorial is for an ESP32 board. That’s why it doesn’t work for you.
For an ESP8266 tutorial, you can check this: https://randomnerdtutorials.com/esp8266-nodemcu-client-server-wi-fi/
Regards,
Sara
Sorry realised my mistake after posting but didn’t know how to delete the post, once I used the correct page everything worked fine, again thanks for these tutorials they are great.
Mel
This tutorial is for to boards one server and one client what if we want sensor data from two servers and show both sensors data on the oled at the same time then what we have to do .
pls guide
This tutorial is for two boards one server and one client. What if we want sensor data from two servers and show both sensors data one client that contain oled and we want both sensors data at the same time then what we have to do .
pls guide
This tutorial is for two boards one server and one client. What if we want sensor data from two servers and show both sensors data one client that contain oled and we want both sensors data at the same time then what we have to do .
pls guide bout this.
So is technically considered (Wifi Direct/P2P)?
Also, is there any way to have the connecting device connect to both the ESP and a separate router (so you don’t lose access to the Internet)?
Thanks!
Hi, thanks for the great job.
I have a question about ESM32CAM client stream on TTGO server, that is must power on server first, and power on client next, any way to improve this please?
Thanks
Summer
Hi.
I’m sorry but I didn’t understand the question.
Can you reformulatE it?
Regards,
Sara
Hi Sara.
Let’s say we set: #1 ESP32 Server (Access Point); and #2 ESP32 Client (Station).
seems they work only when power on #1 first, and power on #2 next? is it OK to power on #2 first and then #1?
Thank you
Summer
Hi, thanks for the tutorial.
is it possible to have the server send a data structure instead of a single number when getting an http request?
a bit similar to the ESP-NOW method.
But I need one packed to be at least 768 bytes. and that’s why I’m not using ESP-NOW for this project since it only kan transmit 250 byte i one packed.
I also need to transfer the data with a minimum speed of 38400 bytes/s to a client and I plan to have 10 of these clients.
So a total of 384,000 bytes/s will be transferred from the server to 10 different clients.
Is this possible with http requests?
Thank you 🙂
Best regards
Max Bursell
Can i use two clients instead of one ? (i” ll make the changes ).
Hi Rui & Sara,
Greetings from Vancouver Island, Canada.
Great video/tutorial.
We have quite a few earth tremors/quakes here and I am looking at placing an 3 axis accelerometer on a rock out in our garden, to monitor any seismic activity.
No router close by.
I was initially thinking of using Bluetooth, but I don’t think they have the range. After looking at your project using two ESP32s to communicate , I think they would have a greater range ( I need a range about 40m).
I would also like to stream the data and display using processing and also log the data on a laptop for further analysis.
Not sure if these ESPs are able transmit data fast enough?
Perhaps you could give me some pointers?
regards
Shaun
Hi.
Maybe it is better to use ESP-NOW.
Take a look at the getting started guide here: https://randomnerdtutorials.com/esp-now-esp8266-nodemcu-arduino-ide/
Then, take a look at all our ESP-NOW projects, I think they will be useful for your scenario: https://randomnerdtutorials.com/?s=esp-now
Regards,
Sara
Is there a relativley easy way to use the client with a SH1106 1.3 Display instead of the SSD1306 display?
i have this working OK wit the SSD1306, but my attempts to change the display are frustrating me.
thank you
You have to use a specific library for the SH1106. It’s not the same as for the SSD1306.
Regards,
Sara
Thank you, I understand that.
I played with it this morning, found some working code for a SH1106 display and successfully integrated it into my project.
I’m aware of that.
i used some code from a working sketch for SH1106 and merged it with my working sketch.
Thanks
Hi, if I have the sensor in the client board, Can I request those readings from the server, for example, to save them in a microSD that is located there. Thank you very much!
Happy new year! What is the maximum bit rate that could be transferred between two ESP32 boards with this method? Thanks!
Dear Rui and Sara;
Thanks again for all your rnd initiatives.
I adapted this project to the BMP180 sensor and works fine.
Happy new year!
Kurro.
Thank you.
Regards,
Sara
Hi Rui and Sara!
Obrigado pelos vários tutoriais disponíveis nos seu canal!
Gostaria de saber se tem como fazer a comunicação entre 2 ESPs usando o roteador. Obrigado
Hello thanks for this awesome tutorial. i am encounting some errors when showing the temp, pressure and humidiy on the oled i2c. i used 1.3 inch rather than a 0.91 inch and then parameters doesnt show all. how can i solve it please?
Hi.
I think maybe your display is not the one with the SSD1306 driver. Can you double-check that?
If it doesn’t come with the SSD1306 driver, you’ll need a different library to make it work.
Regards,
Sara
Bonjour Sara, j’ai essayé ce tutoriel et tout fonctionne très bien. Comme tous les autres que j’ai essayé. La question que je me pose sur le principe client serveur est:
Peut-on renvoyer des données de capteurs du client vers le serveur et par quelle méthode.
Merci
Dear Rui and Sara;
Thanks for this project’ as well as for all other projects.
I’m trying to implement the project using ESP32C3 on Arduino IDE 2.3.2. I have a problem in the following lines:
server.on(“/command”, HTTP_GET,
[](AsyncWebServerRequest* request) {request->send_P(200, “text/plain”, readCommand().c_str()); });
Where the compiler issues the following errors:
In file included from
E:\Current\Tractor\SWtractorCombined_V1.0\src\ESP32_WIFI\ESP32_WIFI.ino:13:
E:\src\ESP32_WIFI\ESP32_WIFI.h: In lambda function:
E:\Current\Tractor\SWtractorCombined_V1.0\src\ESP32_WIFI\ESP32_WIFI.h:35:51:
error: ‘this’ was not captured for this lambda function 35 | request->send_P(200,
“text/plain”, readCommand().c_str());
| ~~~~~~~~~~~^~
E:\Current\Tractor\SWtractorCombined_V1.0\src\ESP32_WIFI\ESP32_WIFI.h:35:51:
error: cannot call member function ‘String localWifiP::readCommand()’ without object
How can I change the Lambda into simple functions call statement?
Best regards
Yona
Still working on the project: I tried to modify the code and generated the code. I created an H file that contains 3 methods, that contains the code from the SETUP and LOOP methods and is used as API. From which the problematic is the “serverBegin”:
”
bool serverBegin() {
WiFi.softAP(ssid, password);
IPAddress IP = WiFi.softAPIP();
server.on(“/command”, HTTP_GET,
(AsyncWebServerRequest request) { request->send_P(200, “text/plain”, commandGenerator()); });
server.begin(); // Start server
return HIGH;
}
”
Where “commandGenerator()” is an external method that returns a string of 30 characters.
The errors now are:
”
ESP32_WIFI.h:49:28: error: expected primary-expression before ‘‘ token
49 | (AsyncWebServerRequest request) { request->send_P(200, “text/plain”, commandGenerator()); });
ESP32_WIFI.h:49:29: error: ‘request’ was not declared in this scope
49 | (AsyncWebServerRequest *request) { request->send_P(200, “text/plain”, commandGenerator()); });
”
Both error pointers point to the term “request” of the “server.on” statement.
I realy need assistance and appreciate it very much.
Regards
Yona