

- #ESP8266 ARDUINO EXAMPLE CODE HOW TO#
- #ESP8266 ARDUINO EXAMPLE CODE INSTALL#
- #ESP8266 ARDUINO EXAMPLE CODE SERIAL#
- #ESP8266 ARDUINO EXAMPLE CODE CODE#
- #ESP8266 ARDUINO EXAMPLE CODE PASSWORD#
Thus, we will setup a server route and a handling function that will be executed when a request is made on that route. Now that we have connected the device to a WiFi network and obtained its local IP, we will handle the web server configuration.


In order to reach the web server from outside the local network we would need to portforward the router, which is a more advanced procedure that we will not cover here. Please note that we will only be able to reach the web server from inside the local network to which the ESP is connected.
#ESP8266 ARDUINO EXAMPLE CODE SERIAL#
Moving on to the setup function, we will open a serial connection and then we will connect the ESP8266 to the WiFi network to which we provided the credentials as global variables.Īfter the connection is established, we will print the ESP8266 IP on the local network, so we can then reach the server. In case we use a port different than 80, we need to specify it when contacting the server using a web browser. Thus, since our client will be a web browser, it will use port 80 by default and we don’t need to explicitly specify it. In our case, we will use port 80, which is the default HTTP port. This value is relevant for the client to be able to connect to the server. It’s important to take in consideration that the constructor of this class receives as input the port where the HTTP server will be listening for incoming requests. To finalize the global variables section, we will declare an object of class AsyncWebServer, which will expose the methods needed for us to setup the HTTP server and handle the incoming requests.
#ESP8266 ARDUINO EXAMPLE CODE PASSWORD#
We will need both the network SSID (network name) and password.Ĭonst char* password = "YourNetworkPassword" We will also declare two global variables which will hold the credentials of the WiFi network to which we are going to connect the ESP8266. Then, we will also need to include the two libraries we have just installed, namely the ESPAsyncTCP.h and the ESPAsyncWebServer.h. First of all, we will need the ESP8266WiFi.h, so we can connect the device to a WiFi network and later receive the HTTP requests.
#ESP8266 ARDUINO EXAMPLE CODE CODE#
We start the code by making the necessary library includes.

Once the procedure is complete for both of the libraries, they should be available to use on the Arduino environment. Delete that appended -master and keep the remaining name. Take in consideration that the extracted folders should have a -master appended in the name. Then, simply select the “ Download ZIP” option and the files should be transferred to your computer.Īfter that, extract the files to your Arduino IDE libraries directory, which is usually located in the following path:Ĭ:\Users\UserName\Documents\Arduino\libraries To download each library, go to their GitHub page and click the “ Clone or download” button at the top of the page, as indicated in figure 1.įigure 1 – Downloading the libraries source code.
#ESP8266 ARDUINO EXAMPLE CODE INSTALL#
In order to install the libraries, we can download their source code and place it under the Arduino libraries folder of our installation. This library is used under the hood by the ESPAsyncWebServer library and thus is a dependency that we need to satisfy. This tutorial was tested on a DFRobot’s ESP8266 FireBeetle board.Īs mentioned in the introduction section, we will need to install the ESPAsyncWebServer library in order to access the high level functions needed to setup the HTTP webserver.Īdditionally, we will also need to install the ESPAsyncTCP library, which is an asynchronous TCP library for the ESP8266. The library is also available for the ESP32 and you can check here an introductory tutorial for that microcontroller. In order to setup the server using a high level API, we will use this library, which takes care of all the lower level details.
#ESP8266 ARDUINO EXAMPLE CODE HOW TO#
The objective of this tutorial is to explain how to set an asynchronous HTTP web server on the ESP8266, using the Arduino core.Īs a simple example, we will setup a server route that receives HTTP GET requests and returns a random number to the client, generated by the ESP8266. The objective of this tutorial is to explain how to set an asynchronous HTTP web server on the ESP8266, using the Arduino core. This tutorial was tested on a DFRobot’s ESP8266 FireBeetle board.
