diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -0,0 +1,43 @@ | |||
1 | package main | ||
2 | |||
3 | import ( | ||
4 | "log" | ||
5 | "time" | ||
6 | |||
7 | "dht11" | ||
8 | |||
9 | "github.com/stianeikeland/go-rpio" | ||
10 | ) | ||
11 | |||
12 | const ( | ||
13 | RELAY_PIN = 27 | ||
14 | TEMP_PIN = 17 | ||
15 | ) | ||
16 | |||
17 | func 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 | |||
26 | func 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 | } | ||