From f034d35a786fc3c292dc4c24cacb2304995e14ac Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Tue, 21 May 2019 13:01:28 +0000 Subject: Initial checkin of working prototype --- main.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..6aac0c7 --- /dev/null +++ b/main.go @@ -0,0 +1,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") + } +} -- cgit v1.2.3