Created
September 10, 2018 06:25
-
-
Save craftzdog/ca99d84059a00689ed9852ac74a0e452 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sensors | |
// Temperature and Pressure sensor | |
import ( | |
"log" | |
"os/exec" | |
"strings" | |
"strconv" | |
) | |
func GetTempAndPressure() (temperature float64, pressure float64, err error) { | |
out, err := exec.Command("/home/pi/anavi-examples/sensors/BMP180/c/BMP180").Output() | |
if err != nil { | |
log.Fatal(err) | |
} | |
s := string(out[:len(out)]) | |
lines := strings.Split(s, "\n") | |
lineTemp := lines[1] | |
linePress := lines[2] | |
tempStr := strings.Split(lineTemp, ": ")[1] | |
temperature, err = strconv.ParseFloat(tempStr[0:len(tempStr)-2], 32) | |
pressStr := strings.Split(linePress, ": ")[1] | |
pressure, err = strconv.ParseFloat(pressStr[0:len(pressStr)-4], 32) | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment