spark

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2016 License: Apache-2.0, Apache-2.0 Imports: 9 Imported by: 0

README

Spark

The Spark Core is a Wi-Fi connected microcontroller from Particle (http://particle.io), the company formerly known as Spark Devices. Once it connects to a Wi-Fi network, it automatically connects with a central server (the "Spark Cloud") and stays connected so it can be controlled from external systems, such as a Gobot program. To run gobot programs please make sure you are running default tinker firmware on the Spark Core.

For more info about the Spark platform click here

How to Install

Installing Gobot with Spark support is pretty easy.

go get -d -u github.com/hybridgroup/gobot/... && go install github.com/hybridgroup/gobot/platforms/spark

How to Use

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()
}

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Name  string
	Data  string
	Error error
}

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

func (s *SparkCoreAdaptor) EventStream(source string, name string) (event *gobot.Event, err error)

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

func (*SparkCoreAdaptor) PwmWrite

func (s *SparkCoreAdaptor) PwmWrite(pin string, level byte) (err error)

PwmWrite writes in pin using analog write api

func (*SparkCoreAdaptor) Variable

func (s *SparkCoreAdaptor) Variable(name string) (result string, err error)

Variable returns a core variable value as a string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL