Skip to content

Latest commit

 

History

History
56 lines (37 loc) · 1.77 KB

ex4.md

File metadata and controls

56 lines (37 loc) · 1.77 KB

Quality of Life - Static IP and mDNS

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

Static IP address

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.

mDNS

Requirements

  • ESP8266WiFi library
  • MDNS support in your operating system/client machines:
    • For Mac OSX support is built in through Bonjour already.
    • For Linux, install Avahi.
    • For Windows, install Bonjour.

Usage

#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.

Main Menu | Next