diff --git a/cmd/root.go b/cmd/root.go index d6646ca6e..af9cd864c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -2,10 +2,12 @@ package cmd import ( "fmt" + "net" "net/http" _ "net/http/pprof" // pprof handler "os" "os/signal" + "strconv" "sync" "syscall" "time" @@ -16,6 +18,7 @@ import ( "github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util/pipe" "github.com/evcc-io/evcc/util/sponsor" + "github.com/grandcat/zeroconf" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/spf13/cobra" @@ -190,6 +193,17 @@ func run(cmd *cobra.Command, args []string) { socketHub := server.NewSocketHub() httpd := server.NewHTTPd(uri, site, socketHub, cache) + // announce webserver on mDNS + if _, port, err := net.SplitHostPort(uri); err == nil { + if portInt, err := strconv.Atoi(port); err == nil { + if zc, err := zeroconf.RegisterProxy("evcc Website", "_http._tcp", "local.", portInt, "evcc", nil, []string{}, nil); err == nil { + shutdown.Register(zc.Shutdown) + } else { + log.ERROR.Printf("mDNS announcement: %s", err) + } + } + } + // metrics if viper.GetBool("metrics") { httpd.Router().Handle("/metrics", promhttp.Handler())