mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-18 08:36:13 +00:00
Add comprehensive mDNS/Bonjour discovery with unified service and diagnostic tools
Features Added: • mDNS/Bonjour discovery using hashicorp/mdns library • Unified discovery service combining UPnP + mDNS + configuration • Parallel discovery execution for optimal performance • Comprehensive logging for both UPnP and mDNS discovery • Network diagnostic tools for troubleshooting New Discovery Methods: • Configuration-based (fastest, most reliable) • UPnP/SSDP discovery (widely supported, enhanced logging) • mDNS/Bonjour discovery (Apple ecosystem friendly) New Programs & Tools: • cmd/example-mdns - Standalone mDNS discovery testing • cmd/example-upnp - Isolated UPnP/SSDP discovery testing • cmd/mdns-scanner - Network diagnostic tool for mDNS services Enhanced Build System: • make dev-mdns / dev-mdns-verbose (mDNS testing) • make dev-upnp / dev-upnp-verbose (UPnP testing) • make dev-scan-all (scan all network services) • make dev-scan-soundtouch (scan for SoundTouch services) Documentation: • docs/DISCOVERY.md - Comprehensive discovery guide • Updated README.md with new features and commands • Full API documentation and troubleshooting guide Technical Improvements: • Detailed request/response logging for UPnP M-SEARCH • Step-by-step mDNS service discovery tracking • IP address resolution with IPv4/IPv6 handling • Service name parsing and device info extraction • Robust error handling and network diagnostics Backward Compatibility: • No breaking changes to existing APIs • All existing tests pass • CLI interface unchanged but enhanced • Legacy UPnP-only service still available
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/user_account/bose-soundtouch/pkg/discovery"
|
||||
)
|
||||
|
||||
func main() {
|
||||
verbose := flag.Bool("v", false, "Enable verbose logging")
|
||||
timeout := flag.Duration("timeout", 5*time.Second, "Discovery timeout")
|
||||
flag.Parse()
|
||||
|
||||
// Configure logging
|
||||
if *verbose {
|
||||
log.SetOutput(os.Stdout)
|
||||
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
|
||||
} else {
|
||||
log.SetOutput(os.Stderr)
|
||||
}
|
||||
|
||||
fmt.Println("SoundTouch mDNS Discovery Example")
|
||||
fmt.Println("================================")
|
||||
|
||||
fmt.Printf("Timeout: %v, Verbose: %v\n", *timeout, *verbose)
|
||||
fmt.Println()
|
||||
|
||||
// Create mDNS discovery service
|
||||
mdnsService := discovery.NewMDNSDiscoveryService(*timeout)
|
||||
|
||||
// Create context with timeout (add buffer time)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), *timeout+2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
fmt.Println("Searching for SoundTouch devices via mDNS...")
|
||||
fmt.Println("This will search for devices advertising _soundtouch._tcp.local. service")
|
||||
if *verbose {
|
||||
fmt.Println("Verbose logging enabled - watch for technical details...")
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
start := time.Now()
|
||||
|
||||
// Discover devices
|
||||
devices, err := mdnsService.DiscoverDevices(ctx)
|
||||
duration := time.Since(start)
|
||||
|
||||
fmt.Printf("Discovery completed in %v\n", duration)
|
||||
fmt.Println()
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("mDNS discovery completed with error: %v\n", err)
|
||||
fmt.Println("Note: This might be normal if no devices support mDNS")
|
||||
}
|
||||
|
||||
// Display results
|
||||
if len(devices) == 0 {
|
||||
fmt.Println("No SoundTouch devices found via mDNS")
|
||||
fmt.Println()
|
||||
fmt.Println("Technical Status:")
|
||||
if *verbose {
|
||||
fmt.Println("✓ mDNS query was sent (check logs above for details)")
|
||||
fmt.Println("✓ No network errors during discovery process")
|
||||
fmt.Println("✗ No devices responded with _soundtouch._tcp service")
|
||||
} else {
|
||||
fmt.Println("Run with -v flag for detailed technical information")
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Println("This could mean:")
|
||||
fmt.Println("- No SoundTouch devices on network")
|
||||
fmt.Println("- Devices don't support Bonjour/mDNS")
|
||||
fmt.Println("- Network blocks multicast traffic (common in corporate networks)")
|
||||
fmt.Println("- Devices use different service name than '_soundtouch._tcp.local.'")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Found %d SoundTouch device(s):\n", len(devices))
|
||||
fmt.Println()
|
||||
|
||||
for i, device := range devices {
|
||||
fmt.Printf("%d. %s\n", i+1, device.Name)
|
||||
fmt.Printf(" Host: %s\n", device.Host)
|
||||
fmt.Printf(" Port: %d\n", device.Port)
|
||||
fmt.Printf(" API URL: http://%s:%d/\n", device.Host, device.Port)
|
||||
fmt.Printf(" Location: %s\n", device.Location)
|
||||
fmt.Printf(" Last seen: %s\n", device.LastSeen.Format("2006-01-02 15:04:05"))
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
fmt.Println("✓ mDNS discovery completed successfully!")
|
||||
fmt.Printf("✓ Found %d device(s) in %v\n", len(devices), duration)
|
||||
}
|
||||
Reference in New Issue
Block a user