gobot.io/x/gobot/v2@v2.1.0/examples/particle_events.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_events.go mydevice myaccesstoken
    12  */
    13  
    14  package main
    15  
    16  import (
    17  	"fmt"
    18  	"os"
    19  
    20  	"gobot.io/x/gobot/v2"
    21  	"gobot.io/x/gobot/v2/platforms/particle"
    22  )
    23  
    24  func main() {
    25  	core := particle.NewAdaptor(os.Args[1], os.Args[2])
    26  
    27  	work := func() {
    28  		if stream, err := core.EventStream("all", ""); err != nil {
    29  			fmt.Println(err)
    30  		} else {
    31  			// TODO: some other way to handle this
    32  			fmt.Println(stream)
    33  		}
    34  	}
    35  
    36  	robot := gobot.NewRobot("spark",
    37  		[]gobot.Connection{core},
    38  		work,
    39  	)
    40  
    41  	robot.Start()
    42  }