This commit is contained in:
Josh Deprez 2021-02-07 17:53:56 +11:00
parent fbfda3b144
commit 222d71a8e0

11
main.go
View file

@ -138,14 +138,19 @@ func main() {
flag.Parse() flag.Parse()
// Is the inverter reachable? // Is the inverter reachable?
var sgc *sungrowConn
for _, addr := range strings.Split(*inverterAddrs, ",") { for _, addr := range strings.Split(*inverterAddrs, ",") {
sgc, err := dialSungrow(addr) conn, err := dialSungrow(addr)
if err != nil { if err != nil {
log.Fatalf("Couldn't dial inverter: %v", err) log.Printf("Couldn't dial inverter: %v", err)
} }
defer sgc.Close() sgc = conn
defer conn.Close()
break break
} }
if sgc == nil {
log.Fatal("Couldn't dial any addresses, aborting")
}
// HTTP setup // HTTP setup
http.Handle("/metrics", promhttp.Handler()) http.Handle("/metrics", promhttp.Handler())