-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Second mdns instance cannot be started #7213
Comments
@BbIKTOP Thanks for the hint ! |
@d-a-v yes, sure, I changed this single line and now i have 2 instances running. Also i connected 2 computers, one to the esp ap and another one to the same wifi that esp sta connected to, and observe esp mdns via dns-sd and tcpdump on both computers |
Hi @BbIKTOP there is a little side effect, probably only for me :) . I use a 2nd interface (an extra WiFI adapter) to get all OTA ports populated to Arduino IDE Win10. The LAN (current iface) has troubles (because I use WoL, I guess) so now the ESPs cannot find their way. Just FYI. |
@lorol Sorry, could you explain further? I can't see how is it related - I mean, what is the influence to the OTA, when mDNS listens on it's interface only? And what exact troubles do you have? |
@BbIKTOP it is my particular problem of having 2x network adapters (2x IPs) on same subnet - on the PC I run ArduinoIDE from. I guess, your implementation is fully correct it just doesn't work for me and I will hold on it. My problem is in PC setup somewhere that makes original LAN adapter inconsistently "seeing" the ESPs on my network. I just plugged an extra WiFi USB stick (no time to fix why the LAN adapter have issues) and all was OK until this change. You can disregard it, no problem. Hope no one else will have weird needs :) Just from curiosity, why the original code several years was exposing IP4_ADDR_ANY - any reason (other than your testing convenience) to be not limited to &m_netif->ip_addr? |
Didn’t get it but ok. I suppose, nobody tried to use it on both interfaces simultaneously, i mean on sta and ap. I. e. nobody tried to run 2 instances yet. Have no another versions |
Sorry, Dave, bad people want me to do my job. Again. I noticed that and definitely return to it this week. Will let you know, surely. Thank you! |
Sorry for delay, still have a lot to do ( |
Let me explain it a bit further (just in case) |
By default this PR does not change anything. First one is to test v2 with Legacy-compatibility:
Second one is the new API. That may or may not compile with your application.
|
Please help me understand - do I need to uncomment that? What shall I change in order to test? I have not defined either NO_GLOBAL_INSTANCES nor NO_GLOBAL_MDNS. I wrongly supposed there's some #define that switch new functionality on and off |
By default LEA is uncommented. |
Tried leav2compat - it is working as supposed, thank you! Tried leav2 - cannot get it working since there’s no ::registerService(char*,char*,unsigned short), just ::registerService(char*,char*,char*,unsigned short) |
@BbIKTOP LEAv2Compat is using LEAv2 and has the same API as LEAv1.
Thanks for the report ! |
I am so lost... so it used to be one instance that works on all interfaces. Then it was restricted, and need to have one instance for each interface. Now the plan is to bring back one instance for all interfaces? In my opinion it should be one instance for all interfaces. It should work smoothly at least for AP_STA. Not sure how it would work for multiple IP interfaces on STA mode. But that seems to be the rare case. |
Actually, single instance never worked. I asked for assistance and I’ve been told to use 2 instances. It sounded strange to use different instances on different ifaces, i never heard about such an implementation, also it’s even more strange to have 2 instances on such a resources poor device, but ok, who am i to object. |
Like @BbIKTOP is telling, a single instance was not properly working under all circumstances with both interface at the same time. There have been several attempts to fix this and the original author @LaborEtArs ended up with providing an updated version in #7281 (not enabled by default) that works with an instance per interface (at least confirmed to be working by @BbIKTOP and me). We may merge it for the soon-to-be-released version 2.7.2 of this core. I am currently working on stripping this new version to make it working with a single instance for all interfaces (even ethernet interfaces) but it will not be ready for 2.7.2. |
The updated MDNS code is still showing issues and requires more work. Per internal discussions, pushing back to v3. |
In git version, a single mDNS instance will now work on all interfaces. Can you try it ? |
Sorry, was a bit busy working. Please remind me, is it enough to add lib_deps=https://github.com/esp8266/Arduino in pio to test? |
Tried it, and looks like it's working. Have esp8266 12e on my custom board, running in Didn't I forget to test anything? |
I believe than you need to use the "stage" configuration in PIO (if that points to the current git master branch). |
Simply added |
If you are able to see the advertisement from both networks, then I think this is fine ! Edit: You'll close this issue when you are conviced it is now OK :) |
Using this code, and ESP hostname 'box': #include <Arduino.h>
#include <ESP8266mDNS.h>
#include <ESP8266WiFi.h>
#define dPrintf(...) \
{ \
Serial.printf(__VA_ARGS__); \
delay(500); \
}
extern char *wifiNet;
extern char *wifiPassword;
char *apName = (char *)"box";
char *apPassword = (char *)"box-12345";
char *apIp = (char *)"10.1.1.1";
char *apMask = (char *)"255.255.255.0";
// MDNSResponder mdnsInt, mdnsExt;
void setup()
{
int res;
Serial.begin(115200);
delay(1000);
Serial.println("\nStarting mDNS test");
WiFi.persistent(false);
WiFi.disconnect();
WiFi.mode(WIFI_AP_STA);
IPAddress localIp;
IPAddress localMask;
IPAddress localGw;
localIp.fromString(apIp);
localMask.fromString(apMask);
localGw.fromString(apIp);
res = WiFi.softAP(apName, apPassword); //, 2, false, 20);
Serial.printf("After softAP: [%s] res=%d, [%s]\n", apName, res, WiFi.localIP().toString().c_str());
res = WiFi.softAPConfig(localIp, localGw, localMask);
Serial.printf("After softAPConfig: %d\n", res);
Serial.printf("After softAP IP: %s\n", WiFi.softAPIP().toString().c_str());
WiFi.hostname(apName);
WiFi.setAutoReconnect(true);
WiFi.begin();
Serial.printf("Local ip is %s\n", WiFi.softAPIP().toString().c_str());
if (!MDNS.begin(apName))
{
Serial.printf("Cannot start internal mDNS responder\n");
}
else
{
Serial.printf("Internal mDNS responder started\n");
}
MDNS.addService("http", "tcp", 80);
//MDNS.addService(0, "http", "tcp", 80);
Serial.println("Started");
}
#define WAIT_COUNT 20
void loop()
{
static int counter = 0;
static int counter2 = 0;
static int lastStatus = WiFi.status();
dPrintf("Updating MDNS\n");
MDNS.update();
Serial.printf("Wifi status=%d, previous status=%d, ip=%s, local ip=%s\n",
(int)WiFi.status(), lastStatus,
WiFi.localIP().toString().c_str(),
WiFi.softAPIP().toString().c_str());
if (counter++ > WAIT_COUNT)
{
if (WiFi.status() == WL_IDLE_STATUS)
{
Serial.println("Reconnecting...");
WiFi.begin(wifiNet, wifiPassword);
// MDNS.end();
// MDNS.begin(apName);
//WiFi.reconnect();
}
if (WiFi.status() == WL_CONNECTED && lastStatus != WL_CONNECTED)
{
Serial.printf("!!!!!!!!!! Connected, IP is: %s\n", WiFi.localIP().toString().c_str());
counter = 0;
//MDNS.end();
//MDNS.begin(apName);
}
lastStatus = WiFi.status();
}
if (lastStatus == WL_CONNECTED && WiFi.status() != WL_CONNECTED)
{
lastStatus = WiFi.status();
// MDNS.end();
// MDNS.begin(apName);
}
if (counter2++ > WAIT_COUNT)
{
dPrintf("Querying services for int\n");
// int scInt = MDNS.queryService("http", "tcp");
//MDNS.notifyAPChange();
}
delay(1000);
} I observe:
|
Please confirm I didn't miss anything, before I close it. Thank you so much! |
I think nothing is missed ! |
Well, I'm closing the issue then. Thank you! |
Just to summarize, the correct setup right now is to call MDNS.begin() only once? re. commented out blocks in the example above. I have only tested this briefly, but can also confirm that everything works as expected. OT, on the same commented out blocks. Needs a new issue I suppose |
These commented out blocks left from the previous testing, but I didn't try ::begin() ::end() in loop() yet |
Second mdns instance cannot be created becuase listening sockel listen on inaddr_any (0)
To be able to create second instance you'd probably need to replace
lib/ESP8266mDNS/src/LEAmDNS_Helpers.cpp
if (m_pUDPContext->listen(IP4_ADDR_ANY, DNS_MQUERY_PORT))
to something like
if (m_pUDPContext->listen(ip_2_ip4(&m_netif->ip_addr), DNS_MQUERY_PORT))
To prevent err -8 ERR_USE on second instance
The text was updated successfully, but these errors were encountered: