2014-12-10 01:27:39 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/spark"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
2014-12-29 00:04:15 +08:00
|
|
|
|
2014-12-10 01:27:39 +08:00
|
|
|
sparkCore := spark.NewSparkCoreAdaptor("spark", "DEVICE_ID", "ACCESS_TOKEN")
|
|
|
|
|
|
|
|
work := func() {
|
2014-12-29 00:04:15 +08:00
|
|
|
if stream, err := sparkCore.EventStream("all", ""); err != nil {
|
|
|
|
fmt.Println(err)
|
2014-12-10 01:27:39 +08:00
|
|
|
} else {
|
2016-08-30 23:53:29 +08:00
|
|
|
// TODO: some other way to handle this
|
|
|
|
// gobot.On(stream, func(data interface{}) {
|
|
|
|
// fmt.Println(data.(spark.Event))
|
|
|
|
// })
|
2014-12-10 01:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("spark",
|
|
|
|
[]gobot.Connection{sparkCore},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
|
|
|
}
|