maakbaas / esp8266-iot-framework

Framework for IoT projects implementing HTTPS requests, a React web interface, WiFi manager, live dashboard, configuration manager, file manager and OTA updates.
GNU General Public License v3.0
418 stars 113 forks source link

mDNS not working #151

Closed marcolino7 closed 2 years ago

marcolino7 commented 2 years ago

Hi, I am trying to configure and make it work mDNS responder in order to make configuration more simple. Looking at varius code around online I found this code

WiFi.hostname("bigclock");
  if (MDNS.begin("bigclock")) {             // Start the mDNS responder for esp8266.local
    MDNS.addService("http", "tcp",80);
    Serial.println("mDNS responder started");
  }

Serial message was on console so MDNS.begin executed succefully. I tried to add before or after WiFiManager.begin(configManager.data.projectName); but it does not work. Anyone get mDNS work?

Marco

maakbaas commented 2 years ago

This adapted example works for me. Maybe you forgot the MDNS update function in your loop? In any case, I have also found that finding MDNS devices can be a bit hit or miss, even when your ESP8266 is configured correctly.

#include <Arduino.h>
#include "LittleFS.h"

#include "WiFiManager.h"
#include "webServer.h"
#include "updater.h"
#include "fetch.h"
#include "configManager.h"
#include "timeSync.h"
#include "ESP8266mDNS.h"

void setup() 
{
    Serial.begin(115200);

    LittleFS.begin();
    GUI.begin();
    configManager.begin();
    WiFiManager.begin(configManager.data.projectName);
    timeSync.begin();

    MDNS.begin("esptest");
    MDNS.addService("http", "tcp", 80);

    Serial.println("Hello world");
}

void loop() 
{
    //software interrupts
    WiFiManager.loop();
    updater.loop();
    configManager.loop();

    //your code here
    MDNS.update();
}