ESP8266 Client-Server Wi-Fi Communication Between Two Boards (NodeMCU)

Learn how to establish a Wi-Fi communication (HTTP) between two ESP8266 NodeMCU boards to exchange data without the need to connect to the internet (you don’t need a router).

You’re going to set one ESP8266 as an Access Point (Server) and another ESP8266 as a Station (Client). Then, the server and the client will exchange data (sensor readings) via HTTP requests. We’ll program the ESP8266 boards using Arduino IDE.

ESP8266 Client-Server Wi-Fi Communication Between Two Boards

In this example, 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 ESP32 board, you can read this dedicated guide: ESP32 Client-Server Wi-Fi Communication.

Watch the Video Demonstration

To see how the project works, you can watch the following video demonstration:

Project Overview

To better understand how everything works, take a look at the following diagram.

ESP8266 Client-Server Wi-Fi Communication Between Project overview
  • The ESP8266 server creates its own wireless network (ESP8266 Soft-Access Point). So, other Wi-Fi devices can connect to that network (SSID: ESP8266-Access-Point, Password: 123456789).
  • The ESP8266 client is set as a station. So, it can connect to the ESP8266 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 ESP8266 client requests temperature, humidity and pressure to the server by making requests on the server IP address followed by /temperature, /humidity and /pressure, respectively (HTTP GET).

The ESP8266 server is listening on those routes and when a request is made, it sends the corresponding sensor readings via HTTP response.

Parts Required

Parts required for ESP8266 Client-Server Communication

For this tutorial, you need the following parts:

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:

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: DHT11/DHT22 Asynchronous Web Server with the ESP8266

BME280 Libraries

The following libraries can be installed through the Arduino Library Manager. Go to Sketch Include LibraryManage Libraries and search for the library name.

You may also like: Guide for BME280 with ESP8266

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: Complete Guide for SSD1306 OLED Display with ESP8266

#1 ESP8266 Server (Access Point)

ESP8266 Server with BME280 temperature humidity pressure

The ESP8266 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 testing, we’re using a BME280 sensor, but you can use any other sensor by modifying a few lines of code (for example: DHT11/DHT22 or DS18B20).

Schematic Diagram

Wire the ESP8266 to the BME280 sensor as shown in the following schematic diagram.

ESP8266 BME280 Wiring Schematic Diagram
BME280ESP8266
VIN/VCC3.3V
GNDGND
SCLGPIO 5 (D1)
SDAGPIO 4 (D2)

Arduino Sketch for #1 ESP8266 Server

Upload the following code to your board.

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp8266-nodemcu-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 <ESP8266WiFi.h>
#include "ESPAsyncWebServer.h"

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

// Set your access point network credentials
const char* ssid = "ESP8266-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(){
  
}

View raw code

How the code works

Start by including the necessary libraries. Include the ESP8266WiFi.h library and the ESPAsyncWebServer.h library to handle incoming HTTP requests.

#include <ESP8266WiFi.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 = "ESP8266-Access-Point";
const char* password = "123456789";

We’re setting the SSID to ESP8266-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 ESP8266 as an access point with the SSID name and password defined earlier.

WiFi.softAP(ssid, password);

Then, handle the routes where the ESP8266 will be listening for incoming requests.

For example, when the ESP8266 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 ESP8266 Server

Upload the code to your board and open the Serial Monitor. You should get something as follows:

Testing the ESP8266 Server Serial Monitor Arduino IDE

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 ESP8266-Access-Point. The password is 123456789.

ESP8266 Server Access Point AP Connection

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:

ESP8266 Server Access Point AP Test request temperature

Try this URL path for the humidity 192.168.4.1/humidity:

ESP8266 Server Access Point AP Test request humidity

Finally, go to 192.168.4.1/pressure URL:

ESP8266 Server Access Point AP Test request pressure

If you’re getting valid readings, it means that everything is working properly. Now, you need to prepare the other ESP8266 board (client) to make those requests for you and display them on the OLED display.

