Add status command
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rob Watson 2022-07-17 11:05:41 +02:00
parent 65d89406dc
commit dd8ec50a07
2 changed files with 46 additions and 1 deletions

View File

@ -35,7 +35,7 @@ func main() {
flag.DurationVar(&pollInterval, "pollInterval", time.Minute, "Poll interval, example: 60s") flag.DurationVar(&pollInterval, "pollInterval", time.Minute, "Poll interval, example: 60s")
flag.Parse() flag.Parse()
if gatewayEndpoint == "" { if gatewayEndpoint == "" || inverterAddr == "" {
flag.Usage() flag.Usage()
os.Exit(1) os.Exit(1)
} }

45
cmd/status/main.go Normal file
View File

@ -0,0 +1,45 @@
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"log"
"net"
"os"
"git.netflux.io/rob/solar-toolkit/inverter"
)
func main() {
var inverterAddr string
flag.StringVar(&inverterAddr, "inverter-addr", "", "IP+port of solar inverter")
flag.Parse()
if inverterAddr == "" {
flag.Usage()
os.Exit(1)
}
conn, err := net.Dial("udp", inverterAddr)
if err != nil {
log.Fatalf("error dialing: %s", err)
}
defer conn.Close()
var inv inverter.ET
runtimeData, err := inv.RuntimeData(context.Background(), conn)
if err != nil {
log.Fatalf("error fetching runtime data: %s", err)
}
json, err := json.Marshal(runtimeData)
if err != nil {
log.Fatalf("error encoding runtime data: %s", err)
}
fmt.Fprint(os.Stdout, string(json))
}