PKGBUILD/pkg/humidity/humidity.go

31 lines
521 B
Go
Raw Normal View History

2018-12-04 18:11:50 +00:00
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
}