Browse Source

mdns: clean-up

mcspr-patch-1
Maxim Prokhorov 3 years ago
parent
commit
e50b6fe79a
10 changed files with 38 additions and 109 deletions
  1. +1
    -4
      code/espurna/board.cpp
  2. +2
    -3
      code/espurna/config/arduino.h
  3. +0
    -10
      code/espurna/config/dependencies.h
  4. +1
    -5
      code/espurna/config/general.h
  5. +0
    -3
      code/espurna/main.cpp
  6. +33
    -73
      code/espurna/mdns.cpp
  7. +0
    -4
      code/espurna/mqtt.cpp
  8. +1
    -5
      code/espurna/nofuss.cpp
  9. +0
    -1
      code/platformio.ini
  10. +0
    -1
      code/test/build/nondefault.h

+ 1
- 4
code/espurna/board.cpp View File

@ -62,11 +62,8 @@ PROGMEM const char espurna_modules[] =
#if LLMNR_SUPPORT
"LLMNR "
#endif
#if MDNS_CLIENT_SUPPORT
"MDNS_CLIENT "
#endif
#if MDNS_SERVER_SUPPORT
"MDNS_SERVER "
"MDNS"
#endif
#if MQTT_SUPPORT
"MQTT "


+ 2
- 3
code/espurna/config/arduino.h View File

@ -204,11 +204,10 @@
//#define INFLUXDB_SUPPORT 1
//#define IR_SUPPORT 1
//#define LED_SUPPORT 0
//#define LLMNR_SUPPORT 1 // Only with latest Arduino Core
//#define MDNS_CLIENT_SUPPORT 1
//#define LLMNR_SUPPORT 1
//#define MDNS_SERVER_SUPPORT 0
//#define MQTT_SUPPORT 0
//#define NETBIOS_SUPPORT 1 // Only with latest Arduino Core
//#define NETBIOS_SUPPORT 1
//#define NOFUSS_SUPPORT 1
//#define NTP_SUPPORT 0
//#define OTA_ARDUINOOTA_SUPPORT 1


+ 0
- 10
code/espurna/config/dependencies.h View File

@ -92,16 +92,6 @@
#define RELAY_SUPPORT 1 // Scheduler needs relays
#endif
#if LWIP_VERSION_MAJOR != 1
#undef MDNS_CLIENT_SUPPORT
#define MDNS_CLIENT_SUPPORT 0 // default resolver already handles this
#endif
#if not defined(ARDUINO_ESP8266_RELEASE_2_3_0)
#undef TELNET_SERVER_ASYNC_BUFFERED
#define TELNET_SERVER_ASYNC_BUFFERED 1 // enable buffered telnet by default on latest Cores
#endif
#if TUYA_SUPPORT
#undef LIGHT_TRANSITION_TIME
#define LIGHT_TRANSITION_TIME 1600 // longer transition than the default


+ 1
- 5
code/espurna/config/general.h View File

@ -172,7 +172,7 @@
#endif
#ifndef TELNET_SERVER_ASYNC_BUFFERED
#define TELNET_SERVER_ASYNC_BUFFERED 0 // Enable buffered output for telnet server (+1Kb)
#define TELNET_SERVER_ASYNC_BUFFERED 1 // Enable buffered output for telnet server (+1Kb)
// Helps to avoid lost data with lwip2 TCP_MSS=536 option
#endif
@ -842,10 +842,6 @@
#define MDNS_SERVER_SUPPORT 1 // Publish services using mDNS by default (1.48Kb)
#endif
#ifndef MDNS_CLIENT_SUPPORT
#define MDNS_CLIENT_SUPPORT 0 // Resolve mDNS names (3.44Kb)
#endif
#ifndef LLMNR_SUPPORT
#define LLMNR_SUPPORT 0 // Publish device using LLMNR protocol by default (1.95Kb) - requires Core version >= 2.4.0
#endif


+ 0
- 3
code/espurna/main.cpp View File

@ -201,9 +201,6 @@ void setup() {
#if MDNS_SERVER_SUPPORT
mdnsServerSetup();
#endif
#if MDNS_CLIENT_SUPPORT
mdnsClientSetup();
#endif
#if LLMNR_SUPPORT
llmnrSetup();
#endif


+ 33
- 73
code/espurna/mdns.cpp View File

@ -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

+ 0
- 4
code/espurna/mqtt.cpp View File

@ -1021,10 +1021,6 @@ void _mqttConnect() {
_mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MAX;
}
#if MDNS_CLIENT_SUPPORT
_mqtt_server = mdnsResolve(_mqtt_server);
#endif
DEBUG_MSG_P(PSTR("[MQTT] Connecting to broker at %s:%hu\n"), _mqtt_server.c_str(), _mqtt_port);
DEBUG_MSG_P(PSTR("[MQTT] Client ID: %s\n"), _mqtt_clientid.c_str());


+ 1
- 5
code/espurna/nofuss.cpp View File

@ -45,11 +45,7 @@ void _nofussWebSocketOnConnected(JsonObject& root) {
void _nofussConfigure() {
String nofussServer = getSetting("nofussServer", NOFUSS_SERVER);
#if MDNS_CLIENT_SUPPORT
nofussServer = mdnsResolve(nofussServer);
#endif
if (nofussServer.length() == 0) {
if (!nofussServer.length()) {
setSetting("nofussEnabled", 0);
_nofussEnabled = false;
} else {


+ 0
- 1
code/platformio.ini View File

@ -141,7 +141,6 @@ lib_deps =
https://github.com/xoseperez/hlw8012.git#1.1.0
IRremoteESP8266@2.7.4
https://github.com/mcspr/justwifi.git#2cb9e769
https://github.com/madpilot/mDNSResolver#4cfcda1
https://github.com/xoseperez/my92xx#3.0.1
https://github.com/256dpi/arduino-mqtt#196556b6
https://bitbucket.org/xoseperez/nofuss.git#0.3.0


+ 0
- 1
code/test/build/nondefault.h View File

@ -2,7 +2,6 @@
#define INFLUXDB_SUPPORT 1
#define KINGART_CURTAIN_SUPPORT 1
#define LLMNR_SUPPORT 1
#define MDNS_CLIENT_SUPPORT 1
#define NETBIOS_SUPPORT 1
#define NOFUSS_SUPPORT 1
#define OTA_MQTT_SUPPORT 1


Loading…
Cancel
Save