-
Notifications
You must be signed in to change notification settings - Fork 284
feat: Add mDNS support for network discovery and dynamic hostname updates #1240
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
base: master
Are you sure you want to change the base?
Conversation
51711c6 to
39e3cef
Compare
|
One other thing to consider if the swarm screen is working with mDNS hostnames. |
8f47af4 to
48d33e0
Compare
|
Regarding http_server.c and CORS : I believe I restored the original checks, while adding a block that also allows requests with Origin set to the mDNS host. |
|
This was also part of #1133, but it's good it's a separate API. Code looks good but haven't tested it yet, I'll give it a spin tomorrow. |
Preliminary work shows it does not. Other bitaxes with no support for mDNS hostnames reject the requests to /api/system/info as they violate CORS when sent from a swarm page that runs on a domain such as http://bitaxe.local. So far the best idea that might work could be to proxy the requests thru the backend of the current device, but I have concerns of an automatic scan for hundreds of hosts thru the backend. |
No, swarm should stay front-end. So is this correct?
If this is the case, then I guess it's fine for now? Does mean that NerdAxes need this at some point as well. Unfortunately I only have a single device at the moment, so I can't test this. |
I'll try again implementing it on the swarm page, maybe my first attempt was incorrect. The swarm page accessible at http://bitaxe.local/#/swarm would try to connect to for example http://192.168.1.10/api/system/info, but because the Origin header is http://bitaxe.local/, the device at 192.168.1.10 replied with a 401 (because it runs a firmware without mDNS support, so it did not understand the bitaxe.local Origin header). If you think that shouldn't be an issue, then I'll try again to implement it and give feedback if I succeed. |
Got the same issue after starting from scratch. Basically, if the other bitaxe(s) on the LAN don't have the mDNS patch, they cannot be accessed because of the URL on the bitaxe you are viewing the swarm page on. The Specific Issue
Why It Happens
The Root CauseThe ESP device firmware doesn't include the required CORS response headers:
This is a server-side issue where the older ESP device is not able to allow cross-origin requests from your web interface So basically : using the mDNS feature and accessing the swarm page via the nice URL breaks the swarm page as it cannot connect to "older" bitaxes. That might be a problem until those devices receive a firmware upgrade. Maybe you know a better way ? |
|
Thanks for the extensive write-up. I think it's fine, we can't expect older devices to magically do-the-right-thing ™️ . For single users, this is a nice improvement as there's a lot of people who run into issues if their local setup already works for hostnames, but none of the calls (f.e. firmware updates) work. For swarm users, they can start using it whenever they have upgraded their devices. |
|
One addition (don't know if that's not already the case): if a mDNS device scans and find a Bitaxe device which also has mDNS, to query it on it's hostname instead of IP. Basically, at some point, we could get rid of the ip column in swarm, or migrate them to a single column. |
21f78e5 to
a90beaa
Compare
|
Swarm Enhancement: Support for IPs and mDNS Hostnames Frontend Changes (Angular): Renamed all "IP" references to "address" for better clarity and flexibility. Backend Changes : Added the device's current IP address to the /api/system/info JSON response to enable subnet scanning when accessing via hostname. Required to be able to scan the LAN as the browser does not seem to be able to resolve the IP of the current page when accessing it over a .local domain Key Benefits: Users can now add swarm peers using either IP (e.g., 192.168.1.100) or hostname (e.g., bitaxe.local). The build passes successfully, and all changes maintain existing functionality while expanding support. Ready for review and testing! |
|
NB I wrote "backwards compatible" but in fact it's not really correct - older firmware block calling their API from a mDNS domain because of CORS |
a90beaa to
6ffc023
Compare
6ffc023 to
e814a08
Compare
…ve device discovery
e814a08 to
e5999d4
Compare
components/connect/connect.c
Outdated
| } | ||
|
|
||
| /* Set mDNS instance name */ | ||
| err = mdns_instance_name_set("ESP-Miner Web Server"); |
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 this instance name exposed somewhere, or is it internal only? If exposed, maybe we can give it a bit nicer name. Maybe device model, f.e. Bitaxe Gamma from DeviceConfig?
|
Changing settings while accessing it on hostname works, but it gave a log line: I didn't access with I'll flash back to master, to see if it's something on my network. I'll test further this evening. Addition: reflashed master and device boots again. Not sure what was happening here. Will continue. |
|
Thanks for the feedback. Yeah I also was hesitating about the "potential peer" warnings. It's an issue with CORS and XHR, on my LAN I have a bunch of devices that can be reached (TVs, routers, etc), but the swarm page cannot really get accurate HTTP status (like a 404 for most devices, or 401 for older bitaxes). Initially I wanted to warn the user they should update the firmware on the other bitaxe(s) but it would make sense they upgrade all of the devices more or less at the same time anyways. I think I can silently skip unresponsive devices without warning. Agree with you about the mDNS instance name, using the device model is a good idea, will implement. I will also try to play around with editing the hostname, to see if I can get the same crash as you did. Could it be the length of the hostname, or the "-" ? |
|
Note on the crash: I had |
Based on the backtrace of the crash, it seems to be related to the screen animation, not the network. But please don't take my word for it, I am not super familiar with any of the code to be honest, and that part is definitely above my head :) |
One possibility : the mDNS feature somehow freezes the CPU long enough for the display code to fail. Maybe I should make sure the mDNS code runs a bit later after boot and/or asynchronously |
Trying this : moving the mDNS configuration to a later stage in the boot process |
|
Added a new commit :
|
|
Commit added to the swarm page so it fails silently for irrelevant/old devices during automatic scans |


Pull Request: Add mDNS Support for Network Discovery and Dynamic Hostname Updates
Summary
This PR implements comprehensive mDNS (Multicast DNS) support for the ESP-Miner device, enabling seamless network discovery and dynamic hostname management. The implementation allows devices to be discovered automatically on local networks using Bonjour/Avahi-compatible services.
Key Features Added
🔍 Network Discovery
🌐 Dynamic Hostname Management
🛡️ Enhanced Security & Usability
Technical Implementation
Files Modified:
components/connect/CMakeLists.txt- Added mDNS component dependencycomponents/connect/connect.c- Core mDNS initialization and managementcomponents/connect/include/connect.h- Public API for hostname updatesmain/http_server/http_server.c- Dynamic hostname updates and CORS improvementsmain/idf_component.yml- Added espressif/mdns dependencyKey Functions Added:
mdns_init()- Initializes mDNS servicemdns_hostname_set()- Sets device hostname for discoverymdns_service_add()- Registers HTTP serviceupdate_mdns_hostname()- Dynamic hostname updatesnormalize_hostname()- Prevents hostname conflictsUsage Examples
Network Discovery:
Web Interface Updates:
Benefits
✅ Improved User Experience: No need to remember IP addresses
✅ Network-Friendly: Works with existing Bonjour/Avahi infrastructure
✅ Dynamic Configuration: Hostname changes take effect immediately
✅ Backward Compatible: Existing functionality remains unchanged
✅ Robust Error Handling: Graceful degradation on mDNS failures
Testing Considerations
.localhostnameDependencies Added
espressif/mdns: ^1.8.0- Official ESP-IDF mDNS componentThis implementation provides a solid foundation for network discovery and makes the ESP-Miner much more user-friendly in home and enterprise networks.