add: humidity (WIP)
This commit is contained in:
30
pkg/humidity/humidity.go
Normal file
30
pkg/humidity/humidity.go
Normal file
@ -0,0 +1,30 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user