Skip to content

Instantly share code, notes, and snippets.

@craftzdog
Created September 10, 2018 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craftzdog/ca99d84059a00689ed9852ac74a0e452 to your computer and use it in GitHub Desktop.
Save craftzdog/ca99d84059a00689ed9852ac74a0e452 to your computer and use it in GitHub Desktop.
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