-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolarapi.go
50 lines (42 loc) · 818 Bytes
/
solarapi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
"os"
)
type Response struct {
Name string
Body Body
Head Head
}
type Body struct {
Data Data
}
type Data struct {
Site Site
}
type Site struct {
P_PV int `json:"P_PV"`
E_Total int `json:"E_Total"`
}
type Head struct {
Timestamp time.Time
}
func main() {
response, err := http.Get("http://pv.fritz.box/solar_api/v1/GetPowerFlowRealtimeData.fcgi")
if err != nil {
os.Exit(1)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
os.Exit(1)
}
var result Response
json.Unmarshal(responseData, &result)
var timestamp = result.Head.Timestamp.Unix()
fmt.Printf("%v: Power = %v\n", timestamp, result.Body.Data.Site.P_PV)
fmt.Printf("%v: Export = %v\n", timestamp, result.Body.Data.Site.E_Total)
}