If you want to deploy your ESP inside walls or other difficult-to-access places, it's not very practical to have to plug in a cable to it every time it boots, just to see it's IP address.
To this problem, you have 2 solutions:
- Static IP address (Not recomended. Can create conflicts with other devices)
- mDNS
If you want your ESP to have a static IP address, the only thing you need to add are these lines of code before you call WiFi.begin()
:
IPAddress ip(192, 168, 1, xx); // where xx is the desired IP Address
IPAddress gateway(192, 168, 1, 1); // set gateway to match your network
IPAddress subnet(255, 255, 255, 0); // set subnet mask to match your network
WiFi.config(ip, gateway, subnet);
That should do the trick, but I recomend avoiding this, which leaves us with mDNS.
- ESP8266WiFi library
- MDNS support in your operating system/client machines:
#include <ESP8266mDNS.h>
const char* Hostname = "myVeryOwnESP8266"; // 'hostname' is a variable in a library, so we use 'Hostname' here.
...
void setup(){
...
if (MDNS.begin(Hostname)) {
Serial.println("MDNS responder started");
}
...
}
To then access your board, you just have to type myVeryOwnESP8266.local
in your browser's address bar.
If you want to learn more about this, like how to find all the ESPs on the network, look at the library documentation here.