Skip to content

Instantly share code, notes, and snippets.

@taiyoh
Created February 8, 2016 13:32
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 taiyoh/7bdffe63dff403546c4e to your computer and use it in GitHub Desktop.
Save taiyoh/7bdffe63dff403546c4e to your computer and use it in GitHub Desktop.
package main
import (
// "fmt"
"github.com/kidoman/embd"
_ "github.com/kidoman/embd/host/rpi"
"github.com/taiyoh/go-embd-bme280"
"time"
)
func main() {
config := LoadConfig("config.toml")
if err := embd.InitI2C(); err != nil {
panic(err)
}
defer embd.CloseI2C()
bus := embd.NewI2CBus(1)
opt := bme280.NewOpt()
bme280, err := bme280.New(bus, opt)
if err != nil {
panic(err)
}
// sender
client := NewM2xClient(config.M2x)
for {
data, err := bme280.Read()
if err != nil {
panic(err)
}
// fmt.Printf("temperature: %f\n", data[0])
// fmt.Printf("pressure: %f\n", data[1])
// fmt.Printf("humidity: %f\n", data[2])
go client.Post(data[0], data[1], data[2])
time.Sleep(30 * time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment