ESP8266 Static IP Address arduino Example

In this tutorial we will learn how to use static IP address for ESP8266 NodeMCU. We make LED on off control with simple web server with static IP to our ESP.

Step 1: Required Header files

There is no need of any special header file for having static IP address.

Step 2: WiFi IP configuration variables

IPAddress variable is used in arduino IDE to define IP address. Note it uses comma separated four byte. and NO equal to sign.

Define Device IP address, Gateway (i.e. wifi router ip), subnet mask and dns

You can get this information from your laptops wifi connection details.

Step 3: Connecting to WiFi Router with Above Configuration

Static ip configuration can be applied to ESP using WiFi.config statement.

WiFi.config(staticIP, subnet, gateway, DNS)

Use this command before WiFi begin. WiFi.hostname is optional, it is used to give name to ESP to identify in WiFi router.

Note That: Sequence of WiFi.config is important, first IPaddress, then subnet then gateway and last is DNS

Complete Code of ESP8266 using Static IP address

This code makes a NodeMCU as webserver and controls onboard LED using web interface.

Change the IP settings, SSID and Password as per your WiFi router and upload.

Upload this code and observer serial monitor.

Read more how to get MAC address and List of WiFi Hotspots

Leave a Reply