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