mirror of
https://github.com/steinhobelgruen/netatmo-api-go.git
synced 2024-11-23 23:03:56 +00:00
Fix
This commit is contained in:
parent
dbb64a439a
commit
82ab0252b0
86
README.md
86
README.md
|
@ -5,70 +5,72 @@ Currently tested only with one weather station, outdoor and indoor modules. Let
|
||||||
|
|
||||||
## Quickstart
|
## Quickstart
|
||||||
|
|
||||||
[Create a new netatmo app](https://dev.netatmo.com/dev/createapp)
|
- [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)
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/exzz/netatmo-api-go"
|
"github.com/exzz/netatmo-api-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
n, err := netatmo.NewClient(netatmo.Config{
|
n, err := netatmo.NewClient(netatmo.Config{
|
||||||
ClientID: "YOUR_APP_ID",
|
ClientID: "YOUR_APP_ID",
|
||||||
ClientSecret: "YOUR_APP_SECRET",
|
ClientSecret: "YOUR_APP_SECRET",
|
||||||
Username: "YOUR_CREDENTIAL",
|
Username: "YOUR_CREDENTIAL",
|
||||||
Password: "YOUR_PASSWORD",
|
Password: "YOUR_PASSWORD",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
dc, err := n.GetDeviceCollection()
|
dc, err := n.GetDeviceCollection()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, station := range dc.Stations() {
|
for _, station := range dc.Stations() {
|
||||||
fmt.Printf("Station : %s\n", station.StationName)
|
fmt.Printf("Station : %s\n", station.StationName)
|
||||||
|
|
||||||
for _, module := range station.Modules() {
|
for _, module := range station.Modules() {
|
||||||
fmt.Printf("\tModule : %s\n", module.ModuleName)
|
fmt.Printf("\tModule : %s\n", module.ModuleName)
|
||||||
|
|
||||||
ts, data := module.Data()
|
ts, data := module.Data()
|
||||||
for dataType, value := range data {
|
for dataType, value := range data {
|
||||||
fmt.Printf("\t\t%s : %s (%d)\n", dataType, value, ts)
|
fmt.Printf("\t\t%s : %s (%d)\n", dataType, value, ts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Output should looks like this :
|
Output should look like this :
|
||||||
```
|
```
|
||||||
Station : Home
|
Station : Home
|
||||||
Module : Outside
|
Module : Outside
|
||||||
Temperature : %!s(float32=20.2) (1440302379)
|
Temperature : %!s(float32=20.2) (1440302379)
|
||||||
Humidity : %!s(int32=86) (1440302379)
|
Humidity : %!s(int32=86) (1440302379)
|
||||||
Module : Bedroom 1
|
Module : Bedroom 1
|
||||||
CO2 : %!s(int32=500) (1441981664)
|
CO2 : %!s(int32=500) (1441981664)
|
||||||
Humidity : %!s(int32=69) (1441981664)
|
Humidity : %!s(int32=69) (1441981664)
|
||||||
Temperature : %!s(float32=21.2) (1441981664)
|
Temperature : %!s(float32=21.2) (1441981664)
|
||||||
Module : Bedroom 2
|
Module : Bedroom 2
|
||||||
Temperature : %!s(float32=21) (1441981632)
|
Temperature : %!s(float32=21) (1441981632)
|
||||||
CO2 : %!s(int32=508) (1441981632)
|
CO2 : %!s(int32=508) (1441981632)
|
||||||
Humidity : %!s(int32=68) (1441981632)
|
Humidity : %!s(int32=68) (1441981632)
|
||||||
Module : Living room
|
Module : Living room
|
||||||
Temperature : %!s(float32=22.1) (1441981633)
|
Temperature : %!s(float32=22.1) (1441981633)
|
||||||
CO2 : %!s(int32=516) (1441981633)
|
CO2 : %!s(int32=516) (1441981633)
|
||||||
Humidity : %!s(int32=67) (1441981633)
|
Humidity : %!s(int32=67) (1441981633)
|
||||||
Module : Dining room
|
Module : Dining room
|
||||||
Humidity : %!s(int32=75) (1441982895)
|
Humidity : %!s(int32=75) (1441982895)
|
||||||
Noise : %!s(int32=36) (1441982895)
|
Noise : %!s(int32=36) (1441982895)
|
||||||
|
@ -78,5 +80,5 @@ Station : Home
|
||||||
|
|
||||||
```
|
```
|
||||||
## Tips
|
## Tips
|
||||||
- Only GetDeviceCollection() method actually do an API call ands refresh all data at once
|
- Only GetDeviceCollection() method actually do an API call and refresh all data at once
|
||||||
- Main station is handle as a module, it means that Modules() method returns list of additional modules and station itself.
|
- Main station is handle as a module, it means that Modules() method returns list of additional modules and station itself.
|
||||||
|
|
Loading…
Reference in a new issue