summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..6aac0c7
--- /dev/null
+++ b/main.go
@@ -0,0 +1,43 @@
1package main
2
3import (
4 "log"
5 "time"
6
7 "dht11"
8
9 "github.com/stianeikeland/go-rpio"
10)
11
12const (
13 RELAY_PIN = 27
14 TEMP_PIN = 17
15)
16
17func toggleRelay(pin *rpio.Pin) {
18 pin.Output()
19 pin.PullDown()
20
21 pin.High()
22 time.Sleep(10 * time.Second)
23 pin.Low()
24}
25
26func main() {
27 err := rpio.Open()
28 if err != nil {
29 log.Fatal(err)
30 }
31 defer rpio.Close()
32
33 tempPin := rpio.Pin(TEMP_PIN)
34 tempSensor := dht11.NewRaspberryPiDHT11(&tempPin)
35
36 if temp, err := tempSensor.GetSensorDataWithRetry(5); err == nil {
37 log.Printf("temp: %d\n", temp.TempC)
38 log.Printf("temp: %f\n", temp.TempF)
39 log.Printf("humidity: %d\n", temp.Humidity)
40 } else {
41 log.Printf("Failed to read sensor")
42 }
43}