{"id":92152,"date":"2020-01-07T18:00:01","date_gmt":"2020-01-07T18:00:01","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=92152"},"modified":"2025-03-15T11:24:16","modified_gmt":"2025-03-15T11:24:16","slug":"esp32-client-server-wi-fi","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-client-server-wi-fi\/","title":{"rendered":"ESP32 Client-Server Wi-Fi Communication Between Two Boards"},"content":{"rendered":"\n<p>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&#8217;ll learn how to send data from one board to the other using HTTP requests. The ESP32 boards will be programmed using Arduino IDE.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Client-Server-Wi-Fi-Communication-Between-Two-Boards.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Client-Server Wi-Fi Communication Between Two Boards\" class=\"wp-image-92557\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Client-Server-Wi-Fi-Communication-Between-Two-Boards.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Client-Server-Wi-Fi-Communication-Between-Two-Boards.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Client-Server-Wi-Fi-Communication-Between-Two-Boards.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Client-Server-Wi-Fi-Communication-Between-Two-Boards.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p>For demonstration purposes, we&#8217;ll send <a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\">BME280 sensor readings<\/a> from one board to the other. The receiver will <a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-dht-temperature-and-humidity-oled-display\/\">display the readings on an OLED display<\/a>.<\/p>\n\n\n\n<p>If you have an ESP8266 board, you can read this dedicated guide: <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-client-server-wi-fi\/\">ESP8266 NodeMCU Client-Server Wi-Fi Communication<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Watch the Video Demonstration<\/h2>\n\n\n\n<p>To see how the project works, you can watch the following video demonstration:<\/p>\n\n\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/2z7Ow4PjJRc?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Project Overview<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Server-Client-HTTP-GET-Communication.jpg?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"1200\" height=\"739\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Server-Client-HTTP-GET-Communication.jpg?resize=1200%2C739&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Client-Server Wi-Fi Communication Between Project overview\" class=\"wp-image-92515\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Server-Client-HTTP-GET-Communication.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Server-Client-HTTP-GET-Communication.jpg?resize=300%2C185&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Server-Client-HTTP-GET-Communication.jpg?resize=1024%2C630&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Server-Client-HTTP-GET-Communication.jpg?resize=768%2C473&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>The ESP32 server creates its own wireless network (<a href=\"https:\/\/randomnerdtutorials.com\/esp32-access-point-ap-web-server\/\">ESP32 Soft-Access Point<\/a>). So, other Wi-Fi devices can connect to that network (<strong>SSID:<\/strong> ESP32-Access-Point, <strong>Password:<\/strong> 123456789).<\/li>\n\n\n\n<li>The ESP32 client is set as a station. So, it can connect to the ESP32 server wireless network.<\/li>\n\n\n\n<li>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: <span class=\"rnthl rntliteral\">\/temperature<\/span>, <span class=\"rnthl rntliteral\">\/humidity<\/span> or <span class=\"rnthl rntliteral\">\/pressure<\/span>.<\/li>\n\n\n\n<li>The server listens for incoming requests and sends an appropriate response with the readings.<\/li>\n\n\n\n<li>The client receives the readings and displays them on the OLED display.<\/li>\n<\/ul>\n\n\n\n<p>As an example, the ESP32 client requests temperature, humidity and pressure to the server by making requests on the server IP address followed by <span class=\"rnthl rntliteral\">\/temperature<\/span>, <span class=\"rnthl rntliteral\">\/humidity<\/span> and <span class=\"rnthl rntliteral\">\/pressure<\/span>, respectively. <\/p>\n\n\n\n<p>The ESP32 server is listening on those routes and when a request is made, it sends the corresponding sensor readings via HTTP response.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Parts Required<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Client-Server-Interaction-Sensor-Readings.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Parts required for ESP32 Client-Server Communication\" class=\"wp-image-92553\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Client-Server-Interaction-Sensor-Readings.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Client-Server-Interaction-Sensor-Readings.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>For this tutorial, you need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a aria-label=\"ESP32 Development boards (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noreferrer noopener\">2x ESP32 Development boards<\/a> &#8211; read <a aria-label=\"Best ESP32 Boards Review (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/esp32-development-boards-review-comparison\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best ESP32 Boards Review<\/a><\/li>\n\n\n\n<li><a aria-label=\"BME280 sensor\u2028 (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/bme280-sensor-module\/\" target=\"_blank\" rel=\"noreferrer noopener\">BME280 sensor<\/a><\/li>\n\n\n\n<li><a aria-label=\"I2C SSD1306 OLED display\u2028 (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/oled-display-128x64-0-96-inch\/\" target=\"_blank\" rel=\"noreferrer noopener\">I2C SSD1306 OLED display<\/a><\/li>\n\n\n\n<li><a aria-label=\"Jumper Wires\u2028 (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper Wires<\/a><\/li>\n\n\n\n<li><a aria-label=\"Breaboard (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noreferrer noopener\">Breaboard<\/a><\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Libraries<\/h2>\n\n\n\n<p>For this tutorial you need to install the following libraries:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Asynchronous Web Server Libraries<\/h3>\n\n\n\n<p>We&#8217;ll use the following libraries to handle HTTP request:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/ESP32Async\/ESPAsyncWebServer\" target=\"_blank\" rel=\"noreferrer noopener\">ESPAsyncWebServer\u00a0<\/a>by ESP32Async<\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/ESP32Async\/AsyncTCP\" target=\"_blank\" rel=\"noreferrer noopener\">AsyncTCP<\/a>\u00a0by ESP32Async<\/li>\n<\/ul>\n\n\n\n<p>You can install those libraries in the Arduino IDE Library Manager. Go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong>&nbsp;and search for the libraries\u2019 names.<\/p>\n\n\n\n<p class=\"rntbox rntclblue\">You may also like: <a rel=\"noreferrer noopener\" aria-label=\"Build an Asynchronous Web Server with the ESP32 (opens in a new tab)\" href=\"https:\/\/randomnerdtutorials.com\/esp32-dht11-dht22-temperature-humidity-web-server-arduino-ide\/\" target=\"_blank\">Build an Asynchronous Web Server with the ESP32<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">BME280 Libraries<\/h3>\n\n\n\n<p>The following libraries can be installed through the Arduino Library Manager. Go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&gt;&nbsp;<strong>Manage Libraries<\/strong>&nbsp;and search for the library name.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/adafruit\/Adafruit_BME280_Library\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit_BME280 library<\/a><\/li>\n\n\n\n<li><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit unified sensor library<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"rntbox rntclblue\">You may also like: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\">Interface BME280 with ESP32 (Guide)<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">I2C SSD1306 OLED Libraries<\/h3>\n\n\n\n<p>To interface with the OLED display you need the following libraries. These can be installed through the Arduino Library Manager. Go to <strong>Sketch <\/strong>&gt; <strong>Include Library<\/strong>&gt; <strong>Manage Libraries<\/strong> and search for the library name.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a aria-label=\"Adafruit SSD1306\u2028 (opens in a new tab)\" href=\"https:\/\/github.com\/adafruit\/Adafruit_SSD1306\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit SSD1306<\/a><\/li>\n\n\n\n<li><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/github.com\/adafruit\/Adafruit-GFX-Library\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit GFX Library<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"rntbox rntclblue\">You may also like: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-ssd1306-oled-display-arduino-ide\/\">I2C SSD1306 OLED Display with ESP32 (Guide)<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">#1 ESP32 Server (Access Point)<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Server-BME-280.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Server with BME280 temperature humidity pressure\" class=\"wp-image-92550\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Server-BME-280.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Server-BME-280.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>The ESP32 server is an <a href=\"https:\/\/randomnerdtutorials.com\/esp32-access-point-ap-web-server\/\">Access Point (AP)<\/a>, that listens for requests on the <span class=\"rnthl rntliteral\">\/temperature<\/span>, <span class=\"rnthl rntliteral\">\/humidity<\/span> and <span class=\"rnthl rntliteral\">\/pressure<\/span> URLs. When it gets requests on those URLs, it sends the latest BME280 sensor readings. <\/p>\n\n\n\n<p>For demonstration purposes, we&#8217;re using a BME280 sensor, but you can use any other sensor by modifying a few lines of code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic Diagram<\/h3>\n\n\n\n<p>Wire the <a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\">ESP32 to the BME280 sensor<\/a> as shown in the following schematic diagram. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"669\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-bme280_schematic.jpg?resize=768%2C669&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 BME280 Wiring Schematic Diagram\" class=\"wp-image-86439\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-bme280_schematic.jpg?w=768&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-bme280_schematic.jpg?resize=300%2C261&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure><\/div>\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BME280<\/strong><\/td><td><strong>ESP32<\/strong><\/td><\/tr><tr><td>VIN\/VCC<\/td><td><span class=\"rnthl rntcred\">3.3V<\/span><\/td><\/tr><tr><td>GND<\/td><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><\/tr><tr><td>SCL<\/td><td><span class=\"rnthl rntcblue\">GPIO 22<\/span><\/td><\/tr><tr><td>SDA<\/td><td><span class=\"rnthl rntcgreen\">GPIO 21<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Arduino Sketch for #1 ESP32 Server<\/h3>\n\n\n\n<p>Upload the following code to your board.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-client-server-wi-fi\/\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*\/\n\n\/\/ Import required libraries\n#include &quot;WiFi.h&quot;\n#include &quot;ESPAsyncWebServer.h&quot;\n\n#include &lt;Wire.h&gt;\n#include &lt;Adafruit_Sensor.h&gt;\n#include &lt;Adafruit_BME280.h&gt;\n\n\/\/ Set your access point network credentials\nconst char* ssid = &quot;ESP32-Access-Point&quot;;\nconst char* password = &quot;123456789&quot;;\n\n\/*#include &lt;SPI.h&gt;\n#define BME_SCK 18\n#define BME_MISO 19\n#define BME_MOSI 23\n#define BME_CS 5*\/\n\nAdafruit_BME280 bme; \/\/ I2C\n\/\/Adafruit_BME280 bme(BME_CS); \/\/ hardware SPI\n\/\/Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); \/\/ software SPI\n\n\/\/ Create AsyncWebServer object on port 80\nAsyncWebServer server(80);\n\nString readTemp() {\n  return String(bme.readTemperature());\n  \/\/return String(1.8 * bme.readTemperature() + 32);\n}\n\nString readHumi() {\n  return String(bme.readHumidity());\n}\n\nString readPres() {\n  return String(bme.readPressure() \/ 100.0F);\n}\n\nvoid setup(){\n  \/\/ Serial port for debugging purposes\n  Serial.begin(115200);\n  Serial.println();\n  \n  \/\/ Setting the ESP as an access point\n  Serial.print(&quot;Setting AP (Access Point)\u2026&quot;);\n  \/\/ Remove the password parameter, if you want the AP (Access Point) to be open\n  WiFi.softAP(ssid, password);\n\n  IPAddress IP = WiFi.softAPIP();\n  Serial.print(&quot;AP IP address: &quot;);\n  Serial.println(IP);\n\n  server.on(&quot;\/temperature&quot;, HTTP_GET, [](AsyncWebServerRequest *request){\n    request-&gt;send(200, &quot;text\/plain&quot;, readTemp().c_str());\n  });\n  server.on(&quot;\/humidity&quot;, HTTP_GET, [](AsyncWebServerRequest *request){\n    request-&gt;send(200, &quot;text\/plain&quot;, readHumi().c_str());\n  });\n  server.on(&quot;\/pressure&quot;, HTTP_GET, [](AsyncWebServerRequest *request){\n    request-&gt;send(200, &quot;text\/plain&quot;, readPres().c_str());\n  });\n  \n  bool status;\n\n  \/\/ default settings\n  \/\/ (you can also pass in a Wire library object like &amp;Wire2)\n  status = bme.begin(0x76);  \n  if (!status) {\n    Serial.println(&quot;Could not find a valid BME280 sensor, check wiring!&quot;);\n    while (1);\n  }\n  \n  \/\/ Start server\n  server.begin();\n}\n \nvoid loop(){\n  \n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP\/ESP_Client_Server\/ESP_Server_Access_Point_AP_BME280.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How the code works<\/h3>\n\n\n\n<p>Start by including the necessary libraries. Include the <span class=\"rnthl rntliteral\">WiFi.h<\/span> library and the <span class=\"rnthl rntliteral\">ESPAsyncWebServer.h<\/span> library to handle incoming HTTP requests.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include \"WiFi.h\"\n#include \"ESPAsyncWebServer.h\"<\/code><\/pre>\n\n\n\n<p>Include the following libraries to interface with the BME280 sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;Wire.h&gt;\n#include &lt;Adafruit_Sensor.h&gt;\n#include &lt;Adafruit_BME280.h&gt;<\/code><\/pre>\n\n\n\n<p>In the following variables, define your access point network credentials:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* ssid = \"ESP32-Access-Point\";\nconst char* password = \"123456789\";<\/code><\/pre>\n\n\n\n<p>We&#8217;re setting the SSID to <span class=\"rnthl rntliteral\">ESP32-Access-Point<\/span>, but you can give it any other name. You can also change the password. By default, its set to <span class=\"rnthl rntliteral\">123456789<\/span>.<\/p>\n\n\n\n<p>Create an instance for the BME280 sensor called <span class=\"rnthl rntliteral\">bme<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Adafruit_BME280 bme;<\/code><\/pre>\n\n\n\n<p>Create an asynchronous web server on port 80.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>AsyncWebServer server(80);<\/code><\/pre>\n\n\n\n<p>Then, create three functions that return the temperature, humidity, and pressure as String variables.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String readTemp() {\n  return String(bme.readTemperature());\n  \/\/return String(1.8 * bme.readTemperature() + 32);\n}\n\nString readHumi() {\n  return String(bme.readHumidity());\n}\n\nString readPres() {\n  return String(bme.readPressure() \/ 100.0F);\n}<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor for demonstration purposes.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<p>Set your ESP32 as an access point with the SSID name and password defined earlier.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>WiFi.softAP(ssid, password);<\/code><\/pre>\n\n\n\n<p>Then, handle the routes where the ESP32 will be listening for incoming requests.<\/p>\n\n\n\n<p>For example, when the ESP32 server receives a request on the <span class=\"rnthl rntliteral\">\/temperature<\/span> URL, it sends the temperature returned by the <span class=\"rnthl rntliteral\">readTemp()<\/span> function as a char (that&#8217;s why we use the <span class=\"rnthl rntliteral\">c_str()<\/span> method.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>server.on(\"\/temperature\", HTTP_GET, &#091;](AsyncWebServerRequest *request){\n  request-&gt;send_P(200, \"text\/plain\", readTemp().c_str());\n});<\/code><\/pre>\n\n\n\n<p>The same happens when the ESP receives a request on the <span class=\"rnthl rntliteral\">\/humidity<\/span> and <span class=\"rnthl rntliteral\">\/pressure<\/span> URLs.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>server.on(\"\/humidity\", HTTP_GET, &#091;](AsyncWebServerRequest *request){\n  request-&gt;send_P(200, \"text\/plain\", readHumi().c_str());\n});\nserver.on(\"\/pressure\", HTTP_GET, &#091;](AsyncWebServerRequest *request){\n  request-&gt;send_P(200, \"text\/plain\", readPres().c_str());\n});<\/code><\/pre>\n\n\n\n<p>The following lines initialize the BME280 sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>bool status;\n\n\/\/ default settings\n\/\/ (you can also pass in a Wire library object like &amp;Wire2)\nstatus = bme.begin(0x76);\nif (!status) {\n  Serial.println(\"Could not find a valid BME280 sensor, check wiring!\");\n  while (1);\n}<\/code><\/pre>\n\n\n\n<p>Finally, start the server.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>server.begin();<\/code><\/pre>\n\n\n\n<p>Because this is an asynchronous web server, there&#8217;s nothing in the <span class=\"rnthl rntliteral\">loop()<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void loop(){\n\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Testing the ESP32 Server<\/h3>\n\n\n\n<p>Upload the code to your board and open the Serial Monitor. You should get something as follows:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"803\" height=\"416\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/access-point-ip-address-esp32-server.jpg?resize=803%2C416&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Testing the ESP32 Server Serial Monitor Arduino IDE\" class=\"wp-image-92532\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/access-point-ip-address-esp32-server.jpg?w=803&amp;quality=100&amp;strip=all&amp;ssl=1 803w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/access-point-ip-address-esp32-server.jpg?resize=300%2C155&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/access-point-ip-address-esp32-server.jpg?resize=768%2C398&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 803px) 100vw, 803px\" \/><\/figure><\/div>\n\n\n<p>This means that the access point was set successfully. <\/p>\n\n\n\n<p>Now, to make sure it is listening for temperature, humidity and pressure requests, you need to connect to its network.<\/p>\n\n\n\n<p>In your smartphone, go to the Wi-Fi settings and connect to the <strong>ESP32-Access-Point<\/strong>. The password is <strong>123456789<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"791\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/connect-to-esp32-access-point-smartphone.png?resize=750%2C791&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Server Access Point AP Connection\" class=\"wp-image-92533\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/connect-to-esp32-access-point-smartphone.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/connect-to-esp32-access-point-smartphone.png?resize=284%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 284w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>While connected to the access point, open your browser and type <span class=\"rnthl rntliteral\">192.168.4.1\/temperature<\/span><\/p>\n\n\n\n<p>You should get the temperature value in your browser:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"343\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/temperature-request-browser-esp32.png?resize=750%2C343&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Server Access Point AP Test request temperature\" class=\"wp-image-92534\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/temperature-request-browser-esp32.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/temperature-request-browser-esp32.png?resize=300%2C137&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Try this URL path for the humidity <span class=\"rnthl rntliteral\">192.168.4.1\/humidity<\/span>:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"319\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/humidity-request-browser-esp32.png?resize=750%2C319&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Server Access Point AP Test request humidity\" class=\"wp-image-92537\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/humidity-request-browser-esp32.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/humidity-request-browser-esp32.png?resize=300%2C128&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Finally, go to <span class=\"rnthl rntliteral\">192.168.4.1\/pressure<\/span> URL:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"330\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/pressure-request-browser-esp32.png?resize=750%2C330&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Server Access Point AP Test request pressure\" class=\"wp-image-92535\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/pressure-request-browser-esp32.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/pressure-request-browser-esp32.png?resize=300%2C132&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>If you&#8217;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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"> #2 ESP32 Client (Station)<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Client-Display-Sensor-Readings-OLED.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Client Receive Readings via HTTP GET Request BME280\" class=\"wp-image-92552\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Client-Display-Sensor-Readings-OLED.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Client-Display-Sensor-Readings-OLED.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>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 <span class=\"rnthl rntliteral\">\/temperature<\/span>, <span class=\"rnthl rntliteral\">\/humidity<\/span>, and <span class=\"rnthl rntliteral\">\/pressure<\/span> URL routes. Then, it displays the readings on an OLED display.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic Diagram<\/h3>\n\n\n\n<p>Wire the <a href=\"https:\/\/randomnerdtutorials.com\/esp32-ssd1306-oled-display-arduino-ide\/\">ESP32 to the OLED display<\/a> as shown in the following schematic diagram.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"685\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP32_OLED.png?resize=873%2C685&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-85566\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP32_OLED.png?w=873&amp;quality=100&amp;strip=all&amp;ssl=1 873w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP32_OLED.png?resize=300%2C235&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP32_OLED.png?resize=768%2C603&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 873px) 100vw, 873px\" \/><\/figure><\/div>\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>OLED<\/strong><\/td><td><strong>ESP32<\/strong><\/td><\/tr><tr><td>VIN\/VCC<\/td><td><span class=\"rnthl rntcred\">VIN<\/span><\/td><\/tr><tr><td>GND<\/td><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><\/tr><tr><td>SCL<\/td><td><span class=\"rnthl rntclgray\">GPIO 22<\/span><\/td><\/tr><tr><td>SDA<\/td><td><span class=\"rnthl rntcyellow\">GPIO 21<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Arduino Sketch for #2 ESP32 Client<\/h3>\n\n\n\n<p>Upload the following code to the other ESP32:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-client-server-wi-fi\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files.\n  \n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n*\/\n\n#include &lt;WiFi.h&gt;\n#include &lt;HTTPClient.h&gt;\n\nconst char* ssid = &quot;ESP32-Access-Point&quot;;\nconst char* password = &quot;123456789&quot;;\n\n\/\/Your IP address or domain name with URL path\nconst char* serverNameTemp = &quot;http:\/\/192.168.4.1\/temperature&quot;;\nconst char* serverNameHumi = &quot;http:\/\/192.168.4.1\/humidity&quot;;\nconst char* serverNamePres = &quot;http:\/\/192.168.4.1\/pressure&quot;;\n\n#include &lt;Wire.h&gt;\n#include &lt;Adafruit_GFX.h&gt;\n#include &lt;Adafruit_SSD1306.h&gt;\n\n#define SCREEN_WIDTH 128 \/\/ OLED display width, in pixels\n#define SCREEN_HEIGHT 64 \/\/ OLED display height, in pixels\n\n\/\/ Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)\n#define OLED_RESET     4 \/\/ Reset pin # (or -1 if sharing Arduino reset pin)\nAdafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &amp;Wire, OLED_RESET);\n\nString temperature;\nString humidity;\nString pressure;\n\nunsigned long previousMillis = 0;\nconst long interval = 5000; \n\nvoid setup() {\n  Serial.begin(115200);\n  \n  \/\/ Address 0x3C for 128x64, you might need to change this value (use an I2C scanner)\n  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {\n    Serial.println(F(&quot;SSD1306 allocation failed&quot;));\n    for(;;); \/\/ Don't proceed, loop forever\n  }\n  display.clearDisplay();\n  display.setTextColor(WHITE);\n  \n  WiFi.begin(ssid, password);\n  Serial.println(&quot;Connecting&quot;);\n  while(WiFi.status() != WL_CONNECTED) { \n    delay(500);\n    Serial.print(&quot;.&quot;);\n  }\n  Serial.println(&quot;&quot;);\n  Serial.print(&quot;Connected to WiFi network with IP Address: &quot;);\n  Serial.println(WiFi.localIP());\n}\n\nvoid loop() {\n  unsigned long currentMillis = millis();\n  \n  if(currentMillis - previousMillis &gt;= interval) {\n     \/\/ Check WiFi connection status\n    if(WiFi.status()== WL_CONNECTED ){ \n      temperature = httpGETRequest(serverNameTemp);\n      humidity = httpGETRequest(serverNameHumi);\n      pressure = httpGETRequest(serverNamePres);\n      Serial.println(&quot;Temperature: &quot; + temperature + &quot; *C - Humidity: &quot; + humidity + &quot; % - Pressure: &quot; + pressure + &quot; hPa&quot;);\n      \n      display.clearDisplay();\n      \n      \/\/ display temperature\n      display.setTextSize(2);\n      display.setTextColor(WHITE);\n      display.setCursor(0,0);\n      display.print(&quot;T: &quot;);\n      display.print(temperature);\n      display.print(&quot; &quot;);\n      display.setTextSize(1);\n      display.cp437(true);\n      display.write(248);\n      display.setTextSize(2);\n      display.print(&quot;C&quot;);\n      \n      \/\/ display humidity\n      display.setTextSize(2);\n      display.setCursor(0, 25);\n      display.print(&quot;H: &quot;);\n      display.print(humidity);\n      display.print(&quot; %&quot;); \n      \n      \/\/ display pressure\n      display.setTextSize(2);\n      display.setCursor(0, 50);\n      display.print(&quot;P:&quot;);\n      display.print(pressure);\n      display.setTextSize(1);\n      display.setCursor(110, 56);\n      display.print(&quot;hPa&quot;);\n           \n      display.display();\n      \n      \/\/ save the last HTTP GET Request\n      previousMillis = currentMillis;\n    }\n    else {\n      Serial.println(&quot;WiFi Disconnected&quot;);\n    }\n  }\n}\n\nString httpGETRequest(const char* serverName) {\n  WiFiClient client;\n  HTTPClient http;\n    \n  \/\/ Your Domain name with URL path or IP address with path\n  http.begin(client, serverName);\n  \n  \/\/ Send HTTP POST request\n  int httpResponseCode = http.GET();\n  \n  String payload = &quot;--&quot;; \n  \n  if (httpResponseCode&gt;0) {\n    Serial.print(&quot;HTTP Response code: &quot;);\n    Serial.println(httpResponseCode);\n    payload = http.getString();\n  }\n  else {\n    Serial.print(&quot;Error code: &quot;);\n    Serial.println(httpResponseCode);\n  }\n  \/\/ Free resources\n  http.end();\n\n  return payload;\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP\/ESP_Client_Server\/ESP_Client_OLED_Display.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How the code works<\/h3>\n\n\n\n<p>Include the necessary libraries for the Wi-Fi connection and for making HTTP requests:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;WiFi.h&gt;\n#include &lt;HTTPClient.h&gt;<\/code><\/pre>\n\n\n\n<p>Insert the ESP32 server network credentials. If you&#8217;ve changed the default network credentials in the ESP32 server, you should change them here to match.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* ssid = \"ESP32-Access-Point\";\nconst char* password = \"123456789\";<\/code><\/pre>\n\n\n\n<p>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&#8217;ll be making requests on the <span class=\"rnthl rntliteral\">\/temperature<\/span>, <span class=\"rnthl rntliteral\">\/humidity<\/span> and <span class=\"rnthl rntliteral\">\/pressure<\/span> URLs.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* serverNameTemp = \"http:\/\/192.168.4.1\/temperature\";\nconst char* serverNameHumi = \"http:\/\/192.168.4.1\/humidity\";\nconst char* serverNamePres = \"http:\/\/192.168.4.1\/pressure\";<\/code><\/pre>\n\n\n\n<p>Include the libraries to interface with the OLED display:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;SPI.h&gt;\n#include &lt;Wire.h&gt;\n#include &lt;Adafruit_GFX.h&gt;\n#include &lt;Adafruit_SSD1306.h&gt;<\/code><\/pre>\n\n\n\n<p>Set the OLED display size:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define SCREEN_WIDTH 128 \/\/ OLED display width, in pixels\n#define SCREEN_HEIGHT 64 \/\/ OLED display height, in pixels<\/code><\/pre>\n\n\n\n<p>Create a <span class=\"rnthl rntliteral\">display<\/span> object with the size you&#8217;ve defined earlier and with I2C communication protocol.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &amp;Wire, OLED_RESET);<\/code><\/pre>\n\n\n\n<p>Initialize string variables that will hold the temperature, humidity and pressure readings retrieved by the server.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String temperature;\nString humidity;\nString pressure;<\/code><\/pre>\n\n\n\n<p>Set the time interval between each request. By default, it&#8217;s set to 5 seconds, but you can change it to any other interval.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const long interval = 5000; <\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the OLED display:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Address 0x3C for 128x64, you might need to change this value (use an I2C scanner)\nif(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {\n  Serial.println(F(\"SSD1306 allocation failed\"));\n  for(;;); \/\/ Don't proceed, loop forever\n}\ndisplay.clearDisplay();\ndisplay.setTextColor(WHITE);<\/code><\/pre>\n\n\n\n<p class=\"rntbox rntclgreen\"><strong>Note: <\/strong> if your OLED display is not working, check its I2C address using an <a href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/master\/Projects\/LCD_I2C\/I2C_Scanner.ino\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"I2C scanner sketch (opens in a new tab)\">I2C scanner sketch<\/a> and change the code accordingly. <\/p>\n\n\n\n<p>Connect the ESP32 client to the ESP32 server network.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>WiFi.begin(ssid, password);\nSerial.println(\"Connecting\");\nwhile(WiFi.status() != WL_CONNECTED) { \n  delay(500);\n  Serial.print(\".\");\n}\nSerial.println(\"\");\nSerial.print(\"Connected to WiFi network with IP Address: \");<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span> is where we make the HTTP GET requests. We&#8217;ve created a function called <span class=\"rnthl rntliteral\">httpGETRequest()<\/span> that accepts as argument the URL path where we want to make the request and returns the response as a <span class=\"rnthl rntliteral\">String<\/span>.<\/p>\n\n\n\n<p>You can use the next function in your projects to simplify your code:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String httpGETRequest(const char* serverName) {\n  HTTPClient http;\n    \n  \/\/ Your IP address with path or Domain name with URL path \n  http.begin(serverName);\n  \n  \/\/ Send HTTP POST request\n  int httpResponseCode = http.GET();\n  \n  String payload = \"--\"; \n  \n  if (httpResponseCode&gt;0) {\n    Serial.print(\"HTTP Response code: \");\n    Serial.println(httpResponseCode);\n    payload = http.getString();\n  }\n  else {\n    Serial.print(\"Error code: \");\n    Serial.println(httpResponseCode);\n  }\n  \/\/ Free resources\n  http.end();\n\n  return payload;\n}<\/code><\/pre>\n\n\n\n<p>We use that function to get the temperature, humidity and pressure readings from the server.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>temperature = httpGETRequest(serverNameTemp);\nhumidity = httpGETRequest(serverNameHumi);\npressure = httpGETRequest(serverNamePres);<\/code><\/pre>\n\n\n\n<p>Print those readings in the Serial Monitor for debugging.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.println(\"Temperature: \" + temperature + \" *C - Humidity: \" + humidity + \" % - Pressure: \" + pressure + \" hPa\");<\/code><\/pre>\n\n\n\n<p>Then, display the temperature in the OLED display:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>display.setTextSize(2);\ndisplay.setTextColor(WHITE);\ndisplay.setCursor(0,0);\ndisplay.print(\"T: \");\ndisplay.print(temperature);\ndisplay.print(\" \");\ndisplay.setTextSize(1);\ndisplay.cp437(true);\ndisplay.write(248);\ndisplay.setTextSize(2);\ndisplay.print(\"C\");<\/code><\/pre>\n\n\n\n<p>The humidity:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>display.setTextSize(2);\ndisplay.setCursor(0, 25);\ndisplay.print(\"H: \");\ndisplay.print(humidity);\ndisplay.print(\" %\"); <\/code><\/pre>\n\n\n\n<p>Finally, the pressure reading:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>display.setTextSize(2);\ndisplay.setCursor(0, 50);\ndisplay.print(\"P:\");\ndisplay.print(pressure);\ndisplay.setTextSize(1);\ndisplay.setCursor(110, 56);\ndisplay.print(\"hPa\");\n\ndisplay.display();<\/code><\/pre>\n\n\n\n<p>We use timers instead of delays to make a request every x number of seconds. That&#8217;s why we have the <span class=\"rnthl rntliteral\">previousMillis<\/span>, <span class=\"rnthl rntliteral\">currentMillis<\/span> variables and use the <span class=\"rnthl rntliteral\">millis()<\/span> function. We have an article that shows the <a href=\"https:\/\/randomnerdtutorials.com\/why-you-shouldnt-always-use-the-arduino-delay-function\/\">difference between timers and delays<\/a> that you might find useful (or read <a href=\"https:\/\/randomnerdtutorials.com\/esp32-pir-motion-sensor-interrupts-timers\/\">ESP32 Timers<\/a>).<\/p>\n\n\n\n<p>Upload the sketch to #2 ESP32 (client) to test if everything is working properly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Testing the ESP32 Client<\/h3>\n\n\n\n<p>Having both boards fairly close and powered, you\u2019ll see that ESP #2 is receiving new temperature, humidity and pressure readings every 5 seconds from ESP #1.<\/p>\n\n\n\n<p>This is what you should see on the ESP32 Client Serial Monitor.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"721\" height=\"424\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/esp32-client-receive-sensor-readings.jpg?resize=721%2C424&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Testing the ESP32 Client Serial Monitor Arduino IDE\" class=\"wp-image-92545\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/esp32-client-receive-sensor-readings.jpg?w=721&amp;quality=100&amp;strip=all&amp;ssl=1 721w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/esp32-client-receive-sensor-readings.jpg?resize=300%2C176&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 721px) 100vw, 721px\" \/><\/figure><\/div>\n\n\n<p>The sensor readings are also displayed in the OLED.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/Display-Readings-OLED-ESP32-Client.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Client Server Communication example data exchange for sensor readigns\" class=\"wp-image-92551\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/Display-Readings-OLED-ESP32-Client.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/Display-Readings-OLED-ESP32-Client.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>That&#8217;s it! Your two boards are talking with each other.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"365\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-to-ESP32-Client-Server-HTTP-Communication.jpg?resize=750%2C365&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 to ESP32 Talking with each other with Wireless Communication\" class=\"wp-image-92565\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-to-ESP32-Client-Server-HTTP-Communication.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-to-ESP32-Client-Server-HTTP-Communication.jpg?resize=300%2C146&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial you&#8217;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&#8217;ve shown how to send BME280 sensor readings, but you can use any other sensor or send any other data. Other recommended sensors:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-dht11-dht22-temperature-humidity-web-server-arduino-ide\/\">ESP32 DHT11 or DHT22 (Guide)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-ds18b20-temperature-arduino-ide\/\">ESP32 DS18B20 (Guide)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/dht11-vs-dht22-vs-lm35-vs-ds18b20-vs-bme280-vs-bmp180\/\">DHT11 vs DHT22 vs DS18B20 vs BME280<\/a><\/li>\n<\/ul>\n\n\n\n<p>We have a similar tutorial for the ESP8266 that you might find useful:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/RandomNerdTutorials.com\/esp8266-nodemcu-client-server-wi-fi\/\">ESP8266 NodeMCU Client-Server Wi-Fi Communication Between Two Boards<\/a><\/li>\n<\/ul>\n\n\n\n<p>We hope you&#8217;ve found this tutorial useful. We&#8217;re preparing more tutorials like these. So, stay tuned and <a href=\"https:\/\/randomnerdtutorials.com\/download\">subscribe to our blog<\/a>!<\/p>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;ll learn how to &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32 Client-Server Wi-Fi Communication Between Two Boards\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-client-server-wi-fi\/#more-92152\" aria-label=\"Read more about ESP32 Client-Server Wi-Fi Communication Between Two Boards\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":92557,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[281,276,277,299,264],"tags":[],"class_list":["post-92152","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp32","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/01\/ESP32-Client-Server-Wi-Fi-Communication-Between-Two-Boards.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/92152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=92152"}],"version-history":[{"count":1,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/92152\/revisions"}],"predecessor-version":[{"id":167988,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/92152\/revisions\/167988"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/92557"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=92152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=92152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=92152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}