gobot.io/x/gobot@v1.16.0/examples/particle_function.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_function.go mydevice myaccesstoken
    10  */
    11  
    12  package main
    13  
    14  import (
    15  	"fmt"
    16  	"os"
    17  
    18  	"gobot.io/x/gobot"
    19  	"gobot.io/x/gobot/platforms/particle"
    20  )
    21  
    22  func main() {
    23  	core := particle.NewAdaptor(os.Args[1], os.Args[2])
    24  
    25  	work := func() {
    26  		if result, err := core.Function("brew", "202,230"); err != nil {
    27  			fmt.Println(err)
    28  		} else {
    29  			fmt.Println("result from \"brew\":", result)
    30  		}
    31  	}
    32  
    33  	robot := gobot.NewRobot("spark",
    34  		[]gobot.Connection{core},
    35  		work,
    36  	)
    37  
    38  	robot.Start()
    39  }