blob: 6aac0c7e3256640900ff5adb2b03a0fc30ced730 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package main
import (
"log"
"time"
"dht11"
"github.com/stianeikeland/go-rpio"
)
const (
RELAY_PIN = 27
TEMP_PIN = 17
)
func toggleRelay(pin *rpio.Pin) {
pin.Output()
pin.PullDown()
pin.High()
time.Sleep(10 * time.Second)
pin.Low()
}
func main() {
err := rpio.Open()
if err != nil {
log.Fatal(err)
}
defer rpio.Close()
tempPin := rpio.Pin(TEMP_PIN)
tempSensor := dht11.NewRaspberryPiDHT11(&tempPin)
if temp, err := tempSensor.GetSensorDataWithRetry(5); err == nil {
log.Printf("temp: %d\n", temp.TempC)
log.Printf("temp: %f\n", temp.TempF)
log.Printf("humidity: %d\n", temp.Humidity)
} else {
log.Printf("Failed to read sensor")
}
}
|