Introduction: ESP8266 Static IP (WIP)

(If your Wi-Fi network is already configured in some way, you may need to talk to your Network Administrator.)

Part of the goal of our project is to assign each ESP8266 its own static IP address to make it easier to keep track of the devices and connect to their webpages.

An IP address is an address that can be used to access and communicate with devices on a network. There are 2 forms of IP addresses, but the most common form is IPv4, which looks something like this: 192.168.1.1. The format is 4 sets of numbers from 0-255, separated by periods, BUT*** it is important to note that some specific numbers have special uses and meanings, some of which you can find information about here: https://en.wikipedia.org/wiki/IPv4#Special-use_ad...

These addresses are typically automatically assigned by a DHCP server. Most homes and high schools use their router as their DHCP server, meaning that the router will automatically assign IP addresses, using Dynamic Host Configuration Protocol (DHCP), to devices as they connect to the network.

Our goal here, however, is to use Static IP addresses, which are IP addresses that are NOT automatically assigned by a DHCP server. The reason for this is that your router isn't set up to give any certain device the same IP address, so it'll use some random address that happens to be available at the time. While this is perfectly fine for most network use, this can be a hassle to deal with when you're doing something like we're doing here and you need to connect to a locally-hosted webpage using the device's IP.

Step 1: Getting Into Your Router's Control Panel

If your router does have some kind of configurations in place, this is the part where you will need to talk to your Network Administrator (whoever set up the configurations, such as a parent/guardian, teacher, tech/IT department, etc.).

In order to get available static IP addresses, you'll either need to find an available range in your current configuration or set up a range yourself. To do this, you'll need to go into the control panel of your router. The way you do this will vary depending on what router you have, but you should be able to look up "how to access {your router name or brand} control panel" and find a tutorial.

Once you're into your router's control panel, find its DHCP settings (which may be under a broader category called "Local Network" or something similar).

Step 2: Reserving Static Range in DHCP

If your router DOES have any special DHCP configurations or reservations set up, then:

  • Either find a range of IP addresses that aren't currently being used in the already reserved range and make a note of these
  • OR make the current range bigger (you can find how to do this in the steps below)

If your router does NOT have any special DHCP configurations or reservations set up, then follow these steps:

  1. Your router is told to assign IP addresses in a certain range, like from 192.168.1.1 to 192.168.1.255, so we want to restrict this range so that we have a range of available addresses that aren't automatically assigned.
  2. Set the range to start higher by changing the number in the last set of numbers. For example, change 192.168.1.1 to 192.168.1.25. This means that your router will no longer automatically assign IP addresses in the range from 192.168.1.1 to 192.168.1.25

We can now manually assign these addresses!

Step 3: Assigning a Static IP to an ESP8266

There are 2 main ways of actually assigning a static IP to an ESP8266: through the router or through the ESP8266.

Requesting a specific address from the router through code on the ESP8266 (my personal preference):

This is a good guide: https://circuits4you.com/2018/03/09/esp8266-static... but the basics are:

  • Put the following include statements at the very top of your code:
#include <ESP8266.WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
  • Then call these methods, where x is the static IP (separate the 4 sets of numbers with commas instead of periods) and y is the IP address of your router (which is also called a gateway):
IPAddress staticIP(x); //static IP address
IPAddress gateway(y); //Router's IP address
IPAddress subnet(255, 255, 255, 0);
IPAddress dns(8, 8, 8, 8);

Using the ESP8266's Media Access Control (MAC) address in the router's settings: