Documentation ¶
Overview ¶
Package spark provides the Gobot adaptor for the Spark Core.
Installing:
go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/spark
Example:
package main import ( "time" "github.com/hybridgroup/gobot" "github.com/hybridgroup/gobot/platforms/gpio" "github.com/hybridgroup/gobot/platforms/spark" ) func main() { gbot := gobot.NewGobot() sparkCore := spark.NewSparkCoreAdaptor("spark", "device_id", "access_token") led := gpio.NewLedDriver(sparkCore, "led", "D7") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("spark", []gobot.Connection{sparkCore}, []gobot.Device{led}, work, ) gbot.AddRobot(robot) gbot.Start() }
For further information refer to spark readme: https://github.com/hybridgroup/gobot/blob/master/platforms/spark/README.md
Index ¶
- type Event
- type SparkCoreAdaptor
- func (s *SparkCoreAdaptor) AnalogRead(pin string) (val int, err error)
- func (s *SparkCoreAdaptor) AnalogWrite(pin string, level byte) (err error)
- func (s *SparkCoreAdaptor) Connect() (errs []error)
- func (s *SparkCoreAdaptor) DigitalRead(pin string) (val int, err error)
- func (s *SparkCoreAdaptor) DigitalWrite(pin string, level byte) (err error)
- func (s *SparkCoreAdaptor) EventStream(source string, name string) (event *gobot.Event, err error)
- func (s *SparkCoreAdaptor) Finalize() (errs []error)
- func (s *SparkCoreAdaptor) Function(name string, args string) (val int, err error)
- func (s *SparkCoreAdaptor) Name() string
- func (s *SparkCoreAdaptor) PwmWrite(pin string, level byte) (err error)
- func (s *SparkCoreAdaptor) Variable(name string) (result string, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SparkCoreAdaptor ¶
type SparkCoreAdaptor struct { DeviceID string AccessToken string APIServer string gobot.Eventer // contains filtered or unexported fields }
func NewSparkCoreAdaptor ¶
func NewSparkCoreAdaptor(name string, deviceID string, accessToken string) *SparkCoreAdaptor
NewSparkCoreAdaptor creates new spark core adaptor with deviceId and accessToken using api.spark.io server as default
func (*SparkCoreAdaptor) AnalogRead ¶
func (s *SparkCoreAdaptor) AnalogRead(pin string) (val int, err error)
AnalogRead reads analog ping value using spark cloud api
func (*SparkCoreAdaptor) AnalogWrite ¶
func (s *SparkCoreAdaptor) AnalogWrite(pin string, level byte) (err error)
AnalogWrite writes analog pin with specified level using spark cloud api
func (*SparkCoreAdaptor) Connect ¶
func (s *SparkCoreAdaptor) Connect() (errs []error)
Connect returns true if connection to spark core is successfull
func (*SparkCoreAdaptor) DigitalRead ¶
func (s *SparkCoreAdaptor) DigitalRead(pin string) (val int, err error)
DigitalRead reads from digital pin using spark cloud api
func (*SparkCoreAdaptor) DigitalWrite ¶
func (s *SparkCoreAdaptor) DigitalWrite(pin string, level byte) (err error)
DigitalWrite writes to a digital pin using spark cloud api
func (*SparkCoreAdaptor) EventStream ¶
EventStream returns a gobot.Event based on the following params:
* source - "all"/"devices"/"device" (More info at: http://docs.spark.io/api/#reading-data-from-a-core-events) * name - Event name to subscribe for, leave blank to subscribe to all events.
A new event is emitted as a spark.Event struct
func (*SparkCoreAdaptor) Finalize ¶
func (s *SparkCoreAdaptor) Finalize() (errs []error)
Finalize returns true if connection to spark core is finalized successfully
func (*SparkCoreAdaptor) Function ¶
func (s *SparkCoreAdaptor) Function(name string, args string) (val int, err error)
Function executes a core function and returns value from request. Takes a String as the only argument and returns an Int. If function is not defined in core, it will time out
func (*SparkCoreAdaptor) Name ¶
func (s *SparkCoreAdaptor) Name() string