Documentation ¶
Index ¶
- Constants
- Variables
- func CronAfter(a Afterer) func(*Cron) error
- func CronJobs(j []string) func(*Cron) error
- func CronSleep(d time.Duration) func(*Cron) error
- func FileExists(path string) bool
- func GetUUID() string
- func ParseCommand(cmd string) (float64, string, error)
- func RegisterInput(name string, f CreateInputDevice)
- func RegisterOutput(name string, f CreateOutputDevice)
- func XBeeSerialPort(p serial.Port) func(InputDevice) error
- type Afterer
- type Alarm
- type App
- type Boiler
- type Broker
- type Commands
- type Comparitor
- type Config
- type Cooler
- type CreateInputDevice
- type CreateOutputDevice
- type Cron
- type File
- type FlowMeter
- type GPIO
- type Gadget
- type GadgetConfig
- type Gadgeter
- type GoGadgeter
- type Heater
- type Info
- type InputDevice
- func NewFlowMeter(pin *Pin, opts ...func(InputDevice) error) (InputDevice, error)
- func NewInputDevice(pin *Pin) (dev InputDevice, err error)
- func NewSwitch(pin *Pin, opts ...func(InputDevice) error) (InputDevice, error)
- func NewThermometer(pin *Pin, opts ...func(InputDevice) error) (InputDevice, error)
- func NewXBee(pin *Pin, opts ...func(InputDevice) error) (InputDevice, error)
- type Message
- type Method
- type MethodRunner
- type Motor
- type OutputDevice
- func NewAlarm(pin *Pin) (OutputDevice, error)
- func NewBoiler(pin *Pin) (OutputDevice, error)
- func NewCooler(pin *Pin) (OutputDevice, error)
- func NewFile(pin *Pin) (OutputDevice, error)
- func NewGPIO(pin *Pin) (OutputDevice, error)
- func NewHeater(pin *Pin) (OutputDevice, error)
- func NewMotor(pin *Pin) (OutputDevice, error)
- func NewOutputDevice(pin *Pin) (dev OutputDevice, err error)
- func NewPWM(pin *Pin) (OutputDevice, error)
- func NewRecorder(pin *Pin) (OutputDevice, error)
- func NewSMS(pin *Pin) (OutputDevice, error)
- func NewThermostat(pin *Pin) (OutputDevice, error)
- type PWM
- type Pin
- type Poller
- type Queue
- type Recorder
- type SMS
- type Server
- type Switch
- type Thermometer
- type Thermostat
- type Value
- type XBee
- type XBeeConfig
Constants ¶
const (
NANO = 1000000000.0
)
const (
Version = "0.0.3"
)
Variables ¶
var ( COMMAND = "command" ERROR = "error" METHOD = "method" DONE = "done" UPDATE = "update" GADGET = "gadget" STATUS = "status" METHODUPDATE = "method update" )
var ( GPIO_DEV_PATH = "/sys/class/gpio" GPIO_DEV_MODE = os.ModeDevice )
var ( Pins = map[string]map[string]map[string]string{ "gpio": map[string]map[string]string{ "8": map[string]string{ "7": "66", "8": "67", "9": "69", "10": "68", "11": "45", "12": "44", "14": "26", "15": "47", "16": "46", "26": "61", }, "9": map[string]string{ "12": "60", "14": "50", "15": "48", "16": "51", }, }, "pwm": map[string]map[string]string{ "8": map[string]string{ "13": "bone_pwm_p8_13", "19": "bone_pwm_p8_19", }, "9": map[string]string{ "14": "bone_pwm_p9_14", "16": "bone_pwm_p9_16", "21": "bone_pwm_p9_21", "22": "bone_pwm_p9_22", }, }, } PiPins = map[string]string{ "7": "4", "11": "17", "12": "18", "13": "27", "15": "22", "16": "23", "18": "24", "22": "25", "29": "5", "31": "6", "32": "12", "33": "13", "35": "19", "36": "16", "37": "26", "38": "20", "40": "21", } )
The beaglebone black GPIO pins that are available by default. You can use the device tree overlay to get more.
var ( PWMMode = os.ModeDevice PWM_DEVPATH = "/sys/devices/ocp.*/pwm_test_P%s_%s.*" TREEPATH = "/sys/devices/bone_capemgr.*/slots" )
Functions ¶
func RegisterInput ¶
func RegisterInput(name string, f CreateInputDevice)
func RegisterOutput ¶
func RegisterOutput(name string, f CreateOutputDevice)
func XBeeSerialPort ¶
func XBeeSerialPort(p serial.Port) func(InputDevice) error
Types ¶
type Alarm ¶
type Alarm struct {
// contains filtered or unexported fields
}
Alarm (when 'on') turns on its output devices when any of the events defined in pin.Args.Events happens. It turns off after:
1: alarm.duration has passed 2: the alarm is turned off
type App ¶
type App struct {
// contains filtered or unexported fields
}
App holds all the gadgets and handles passing Messages to them, and receiving Messages from them. It is the central part of Gadgets system.
func New ¶
New creates a new Gadgets system. The cfg argument can be a path to a json file or a Config object itself.
type Boiler ¶
type Boiler struct {
// contains filtered or unexported fields
}
Configure a boiler like:
{ "host": "http://192.168.1.30:6111", "gadgets": [ { "location": "the lab", "name": "temperature", "pin": { "type": "thermometer", "OneWireId": "28-0000041cb544", "Units": "F" } }, { "location": "the lab", "name": "heater", "pin": { "type": "boiler", "port": "8", "pin": "11", "args": { "type": "heater", "sensor": "the lab temperature", "high": 150.0, "low": 120.0 } } } ] }
With this config the boiler will react to temperatures from 'the lab temperature' (which is the location + name of the thermometer) and turn on the gpio if the temperature is > 120.0, turn and turn it off when the temperature > 150.0.
If you set args.type = "cooler" then it will start cooling when the temperature gets above 150, and stop cooling when the temperature gets below 120.
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
All the gadgets of the system push their messages here.
type Comparitor ¶
type Config ¶
type Config struct { Master string `json:"master,omitempty"` Host string `json:"host,omitempty"` Port int `json:"port,omitempty"` Gadgets []GadgetConfig `json:"gadgets,omitempty"` }
func (Config) CreateGadgets ¶
type CreateInputDevice ¶
type CreateInputDevice func(pin *Pin, opts ...func(InputDevice) error) (InputDevice, error)
type CreateOutputDevice ¶
type CreateOutputDevice func(pin *Pin) (OutputDevice, error)
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
func (*Cron) GetDirection ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is a way to a debug gadgets system. Doesn't really do anything.
type FlowMeter ¶
type FlowMeter struct { GPIO Poller //Value represents the total volume represented by //a pulse (rate is calculated from this total volume). Value float64 //min_span is the minimum number of seconds between //2 pulses from the physical flow meter. It is used //for de-bouncing the signal. MinSpan float64 Units string // contains filtered or unexported fields }
FlowMeter waits for a high pulse from a gpio pin then caclulates the flow based on the time between high pulses.
type GPIO ¶
type GPIO struct {
// contains filtered or unexported fields
}
GPIO interacts with the linux sysfs interface for GPIO to turn pins on and off. The pins that are listed in gogadgets.Pins have been found to be availabe by default but by using the device tree overlay you can make more pins available. GPIO also has a Wait method and can poll a pin and wait for a change of direction.
type Gadget ¶
type Gadget struct { Type string Location string Name string Output OutputDevice Input InputDevice Direction string OnCommands []string OffCommands []string InitialValue string UID string Operator string // contains filtered or unexported fields }
Each part of a Gadgets system that controls a single piece of hardware (for example: a gpio pin) is represented by Gadget. A Gadget must have either an InputDevice or an OutputDevice. Gadget fulfills the GoGaget interface.
func (*Gadget) GetDirection ¶
type GadgetConfig ¶
type GadgetConfig struct { Type string `json:"type,omitempty"` Location string `json:"location,omitempty"` Name string `json:"name,omitempty"` OnCommands []string `json:"on_commands,omitempty"` OffCommands []string `json:"off_commands,omitempty"` OnValue string `json:"on_value,omitempty"` OffValue string `json:"off_value,omitempty"` InitialValue string `json:"initial_value,omitempty"` Pin Pin `json:"pin,omitempty"` Args map[string]interface{} `json:"args,omitempty"` }
type Gadgeter ¶
type Gadgeter interface { GetUID() string GetDirection() string Start(in <-chan Message, out chan<- Message) }
func NewGadget ¶
func NewGadget(config *GadgetConfig) (Gadgeter, error)
NewGadget returns a gadget with an input or output device There are several types of Input/Output devices build into GoGadgets (eg: header, cooler, gpio, thermometer and switch) NewGadget reads a GadgetConfig and creates the correct type of Gadget.
type GoGadgeter ¶
type Heater ¶
type Heater struct {
// contains filtered or unexported fields
}
Heater represents an electic heating element. It provides a way to heat up something to a target temperature. In order to use this there must be a thermometer in the same Location.
type InputDevice ¶
Inputdevices are started as goroutines by the Gadget that contains it.
func NewFlowMeter ¶
func NewFlowMeter(pin *Pin, opts ...func(InputDevice) error) (InputDevice, error)
func NewInputDevice ¶
func NewInputDevice(pin *Pin) (dev InputDevice, err error)
func NewSwitch ¶
func NewSwitch(pin *Pin, opts ...func(InputDevice) error) (InputDevice, error)
func NewThermometer ¶
func NewThermometer(pin *Pin, opts ...func(InputDevice) error) (InputDevice, error)
func NewXBee ¶
func NewXBee(pin *Pin, opts ...func(InputDevice) error) (InputDevice, error)
type Message ¶
type Message struct { UUID string `json:"uuid"` From string `json:"from,omitempty"` Name string `json:"name,omitempty"` Location string `json:"location,omitempty"` Type string `json:"type,omitempty"` Sender string `json:"sender,omitempty"` Target string `json:"target,omitempty"` Body string `json:"body,omitempty"` Host string `json:"host,omitempty"` Method Method `json:"method,omitempty"` Timestamp time.Time `json:"timestamp,omitempty"` Value Value `json:"value,omitempty"` TargetValue *Value `json:"target_value,omitempty"` Info Info `json:"info,omitempty"` Config Config `json:"config,omitempty"` }
Message is what all Gadgets pass around to each other.
type MethodRunner ¶
type MethodRunner struct {
// contains filtered or unexported fields
}
Gadgets respond to the Robot Command Language (RCL) and a list of RCL messages can be run to form a method. Runner takes a method as input and runs it.
If a RCL message starts with 'wait' runner pauses the method and waits for the condition if the wait to be fulfilled. For example, if the RCL message
'wait for 5 seconds'
is recieved, Runner waits for 5 seconds and continues with the the rest of the message.
Another example would be
'wait for boiler temperature >= 200 F'.
MethodRunner would then wait for a message from the boiler that says its temperature is 200 F (or more). It then sends the next message of the method
func (*MethodRunner) GetDirection ¶
func (m *MethodRunner) GetDirection() string
func (*MethodRunner) GetUID ¶
func (m *MethodRunner) GetUID() string
func (*MethodRunner) Start ¶
func (m *MethodRunner) Start(in <-chan Message, out chan<- Message)
type Motor ¶
type Motor struct {
// contains filtered or unexported fields
}
Motor controls a http://www.pololu.com/product/1451 motor driver carrier.
| | | | | O O O O O O O O O O | --|-------------------- | | | | ===
type OutputDevice ¶
type OutputDevice interface { On(val *Value) error Off() error Update(msg *Message) bool Status() map[string]bool Commands(string, string) *Commands }
OutputDevice turns things on and off. Currently the
func NewAlarm ¶
func NewAlarm(pin *Pin) (OutputDevice, error)
func NewBoiler ¶
func NewBoiler(pin *Pin) (OutputDevice, error)
func NewCooler ¶
func NewCooler(pin *Pin) (OutputDevice, error)
func NewFile ¶
func NewFile(pin *Pin) (OutputDevice, error)
func NewGPIO ¶
func NewGPIO(pin *Pin) (OutputDevice, error)
func NewHeater ¶
func NewHeater(pin *Pin) (OutputDevice, error)
func NewMotor ¶
func NewMotor(pin *Pin) (OutputDevice, error)
func NewOutputDevice ¶
func NewOutputDevice(pin *Pin) (dev OutputDevice, err error)
func NewPWM ¶
func NewPWM(pin *Pin) (OutputDevice, error)
func NewRecorder ¶
func NewRecorder(pin *Pin) (OutputDevice, error)
func NewSMS ¶
func NewSMS(pin *Pin) (OutputDevice, error)
func NewThermostat ¶
func NewThermostat(pin *Pin) (OutputDevice, error)
type PWM ¶
type PWM struct {
// contains filtered or unexported fields
}
echo am33xx_pwm > /sys/devices/bone_capemgr.9/slots echo bone_pwm_P8_13 > /sys/devices/bone_capemgr.9/slots /sys/devices/ocp.3/pwm_test_P8_13.15
type Pin ¶
type Pin struct { Type string `json:"type,omitempty"` Port string `json:"port,omitempty"` Pin string `json:"pin,omitempty"` Direction string `json:"direction,omitempty"` Edge string `json:"edge,omitempty"` ActiveLow string `json:"active_low,omitempty"` OneWirePath string `json:"onewire_path,omitempty"` OneWireId string `json:"onewire_id,omitempty"` Sleep time.Duration `json:"sleep,omitempty"` Value interface{} `json:"value,omitempty"` Units string `json:"units,omitempty"` //Platform is either "rpi" or "beaglebone" Platform string `json:"platform,omitempty"` Frequency int `json:"frequency,omitempty"` Args map[string]interface{} `json:"args,omitempty"` Pins map[string]Pin `json:"pins,omitempty"` Lock *sync.Mutex `json:"-"` // contains filtered or unexported fields }
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
All of the gadgets in a gadgets app push their messages through a single channel. This queue guarantees that all gadgets with be able to send their message without being blocked.
func (*Queue) Wait ¶
func (q *Queue) Wait()
One goroutine pushes the incoming messages to this queue, and another goroutine grabs messages from the queue and pushes them back out to the system. This method adds synchronization so that when the queue is empty the second goroutine is blocked until a message is pushed to the queue.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder takes all the update messages it receives and saves them by posting to quimby
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) GetDirection ¶
type Switch ¶
type Switch struct { GPIO Poller Value bool Units string // contains filtered or unexported fields }
Switch is an input device that waits for a GPIO pin to change value (1 to 0 or 0 to 1). When that change happens it sends an update to the rest of the system.
type Thermometer ¶
type Thermometer struct {
// contains filtered or unexported fields
}
func (*Thermometer) GetValue ¶
func (t *Thermometer) GetValue() *Value
func (*Thermometer) Start ¶
func (t *Thermometer) Start(in <-chan Message, out chan<- Value)
This is an InputDevice, so it must have a Start.
type Thermostat ¶
type Thermostat struct {
// contains filtered or unexported fields
}
Thermostat is used for controlling a furnace. Configure a thermostat like:
{ "host": "http://192.168.1.18:6111", "gadgets": [ { "location": "home", "name": "temperature", "pin": { "type": "thermometer", "OneWireId": "28-0000041cb544", "Units": "F" } }, { "location": "home", "name": "furnace", "pin": { "type": "thermostat", "pins": { "heat": { "platform": "rpi", "pin": "11", "direction": "out" }, "cool": { "platform": "rpi", "pin": "13", "direction": "out" }, "fan": { "platform": "rpi", "pin": "15", "direction": "out" } }, "args": { "sensor": "home temperature", "timeout": "5m" } } } ] }
With this config the thermostat will react to temperatures from 'the lab temperature' (which is the location + name of the thermometer) and turn on the gpio if the temperature is > 120.0, turn and turn it off when the temperature > 150.0.
If you set args.type = "cooler" then it will start cooling when the temperature gets above 150, and stop cooling when the temperature gets below 120.
func (*Thermostat) Commands ¶
func (t *Thermostat) Commands(location, name string) *Commands
func (*Thermostat) Off ¶
func (t *Thermostat) Off() error
func (*Thermostat) On ¶
func (t *Thermostat) On(val *Value) error
func (*Thermostat) Status ¶
func (t *Thermostat) Status() map[string]bool
func (*Thermostat) Update ¶
func (t *Thermostat) Update(msg *Message) bool