ESPmDNS: An ESP32 secret (to me anyway)


ESPmDNS enables (Zeroconf/ Bonjour/) Multicast DNS on your ESP32 (and maybe ESP8266? don’t know) microcontroller.

Previously I’d been assigning a static address to ESP32 devices via my router. This is a pain: you forget what you assigned where-and-when etc.

With a few lines of code, you can access the microcontroller on a local network via http://<unique device name>.local regardless of what IP address is assigned on your local network.

ESPmDNS is an espressif library: here

Add the bit in bold below (and add lib to project in whatever IDE you are using). Bits either side are pretty much boilerplate code.

#include <Arduino.h>
#include "esp_camera.h"
#include <WiFi.h>
#include <ESPmDNS.h>

void setup() {

  (...)

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");


  if (!MDNS.begin("Replace with unique_device_name")) {
      Serial.println("Error setting up MDNS responder!");
      while(1){
          delay(1000);
      }
  }

  startServer();

  (...)

}

That’s it.

Series Navigation

<< ESP32 meet Science Journal. Science Journal, meet ESP32