particle

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2017 License: Apache-2.0, Apache-2.0 Imports: 9 Imported by: 0

README

Particle

The Particle Photon and Particle Electron are connected microcontrollers from Particle (http://particle.io), the company formerly known as Spark Devices. The Photon uses a Wi-Fi connection to the Particle cloud, and the Electron uses a 3G wireless connection. Once the Photon or Electron connects to the network, it automatically connects with a central server (the "Particle 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 Photon or Electron.

For more info about the Particle platform go to https://www.particle.io/

How to Install

Installing Gobot with Particle support is pretty easy.

go get -d -u gobot.io/x/gobot/...

How to Use

package main

import (
	"time"

	"gobot.io/x/gobot"
	"gobot.io/x/gobot/drivers/gpio"
	"gobot.io/x/gobot/platforms/particle"
)

func main() {
	core := particle.NewAdaptor("device_id", "access_token")
	led := gpio.NewLedDriver(core, "D7")

	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	robot := gobot.NewRobot("spark",
		[]gobot.Connection{core},
		[]gobot.Device{led},
		work,
	)

	robot.Start()
}

Documentation

Overview

Package particle provides the Gobot adaptor for the Particle Photon and Electron.

Installing:

go get gobot.io/x/gobot && go install gobot.io/x/gobot/platforms/particle

Example:

package main

import (
	"time"

	"gobot.io/x/gobot"
	"gobot.io/x/gobot/drivers/gpio"
	"gobot.io/x/gobot/platforms/particle"
)

func main() {
	core := paticle.NewAdaptor("device_id", "access_token")
	led := gpio.NewLedDriver(core, "D7")

	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	robot := gobot.NewRobot("particle",
		[]gobot.Connection{core},
		[]gobot.Device{led},
		work,
	)

	robot.Start()
}

For further information refer to Particle readme: https://github.com/hybridgroup/gobot/blob/master/platforms/particle/README.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adaptor

type Adaptor struct {
	DeviceID    string
	AccessToken string
	APIServer   string

	gobot.Eventer
	// contains filtered or unexported fields
}

Adaptor is the Gobot Adaptor for Particle

func NewAdaptor

func NewAdaptor(deviceID string, accessToken string) *Adaptor

NewAdaptor creates new Photon adaptor with deviceId and accessToken using api.particle.io server as default

func (*Adaptor) AnalogRead

func (s *Adaptor) AnalogRead(pin string) (val int, err error)

AnalogRead reads analog ping value using Particle cloud api

func (*Adaptor) AnalogWrite

func (s *Adaptor) AnalogWrite(pin string, level byte) (err error)

AnalogWrite writes analog pin with specified level using Particle cloud api

func (*Adaptor) Connect

func (s *Adaptor) Connect() (err error)

Connect returns true if connection to Particle Photon or Electron is successful

func (*Adaptor) DigitalRead

func (s *Adaptor) DigitalRead(pin string) (val int, err error)

DigitalRead reads from digital pin using Particle cloud api

func (*Adaptor) DigitalWrite

func (s *Adaptor) DigitalWrite(pin string, level byte) (err error)

DigitalWrite writes to a digital pin using Particle cloud api

func (*Adaptor) EventStream

func (s *Adaptor) 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.particle.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 particle.Event struct

func (*Adaptor) Finalize

func (s *Adaptor) Finalize() (err error)

Finalize returns true if connection to Particle Photon or Electron is finalized successfully

func (*Adaptor) Function

func (s *Adaptor) 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 (*Adaptor) Name

func (s *Adaptor) Name() string

Name returns the Adaptor name

func (*Adaptor) PwmWrite

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

PwmWrite writes in pin using analog write api

func (*Adaptor) ServoWrite added in v1.1.0

func (s *Adaptor) ServoWrite(pin string, angle byte) (err error)

ServoWrite writes the 0-180 degree angle to the specified pin. To use it requires installing the "tinker-servo" sketch on your Particle device. not just the default "tinker".

func (*Adaptor) SetName

func (s *Adaptor) SetName(n string)

SetName sets the Adaptor name

func (*Adaptor) Variable

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

Variable returns a core variable value as a string

type Event

type Event struct {
	Name  string
	Data  string
	Error error
}

Event is an event emitted by the Particle cloud

Jump to

Keyboard shortcuts

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