-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add mDNS support for MQTT server #4769
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
Conversation
- fixes #4671 - reduce some topic string parsing - moves LWT into onConnect
""" WalkthroughThe update refactors MQTT topic string construction in Changes
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes found. Possibly related PRs
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
So far, I had no luck with this PR. I installed There is no such problem if I use a regular DNS name or IP address. And a variety of ESPHome devices can connect using the mDNS name without problem as well. |
You don't need to add |
How do you mean? That's what my mDNS domain is called, and broadcasted via avahi-publish. |
.local is needed for your host computer to know it needs to do mDNS. querying mDNS directly does not need it. |
Yes exactly. How does WLED know I want to resolve an mDNS address if I don't add the correct |
Just enter the hostname. What else? Similar as, if you are old enough to remember it, WINS. |
Again, how will it know it's an mDNS domain if I strip the |
See the code. |
I see changes to MQTT topic parsing which seem irrelevant to this PR. However I'm a Java dev with limited understanding of CPP code so I can't say for sure. Can you describe in words? Typically, in these kind of hostname fields there are these cases:
|
wled00/mqtt.cpp
Outdated
mqttMDNS.replace(F(".local"), ""); // remove .local if present | ||
if (strlen(cmDNS) > 0 && mqttMDNS.length() > 0 && mqttMDNS.indexOf('.') < 0) { // if mDNS is enabled and server does not have domain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is .replace()
limited to the end of strings? Otherwise it would strip in the middle of DNS names too which is probably not wanted.
In general, I'd recommend explicitly checking for .local
at the end, and only if present resolve via mDNS (stripping the domain if it isn't done by the mDNS component anyway). It seems the above code just checks for the presence of dots, which is imho not correct. Plain hostnames (without dots) are typically expected to be resolved via DNS (using the search domain).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the impl from this PR would fail for those who use dots in their mDNS name. Yes, some people do this and I understand this is bending the mDNS spec a bit, but it would be nice to support these cases anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more comment about .replace()
: is it case-insensitive? Both DNS and mDNS names/domains are case-insensitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are welcome to add on to this at a later time. For now just test if it fulfills your needs with .local domain.
You have to understand that I'm doing that in my spare time and I have no need for this feature and limited resources in ESP may need a few compromises.
FYI resolving mDNS host only requires hostname, no domain. Domain is only there to determine if regular DNS is needed or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, and thanks for your time investment. I was just reviewing this PR as you asked me to do.
I retested the 24f2306 binary and |
However,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure "removing anything behind .local" is the correct fix?
A user could have a perfectly conformant DNS name "server1.localservers.example.com" and this code would strip it to just "server1" and interpret it as an mDNS name.
I think a more correct fix would make sure the .local
part needs to appear at the end of the string to be considered as a mDNS name.
Agreed, but that is a bit more complex. However, that stripping is only done for mDNS resolution. If host is not found, regular DNS query is made. See |
Summary by CodeRabbit
New Features
Improvements
Documentation