|
|
@ -33,7 +33,7 @@ void _mdnsFindMQTT() { |
|
|
|
#endif
|
|
|
|
|
|
|
|
void _mdnsServerStart() { |
|
|
|
if (MDNS.begin((char *) getSetting("hostname").c_str())) { |
|
|
|
if (MDNS.begin(getSetting("hostname", getIdentifier()))) { |
|
|
|
DEBUG_MSG_P(PSTR("[MDNS] OK\n")); |
|
|
|
} else { |
|
|
|
DEBUG_MSG_P(PSTR("[MDNS] FAIL\n")); |
|
|
@ -43,96 +43,56 @@ void _mdnsServerStart() { |
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void mdnsServerSetup() { |
|
|
|
bool done { false }; |
|
|
|
|
|
|
|
#if WEB_SUPPORT
|
|
|
|
#if WEB_SUPPORT
|
|
|
|
{ |
|
|
|
MDNS.addService("http", "tcp", getSetting("webPort", static_cast<uint16_t>(WEB_PORT))); |
|
|
|
#endif
|
|
|
|
done = true; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if TELNET_SUPPORT
|
|
|
|
MDNS.addService("telnet", "tcp", TELNET_PORT); |
|
|
|
#endif
|
|
|
|
|
|
|
|
// Public ESPurna related txt for OTA discovery
|
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "app_name", APP_NAME); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "app_version", getVersion()); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "build_date", buildTime()); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "mac", WiFi.macAddress()); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "target_board", getBoardName()); |
|
|
|
#if TELNET_SUPPORT
|
|
|
|
{ |
|
|
|
char buffer[6] = {0}; |
|
|
|
itoa(ESP.getFlashChipRealSize() / 1024, buffer, 10); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "mem_size", (const char *) buffer); |
|
|
|
MDNS.addService("telnet", "tcp", TELNET_PORT); |
|
|
|
done = true; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if OTA_ARDUINOOTA_SUPPORT
|
|
|
|
{ |
|
|
|
char buffer[6] = {0}; |
|
|
|
itoa(ESP.getFlashChipSize() / 1024, buffer, 10); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "sdk_size", (const char *) buffer); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "app_name", APP_NAME); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "app_version", getVersion()); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "build_date", buildTime()); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "mac", WiFi.macAddress()); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "target_board", getBoardName()); |
|
|
|
|
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "mem_size", |
|
|
|
String(static_cast<int>(ESP.getFlashChipRealSize() / 1024), 10)); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "sdk_size", |
|
|
|
String(static_cast<int>(ESP.getFlashChipSize() / 1024), 10)); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "free_space", |
|
|
|
String(static_cast<int>(ESP.getFreeSketchSpace() / 1024), 10)); |
|
|
|
done = true; |
|
|
|
} |
|
|
|
{ |
|
|
|
char buffer[6] = {0}; |
|
|
|
itoa(ESP.getFreeSketchSpace(), buffer, 10); |
|
|
|
MDNS.addServiceTxt("arduino", "tcp", "free_space", (const char *) buffer); |
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!done) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
wifiRegister([](justwifi_messages_t code, char * parameter) { |
|
|
|
|
|
|
|
if (code == MESSAGE_CONNECTED) { |
|
|
|
_mdnsServerStart(); |
|
|
|
#if MQTT_SUPPORT
|
|
|
|
_mdnsFindMQTT(); |
|
|
|
#endif // MQTT_SUPPORT
|
|
|
|
#if MQTT_SUPPORT
|
|
|
|
_mdnsFindMQTT(); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
if (code == MESSAGE_ACCESSPOINT_CREATED) { |
|
|
|
_mdnsServerStart(); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif // MDNS_SERVER_SUPPORT
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// mDNS Client
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#if MDNS_CLIENT_SUPPORT
|
|
|
|
|
|
|
|
#include <WiFiUdp.h>
|
|
|
|
#include <mDNSResolver.h>
|
|
|
|
|
|
|
|
using namespace mDNSResolver; |
|
|
|
WiFiUDP _mdns_udp; |
|
|
|
Resolver _mdns_resolver(_mdns_udp); |
|
|
|
|
|
|
|
String mdnsResolve(char * name) { |
|
|
|
|
|
|
|
if (strlen(name) == 0) return String(); |
|
|
|
if (WiFi.status() != WL_CONNECTED) return String(); |
|
|
|
|
|
|
|
_mdns_resolver.setLocalIP(WiFi.localIP()); |
|
|
|
IPAddress ip = _mdns_resolver.search(name); |
|
|
|
|
|
|
|
if (ip == INADDR_NONE) return String(name); |
|
|
|
DEBUG_MSG_P(PSTR("[MDNS] '%s' resolved to '%s'\n"), name, ip.toString().c_str()); |
|
|
|
return ip.toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String mdnsResolve(String name) { |
|
|
|
return mdnsResolve((char *) name.c_str()); |
|
|
|
} |
|
|
|
|
|
|
|
void mdnsClientSetup() { |
|
|
|
|
|
|
|
// Register loop
|
|
|
|
espurnaRegisterLoop(mdnsClientLoop); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void mdnsClientLoop() { |
|
|
|
_mdns_resolver.loop(); |
|
|
|
} |
|
|
|
|
|
|
|
#endif // MDNS_CLIENT_SUPPORT
|