netatmo-api-go/README.md

90 lines
2.5 KiB
Markdown
Raw Normal View History

2015-09-11 14:38:11 +00:00
# netatmo-api-go
2015-09-11 14:57:03 +00:00
Simple API to access Netatmo weather station data written in Go.
2016-11-14 12:48:34 +00:00
Currently tested only with one weather station, outdoor and indoor modules and rain gauge. Let me know if it works with wind gauge.
2015-09-11 14:57:03 +00:00
## Quickstart
2015-09-11 15:14:09 +00:00
- [Create a new netatmo app](https://dev.netatmo.com/dev/createapp)
- Download module ```go get github.com/exzz/netatmo-api-go```
- Try below example (do not forget to edit auth credentials)
2015-09-11 14:57:03 +00:00
## Example
2016-11-14 12:48:34 +00:00
```
go
package main
2015-09-11 14:57:03 +00:00
import (
2016-11-14 12:48:34 +00:00
"fmt"
"os"
2015-09-11 14:57:03 +00:00
2016-11-14 12:48:34 +00:00
netatmo "github.com/exzz/netatmo-api-go"
2015-09-11 14:57:03 +00:00
)
func main() {
2016-11-14 12:48:34 +00:00
n, err := netatmo.NewClient(netatmo.Config{
2015-09-11 14:57:03 +00:00
ClientID: "YOUR_APP_ID",
ClientSecret: "YOUR_APP_SECRET",
Username: "YOUR_CREDENTIAL",
Password: "YOUR_PASSWORD",
2016-11-14 12:48:34 +00:00
})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
2015-09-11 14:57:03 +00:00
2016-11-14 12:48:34 +00:00
dc, err := n.Read()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
2015-09-11 14:57:03 +00:00
2016-11-14 12:48:34 +00:00
for _, station := range dc.Stations() {
fmt.Printf("Station : %s\n", station.StationName)
2015-09-11 14:57:03 +00:00
2016-11-14 12:48:34 +00:00
for _, module := range station.Modules() {
fmt.Printf("\tModule : %s\n", module.ModuleName)
2015-09-11 14:57:03 +00:00
2016-11-14 12:48:34 +00:00
ts, data := module.Data()
for dataType, value := range data {
fmt.Printf("\t\t%s : %s (%d)\n", dataType, value, ts)
}
}
}
2015-09-11 14:57:03 +00:00
}
```
2015-09-11 15:14:09 +00:00
Output should look like this :
2015-09-11 14:57:03 +00:00
```
Station : Home
2016-11-14 12:48:34 +00:00
Module : Chambre Enfant
Temperature : %!s(float32=18.4) (1479127223)
CO2 : %!s(int32=567) (1479127223)
Humidity : %!s(int32=65) (1479127223)
Module : Chambre
Temperature : %!s(float32=18.1) (1479127230)
CO2 : %!s(int32=494) (1479127230)
Humidity : %!s(int32=65) (1479127230)
Module : Salon
Temperature : %!s(float32=18.3) (1479127217)
CO2 : %!s(int32=434) (1479127217)
Humidity : %!s(int32=63) (1479127217)
Module : Exterieur
Temperature : %!s(float32=11.9) (1479127243)
Humidity : %!s(int32=81) (1479127243)
Module : Pluie
Rain : %!s(float32=0) (1479127249)
Module : Salle à manger
Temperature : %!s(float32=17.8) (1479127255)
CO2 : %!s(int32=473) (1479127255)
Humidity : %!s(int32=68) (1479127255)
Noise : %!s(int32=36) (1479127255)
Pressure : %!s(float32=1033.3) (1479127255)
2015-09-11 14:57:03 +00:00
```
## Tips
2016-07-29 13:54:09 +00:00
- Only Read() method actually do an API call and refresh all data at once
2015-09-11 14:57:03 +00:00
- Main station is handle as a module, it means that Modules() method returns list of additional modules and station itself.