2014-12-09 22:33:02 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-12-28 20:46:27 +08:00
|
|
|
"time"
|
2014-12-09 22:33:02 +08:00
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/spark"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
|
2014-12-09 22:58:52 +08:00
|
|
|
sparkCore := spark.NewSparkCoreAdaptor("spark", "DEVICE_ID", "ACCESS_TOKEN")
|
2014-12-09 22:33:02 +08:00
|
|
|
|
|
|
|
work := func() {
|
2014-12-28 20:46:27 +08:00
|
|
|
gobot.Every(1*time.Second, func() {
|
|
|
|
if temp, err := sparkCore.Variable("temperature"); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
} else {
|
|
|
|
fmt.Println("result from \"temperature\" is:", temp)
|
|
|
|
}
|
|
|
|
})
|
2014-12-09 22:33:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("spark",
|
|
|
|
[]gobot.Connection{sparkCore},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
|
|
|
}
|