Skip to content

Commit

Permalink
Provide easier access to evcc web interface (evcc-io#2492)
Browse files Browse the repository at this point in the history
- Use mdns to provide access to the evcc website via `http://evcc.local:7070`
- Correctly shutdown the mdns announcement on exit
- Unknown: We need to check how this works in a docker environment, as that may provide unreachable IP addresses
  • Loading branch information
DerAndereAndi authored Feb 7, 2022
1 parent f4e4792 commit 5cac3af
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package cmd

import (
"fmt"
"net"
"net/http"
_ "net/http/pprof" // pprof handler
"os"
"os/signal"
"strconv"
"sync"
"syscall"
"time"
Expand All @@ -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"
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 5cac3af

Please sign in to comment.