#2 ESP8266 Client (Station)

ESP8266 Client Receive Readings via HTTP GET Request BME280

The ESP8266 Client is a Wi-Fi station that connects to the ESP8266 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 the OLED display.

Schematic Diagram

Connect an OLED display to your ESP8266 board as shown in the following schematic diagram.

ESP32 OLED Display Wiring Schematic Diagram
PinESP8266
Vin3.3V
GNDGND
SCLGPIO 5 (D1)
SDAGPIO 4 (D2)

Arduino Sketch for #2 ESP8266 Client

Upload the following code to the other ESP8266 (the client):

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp8266-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 <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>

#include <ESP8266WiFiMulti.h>
ESP8266WiFiMulti WiFiMulti;

const char* ssid = "ESP8266-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     -1 // 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);
  Serial.println();
  
  // 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);
 
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("Connected to WiFi");
}

void loop() {
  unsigned long currentMillis = millis();
  
  if(currentMillis - previousMillis >= interval) {
     // Check WiFi connection status
    if ((WiFiMulti.run() == 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.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 IP address with path or Domain name with URL 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;
}

View raw code

How the code works

Include the necessary libraries for the Wi-Fi connection and for making HTTP requests:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>

#include <ESP8266WiFiMulti.h>

You need to create a WiFiMulti instance.

ESP8266WiFiMulti WiFiMulti;

Insert the ESP8266 server network credentials. If you’ve changed the default network credentials in the ESP8266 server, you should change them here to match.

const char* ssid = "ESP8266-Access-Point";
const char* password = "123456789";

Then, save the URLs where the client will be making HTTP requests. The ESP8266 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 <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 ESP8266 client to the ESP8266 server network.

while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
}
Serial.println("");
Serial.println("Connected to WiFi");

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) {
  WiFiClient client;
  HTTPClient http;
    
  // Your IP address with path or Domain name with URL 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;
}

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 ESP8266 Timers).

Upload the sketch to #2 ESP8266 (client) to test if everything is working properly.

Testing the ESP8266 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 ESP8266 Client Serial Monitor.

Testing the ESP8266 Client Serial Monitor Arduino IDE

The sensor readings are also displayed in the OLED.

ESP8266 Client Server Communication example data exchange for sensor readings

That’s it! Your two ESP8266 boards are talking with each other.

Wrapping Up

In this tutorial we’ve shown you how to send data from one ESP8266 board to the other using HTTP requests. This project can be very useful if you need to setup a wireless communication between two boards or more and you don’t have a router nearby.

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 ESP32 that you might find useful:

We hope you liked this tutorial. We’re preparing more tutorials like these. So, stay tuned and subscribe to our blog!

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

