PKGBUILD/pkg/humidity/humidity.go
2018-12-07 20:42:30 +01:00

31 lines
521 B
Go

package humidity
import (
"fmt"
dht "github.com/MichaelS11/go-dht"
)
func Get() error {
err := dht.HostInit()
if err != nil {
return fmt.Errorf("HostInit error: %v", err)
}
dht, err := dht.NewDHT("GPIO19", dht.Celsius, "dht11")
if err != nil {
return fmt.Errorf("NewDHT error: %v", err)
}
humidity, temperature, err := dht.ReadRetry(10)
if err != nil {
return fmt.Errorf("Read error: %v", err)
}
fmt.Printf("humidity: %v\n", humidity)
fmt.Printf("temperature: %v\n", temperature)
return nil
}