I am having an issue with mDNS when it is not a part of the standard setup() loop() constructs. I could just leave it in main, however I have other processing I am wanting to do, and leaving it in there is messy and violates the "one purpose, one file" paradigm. Plus, this is driving me crazy.
The following will compile and run with no errors:
main.h
#ifndef MAIN_H
#define MAIN_H
#include <WiFiManager.h>
#include <ESP8266mDNS.h>
void setup();
void loop();
void mdnssetup();
#endif // MAIN_H
main.cpp:
#include "main.h"
void setup() {
WiFiManager wifiManager;
mdnssetup();
}
void loop() {
MDNS.update();
yield();
}
void mdnssetup() {
MDNS.begin(WiFi.hostname());
MDNS.addService("http", "tcp", 80);
}
Whenever I pull the function to a separate file I get errors. The following configuration (where I separate the MDNS setup) generates errors:
main.h:
#ifndef MAIN_H
#define MAIN_H
#include "mdns.h"
#include <WiFiManager.h>
void setup();
void loop();
#endif // MAIN_H
main.cpp:
#include "main.h"
void setup() {
WiFiManager wifiManager;
mdnssetup();
}
void loop() {
MDNS.update();
yield();
}
mdns.h:
#ifndef MDNS_H
#define MDNS_H
#include <ESP8266mDNS.h>
void mdnssetup();
#endif // MDNS_H
mdns.cpp
#include "mdns.h"
void mdnssetup() {
MDNS.begin(WiFi.hostname());
MDNS.addService("http", "tcp", 80);
}
The following are the errors I receive in the latter setup:
In file included from src\mdns.h:4:0,
from src\main.h:4,
from src\main.cpp:1:
C:\Users\foo\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266mDNS\src/ESP8266mDNS.h:52:27: error: expected type-specifier
using MDNSResponder = esp8266::MDNSImplementation::MDNSResponder; //new
^
C:\Users\foo\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266mDNS\src/ESP8266mDNS.h:54:12: error: 'MDNSResponder' does not name a type
extern MDNSResponder MDNS;
^
src\main.cpp: In function 'void loop()':
src\main.cpp:9:5: error: 'MDNS' was not declared in this scope
MDNS.update();
^
*** [.pio\build\d1_mini\src\main.cpp.o] Error 1
In file included from src\mdns.h:4:0,
from src\mdns.cpp:1:
C:\Users\foo\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266mDNS\src/ESP8266mDNS.h:52:27: error: expected type-specifier
using MDNSResponder = esp8266::MDNSImplementation::MDNSResponder; //new
^
C:\Users\foo\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266mDNS\src/ESP8266mDNS.h:54:12: error: 'MDNSResponder' does not name a type
extern MDNSResponder MDNS;
^
src\mdns.cpp: In function 'void mdnssetup()':
src\mdns.cpp:4:5: error: 'MDNS' was not declared in this scope
MDNS.begin(WiFi.hostname());
^
*** [.pio\build\d1_mini\src\mdns.cpp.o] Error 1
Obviously, I can read the errors. I have a faint understanding of what this is telling me in general. However, applying what it's telling me is beyond my comprehension. In other words, please use small words and please don't cut and paste the errors as if that's the solution as I've seen in some of my searches.