114 thoughts on “ESP8266 Client-Server Wi-Fi Communication Between Two Boards (NodeMCU)”

  1. Sara,
    The tutorial is excellent and very well presented.
    But i have a question which is 1/2 related to your post.
    I want/need to have the same communication without Master/Slave.
    Let me explain: I have two boards which needs to send one to each other, data from time to time. For the moment i use some Lora devices as wireless communication channel. I want to use your project, or part of it, and whenever i need board A send some data to board B (max 100 bytes), and vice versa.
    Each board should be independent and send data at any time .
    To avoid collision, each board can send a small string which represent a request to send. The other board should replay with answer ready to listen.
    The first board send now data and end it with a “end data” string.
    In this way, each board can independently send data with no collision.
    Do you have an example to follow for this type of communication ?
    Regards
    Ion

    Reply
      • Dear Sara
        I am learner of IOT with the help of NODEMCU. Please can you provide me a sketch to operate a relay on server(Node MCU) from client (NodeMCU). I want to learn more about communication between 2 nodemcu boards.
        Your previous tutorial is really amazing and good.
        Thanks and Regards
        Nitin

        Reply
  2. I would like to have a server that receives data from n. client.
    Because I would like to read the temperatures of various rooms and control the zone solenoid valves of the heating system.

    Reply
  3. What about websocket and espnow ? HTTP request is slow and will load your network traffic if you have multiple nodes and a lot of data to exchange.

    Reply
  4. Hi Sarah!
    You have written very good tutorials. Firstly, I want to thank you!
    I have two ESP 66 boards and a BME 880 sensor. I do’t have a display, but I do not need it yet. (in the future I want to use the Arduino Mega board with a built-in 8266 + TFT display 3.2 inches).
    I upload the sketches server and client. But in com port of the client I received an “error: -1” instead of “HTTP Response code: 200” , and “–” instead of data. Although on the browser page I get temperature, pressure and humidity data. Help me please! What am I doing wrong?

    Reply
  5. I quite like this project, but can’t get it working properly yet. I am using the ESP8266 option, with ESP-01 for both server and client. I am also using a BMP280 instead of a BME280. I have commented out all the lines of code that refer to humidity.
    The server seems to work perfectly; if I use my cellphone, I can see the updated temperature or pressure when I refresh the page. The problem is, on the client I can’t ever see a valid temperature or pressure on my OLED screen (I only see “–” where the temperature and pressure values should be), and in the serial monitor I see “Error code: -1”. I know that Wifi is connected, as I receive an ip address (which I display on the OLED). Could there be a problem with my “httpGETRequest”? Have I messed it up by using the BMP280 instead of the BME280? (I used the appropriate library).

    Reply
  6. Hi Sara,
    In the client sketch I have this error:
    no matching function for call to ‘Adafruit_SSD1306::Adafruit_SSD1306(int, int, TwoWire*, int)’

    All libraries are installed .

    I work with win10 and Arduino IDE 1.8.5

    Thanks
    Renzo

    Reply
  7. Hi Sara!
    a few days ago I ran into a problem like Richard. I found a solution to the problem. My ESP8266 (client) was selected in the station mode and access points simultaneously. I switched this mode to the station. This can be done using the ESPlorer. After that, data was transferred from the server to the client. Although, from 1 to 3 data were sometimes lost.

    Reply
  8. Hi Sara:
    Started all over again from scratch. All new hardware, no mods from your design, with ESP8266 dev kits, BME280, SSD1360 I2C display. Able to use cell phone browser to read temperature, humidity, pressure, from server at 192.168.4.1. Client always gets error code: -1. Values never transfer to client.

    Using all your required libraries, Windows 10 Pro, Arduino IDE App 1.8.21

    Spent so much time on this, still failing 🙁

    Reply
  9. Yes this works! Sorry it couldn’t compile because I missed a few lines while copying your new code 😮 (too much rushing!)

    Thanks for your help!

    Reply
    • What kind of alert function?
      We’re working on a tutorial to send email notifications/or trigger some action when temperature goes below or above a certain threshold.
      It should be published next week.
      Regards,
      Sara

      Reply
      • Hi

        Like horn or splashing light that
        when i am asleep i can wake and fix situation
        so the tomatoes do not freeze,
        Like it did last November 2019.

        Residual-current device went off and so the heater
        went off too.I was meaning to remove some tomatoes
        to house for winter but they all died because -8 Celsius.

        That is all.
        Best regards

        Reply
  10. And again. Thank you for your dedication and beautiful work.
    I am trying (example) to get 23.5 Gr / c 23.5 Gr / c on the screen. So 1 place behind the comma. But I cannot use xx, 1 as usual.
    How is it possible or not possible?
    Greetings from the old man 🙂 in the Netherlands

    Reply
  11. Hello, I want to use this tutorial for research at my workshop. I have given the source that it came from this website.
    This tutorial so helpfull, thankyou very much

    Reply
  12. Having problems to compile client sketch. There is problem with line: http.begin(client, serverName);
    Incomments for error :no matching function for call to ‘HTTPClient;;begin(WiFiClient&, const char*&)’

    Reply
    • Hi Neil.
      I don’t know why you’re getting that error.
      I checked the code again and it is working fine for me.
      Double-check that you have an ESP8266 board selected and that you’re using the exact code we’re using.
      Without further details, it is very difficult to find out what might be wrong.
      Regards,
      Sara

      Reply
  13. hi, i have double checked everything. i have even reinstalled all libraries needed. i am using the same code and it’s not been modified. it seems to be an issue with ESP8266HTTPClient not working with your code.

    Reply
    • it’s work for me by do like this
      // Your IP address with path or Domain name with URL path
      //http.begin(WiFiClient, serverName); (before)
      http.begin(serverName); (after)

      Reply
      • Thank You very much for advice. It start compiling and work.
        I modify client code to work onserial with PC instead of display.

        Reply
  14. Hello. I hope you are doing well.
    I have one ESP8266 and one ESP32. Am I need to modify something in the code? (ESP32 is set as a client)

    Reply
  15. Hi, my server works with a mobile phone. But I have difficulties in getting contact with my client. Usually I have “dots for ever”, but one time a connection. So I guess there is nothing completely wrong with my code. Now I have a connection again, but it took a really long time. The devices are close to each other. Do you have suggestions?

    Reply
    • I have this working now. My problems were probably caused by a power bank that switches off after some time when the current is below some limit. Beware of those “too clever” devices! Makes sense with charging of batteries, but not with debugging wireless devices. ESP-NOW seems to be still better for my current project.

      Reply
      • Hi.
        Yes, that happens sometimes with some “smart” powerbanks. Happens with one we have here too. Not very practical to test ESP32 devices.
        Regards,
        Sara

        Reply
  16. Hi, I have a problem about the library. When I upload the code,ESPAsyncWebServer.h library doesnt allow it.
    ESPAsyncWebServer.h: No such file or directory
    Do you know how can i get this library ?
    Thank you so much.

    Reply
  17. Hi, is it possible to run this program and to connect the AP esp to the router for a webserver at the same time? 🙂

    Reply
    • Hi.
      Yes, I think it is possible.
      You need to set the board both as a WiFi Station and Access Point simultaneously.
      Regards,
      Sara

      Reply
      • Hi sara
        i have a problem when i want to run both at the same time. At the moment I run the WiFiServer and the AsyncWebServer both on server port 80 and it doesn’t work. I just don’t know which port I could use anymore. Do you have an idea? I would be happy about an answer.
        Best regards

        Reply
  18. Hello is possibble to get data from client,

    because if is than i would like to server run on my Wemos D1 mini with nextion display
    with 4 Wemos D1 as client on which i will have two sensor One will be color sensor other will be weight scale, also i woul like to send data when i press button on nextion .

    Is possibble this. or you have some other idea how i can do this ?

    Reply
  19. Hi, the libraries mentioned in the article don’t match the code. I only see one of the libraries mentioned, the other is ESP8266Wifi. I can’t find that in the library manager either. The ESPAsync TCP is mentioned that you need to download it but is not referenced in the code. Can you help me get it to compile? I tried the zip import and that didn’t work. Looking at the libraries, there is no ESP8266WiFi.h file Thanks!

    Reply
    • Hi.
      You just need to install these two libraries:
      ESPAsyncWebServer library (download ESPAsyncWebServer library)
      ESPAsync TCP library (download ESPAsyncTCP library)

      The ESPAsyncWebServer needs the ESPAsync TCP to work. You don’t need to put it in your code. The ESPAsyncWebServer will automatically search for ir.
      The ESP8266WiFi is installed by default when you install the ESP8266 in your Arduino IDE.
      Just make sure that you selected an ESP8266 board in the Boards Menu.
      Regards,
      Sara

      Reply
  20. Hi,
    I would like to have communication without master/slave.
    I have two cards that need to send each other data from time to time. Each card must be independent and send data at any time.
    Then I need to avoid any collision.
    Do you have an example for this type of communication?
    Thanks !

    Reply
  21. Hi Rui, should be an error at cliente code.
    You write:
    http.begin(client, serverName);
    Why do you need client?
    when i compile, i’ve an error.
    no matching function for call to ‘HTTPClient::begin(WiFiClient&, const char*&)’

    bool begin(String host, uint16_t port, String uri, bool https, String httpsFingerprint) attribute ((deprecated));

    And examples of this library they wrote:
    http.begin( serverName);

    Reply
  22. Hey, Thanks for uploading code. Its very valuable for me especially becouse I ve just started learning. I have a question. How to make the connection faster? Is it possible to send between ESP quicker and send more data for example: 20 bytes in 10 Hz?

    Reply
  23. Hi,
    I haven’t found the solution for 1 week. Can you help me?
    My project is to measure their fever with ttgo oled on the wrists of students in a classroom and gather this on the server to see the fire of the whole class on the web page. So far, everything is in your project, but I also show the clock on the oled screen on the wristbands of the students. My problem is when I try with your codes, the server resets the wristbands after receiving data and the articles are restarted. For this reason, I cannot see what time it is in the wristbands, it is necessary to wait a while for it to restart.
    What should I do? Can you help me urgently?
    or can someone who can help contact me?
    Thank you very much.

    Reply
  24. I need a serial connection, TX and RX on both ends, ESP to ESP but can’t find what I’m looking for. Anyone know of such a thing?

    Reply
  25. very well detail. I wanted to know if this is very much possible with a water level sensor, am having challenges with it

    Reply
  26. Hello Sara Santos, I uploaded the first code, but my serial monitor is full of garbled codes, and my phone can’t find the wifi signal. Can you help me?

    Reply
  27. Hello, thanks a lot for the tutorial!
    I just have a little problem: the Client ESP can’t connect to the Access Point. Where could the problem come from?
    Thanks a lot!

    Reply
      • Hi, in the Serial Monitor of the Client ESP, I can only see dots being displayed, coming from this line of code:
        while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(“.”);
        }
        So I guess that means my Client ESP can’t connect to the Wi-Fi. Why is that?
        Thanks a lot !

        Reply
        • Yes.
          That’s the issue.
          We updated the code two days ago.
          Can you double-check that you’re using the latest version of our code?
          Additionally, make sure you have the ESP8266 boards installation up to date. Go to Tools > Boards > Boards Manager and search for ESP8266. Update to the latest version.
          Regards,
          Sara

          Reply
  28. Dear Sara,
    I meet a problem using an ESP8266 in SoftAP mode. May be you can help me?
    Using different examples found on the net, I have written a small program, and my ESP-01 is now connected both as a station and an access point, with correct addresses.
    But I am stalled there.
    What I want to do is to receive UDP packets on the AP size, and send UDP packets on the station size (after some processing between both).
    In previous programs I wrote, I used the “readPacket” and “sendPacket” functions to receive and send UDP packets, but how can I distinguish between both networks?
    I have tried to duplicate the instanciation of UDP (WiFiUDP udp) but I get an error message from the IDE.
    Could you please help me?
    Best regards,

    Jean-Pierre Maniquaire (absolute beginner!)

    Reply
  29. Unfortunately it does not work.
    Reading via WWW (query to the server) in the browser returns the result. However, the ESP8266 board (client) receives the message “ERROR CODE: -1” over the serial. I have uploaded the batch you provided to github and it’s still the same. What could be wrong?

    Reply
  30. Hello! I love your tutorials and I have purchased some books from you. Thanks for all you do!

    I’m having a problem with running a program on my Esp8266-01 that sends me an email when a sensor reading gets low (low moisture in a potted plant). When I plug the unit into my computer, the program runs fine (set to run via boot.py), but when I use a battery (I’ve used , 18650s, Li-Po, and even a 9-Volt) it doesn’t work. It seems that the wifi is not activating as I can’t see the IP on my DHCP list. I am using a voltage regulator (made from one of your tutorials) that reads 3.33V (output) on a multimeter, so I can’t see why it’s not working. Again, it runs fine when plugged into my computer via USB. Thanks in advance for any help on this.

    Reply
    • Hi.
      Are you using micropython?
      Which IDE are you using?
      You’re probably running the code from the IDE without uploading the code to the board. If you’re pressing the IDE “run” button, it will run the code in the board, without actually uploading it.
      Make sure the code is uploaded to the board.
      Regards,
      Sara

      Reply
      • I had replied to my own post with that info – but I’ m using micropython and Mu Editor. The board is flashed with MP and all of the files exist on the board, it runs inside the repl and as I said above, it works when plugged into my computer – sending an email to me with the temp and moisture level from my sensor. When unplugged from my computer and powered by a battery it does not work. Im using a voltage regulator that is working properly providing the correct 3.3v. I have used several different batteries (9v, two 18650s, Lopo, etc.).

        I saw a post somewhere that said that the CH_EN needed to be connected to the 3.3v as well, but this has resulted in disabling two boards. The led still lights and Mu Editor recognizes the board, but repl no longer works and I can’t list files on the board or flash – even the firmware again.

        Reply
          • I have this essential setup – without the push-button and the resistor. From my understanding, it is not necessary for the working of this circuit to connect to RST (I will later to provide deep sleep). Please correct me if I am mistaken. The resistor doesn’t effect the connection of the CH_PD (CH_EN in my case) as according to the schematic, it is directly connected to 3.3v. In my case, my boards are damaged (can no longer connect to them) after connecting CH_EN to 3.3v. Thanks for any more advise you can provide.

          • Maybe your boards are a different pinout?
            Maybe the pins are placed in a different arrangement?
            I don’t know what can be the issue.
            Regards,
            Sara

          • I got it to work using your sketch. Thanks for your help. So now the button wakes up the ESP8266-01 and then does its thing and goes back to sleep. I would like to set the sleep to 24 hours (86400000 ms) but without the button – which I know how to do. Can you tell me how I can remove the button from the circuit so that it will just wake itself up, operas and then go back to sleep with out having the press the button? I assume the RST still needs the 10K resistor. Thanks.

  31. Hi Sara
    Can you help me about this scenario, i have 4 nodemcu esp32 with 1 temperature sensor in each of them, i want to connect them together with lora by one point such as lora gateway but i haven’t enough money to bought a gateway, my scenario is: node 1 connected to node 2 via lora then node 2 connected to node 3 via wifi then node 3 connected to node 4 via lora and at the end node 4 connected to Internet or dashboard server via wifi, is possible this or no? Thanks for your help

    Reply
  32. Hi Sara.
    it is possible to exchange data between two boards (ESP8266 or ESP32) via Wi-Fi through Blynk or something similar?
    Thanks
    Renzo

    Reply
  33. Very interesting. Thankyou!!
    I wonder if its possible to connect the ESP8266 to an eduroam network.
    I’ve done it with the ESP32, but I do not find the correct code lines to do the same with the ESP8266
    This is what I type for ESP32
    #include “WiFi.h” //librería para conexión WiFi
    #include “esp_wpa2.h” //wpa2 library for connections to Enterprise networks
    #define EAP_IDENTITY “*******” // Username
    #define EAP_PASSWORD “*******” //your Eduroam password
    const char* ssid = “eduroam”; // Eduroam SSID

    Is there something for ESP8266WiFi library?
    Thankyou!!

    Reply
  34. hello ruy santos
    i have tested your code work fine. M2M

    i have tested add connection with fixed ip with Router
    the server work fine with smartphone reply message.
    but the client not receiving reply 🙁
    have suggestion for code modification in the client ?
    thank you

    Reply
  35. Thank you for this tutorial. Absolutely top notch. I had a similar problem to Henry: Client http Get request always returning -1 as if the http.begin had not worked. I know server was good because I tested from my phone as you said. I noticed that for some reason in my IDE, ESP8266HTTPClient.h was not highlighted the same color as other library headers were. Unable to resolve, on a long shot I updated from Arduino 1.8.19 to 2.0.2 and recompiled the exact same source code and it is now working. Thanks again for the fun project.

    Reply
  36. I’ll have to do more tests. i tried a code that works but it only reads one page. another change i wanted to try was to send all parameters in a single page i can’t.

    Reply
  37. Great explanantion
    Can u give a short note on how to connect multiple nodemcu clients to server and do the same process of getting readings and displaying in the server LCD board
    I have been working in this long time and you thoughts might really give me a way forward

    Reply
  38. Very much appreciate your turorial. This is my first time with ESP8266 NodeMCU. I did get it to work with a DHT11 and slightly different display. I had to strip all the pressure related code out as DHT11 does not provide pressure. Took a long time but I learned a lot. My solution seems buggy as the client will only receive one set of data and display it before it disconnects. Since the intent of my investment has been met, I’m happy with the result. However, if somone else has this issue let me know. I would like to understand why the client disconnects after one reading. I am very impressed with your work and plan to look at some of your other work and offerings.

    Reply
  39. This seems to work well for me for the most part. However, after logging the data for some time, I notice that occasionally I will get zeros for the readings. Not sure why. Anybody have a good way of error checking the data?

    Reply
    • Not sure it’s the same thing you are experiencing but I am of the opinion that after a while the actual wifi connection is lost, I suspect due to weak signal, interference, etc. I hit the reset button on my client device and it reconnects and might remain connected for 12 hour or a week. Mine seems to fail more when it is cold but I have no hard data on this, just “seems” like it.

      Do you think you are getting bad readings from the sensors? I built this with three different sensors trying to find the one I thought was most accurate. I do not recall getting bad (zeros) reads from the sensors, only losing the connection like I mentioned. I suppose we could make it more robust by making it verify the connection and reset or reboot automatically but I haven’t done so.

      Reply
  40. Üdvözlöm Sara! István vagyok.Egy kis segítséget szeretnék kérni. Amit meg akarok valósítani az a következő. Wemos D1 Mini wi-fi AP mód, DS18b20 vagy BMP180 és ST7789 oled. Ez lenne az adó, több is külső belső hőmérséklet, stb. A vevő: Wemos D1 Mini I2C 20×4 LCD. Valamint I2C 16×4 LCD big font és a kijelzése egy tizedesjegyig látható pl:17,5 Celsius. Válaszát előre is köszönöm. Üdv: István

    Reply
  41. Hi, is there a micropython version for this project? Would it be possible to have communication between a raspberry pi pico W and esp 8266?

    Thank you

    Reply
    • Hi.
      Yes.
      That would be possible. Unfortunately, at the moment, we don’t have any tutorials about this subject in micropython.
      Regards,
      Sara

      Reply
  42. A project I completed in the past was an automatic doorbell. The client (ESP D1 R2 Mini) is on the porch sensing and the server (ESP01) is inside the house listening. If the client’s ultrasonic sensor (HC-SR04) detects someone on the porch it sends a UDP packet “Sound the Alarm” to the server. The server then plays the tones.

    Everything works great, however as an exercise I want to upgrade from UDP to TCP because of the additional benefits of TCP. I thought I would look at this example. However, I have a question. Is it possible to use the TCP protocol in as a stand-alone transport layer much like UDP? Or does TCP always include the additional application, internet, and network access layers? If TCP can be used as a stand-alone transport layer, do you have a tutorial that demonstrates it?

    Reply
  43. Hi I get the following error at compilation:

    error: no matching function for call to ‘HTTPClient::begin(WiFiClient&, const char*&)’
    http.begin(client, serverName);

    I thought maybe I had old libraries, but just updated to the newest arduino IDE with a fresh install and added all the new libs as you have posted here.

    let me know what you think. thanks

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.