gobot.io/x/gobot@v1.16.0/examples/particle_variable.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 /* 6 To run this example, pass the device ID as first param, 7 and the access token as the second param: 8 9 go run examples/particle_variable.go mydevice myaccesstoken 10 */ 11 12 package main 13 14 import ( 15 "fmt" 16 "os" 17 "time" 18 19 "gobot.io/x/gobot" 20 "gobot.io/x/gobot/platforms/particle" 21 ) 22 23 func main() { 24 core := particle.NewAdaptor(os.Args[1], os.Args[2]) 25 26 work := func() { 27 gobot.Every(1*time.Second, func() { 28 if temp, err := core.Variable("temperature"); err != nil { 29 fmt.Println(err) 30 } else { 31 fmt.Println("result from \"temperature\" is:", temp) 32 } 33 }) 34 } 35 36 robot := gobot.NewRobot("spark", 37 []gobot.Connection{core}, 38 work, 39 ) 40 41 robot.Start() 42 }