...

Package uiot

import "github.com/TrevorFarrelly/u-iot"
Overview
Index
Subdirectories

Overview ▾

Package uiot provides functionality for building your own smart home network.

func Close

func Close()

Close notifies all known remote devices that this device is disconnecting from the network.

func CloseHandler

func CloseHandler()

CloseHandler adds a SIGTERM handler to automatically disconnect from the network.

type Device

Device represents a device's location and functionality within a home.

type Device struct {
    Name  string
    Type  Type
    Room  Room
    Funcs map[string]*Func
    // contains filtered or unexported fields
}

func NewDevice

func NewDevice(name string, t Type, r Room) *Device

NewDevice creates a new device with the provided name, room, and type. This device is intended to be used locally, as a place to define functions that can be called remotely.

func (*Device) AddFunction

func (d *Device) AddFunction(name string, f func(...int), p ...Param) error

AddFunction adds a function f to device d. Remote devices can call this function using the provided name and params, p.

func (Device) CallFunc

func (d Device) CallFunc(name string, p ...int) error

CallFunc calls a remote device's function with the provided parameter values. Parameter checking is handled internally, i.e. if the provided parameters are outside the range specified in AddFunction, CallFunc will return an error.

func (Device) String

func (d Device) String() string

String returns a string representing this device, in the form (type, room) name: func func func...

type Event

Event represents a change in state in the network. Used in the Network struct, specifically when the user has enabled eventing via network.EnableEvents().

type Event struct {
    Type EventType
    Dev  *Device
}

type EventType

EventType represents the different types of events that are supported by the eventing interface.

type EventType int
const (
    Connect EventType = iota
    Disconnect
)

func (EventType) String

func (t EventType) String() string

type Func

Func represents a function that a device performs. F will be nil in any remote device.

type Func struct {
    F      func(...int)
    Params []Param
}

func (Func) String

func (f Func) String() string

String returns the string representation of the function, in the form (param, param, param...)

type Network

Network contains a list of all devices on the network, updated dynamically as devices connect and disconnect.

type Network struct {
    // contains filtered or unexported fields
}

func Bootstrap

func Bootstrap(dev *Device, port int) (*Network, error)

Bootstrap starts networking services and broadcasts device information dev to the rest of the network.

func (Network) CallAll

func (n Network) CallAll(r Room, t Type, name string, p ...int) error

CallAll calls a function on all devices that match the provided room and type.

func (*Network) EnableEvents

func (n *Network) EnableEvents() chan *Event

EnableEvents provides access to the Event channel, allowing a device to detect when a remote device connects or disconnects from the network.

func (Network) GetDevice

func (n Network) GetDevice(name string) (*Device, error)

GetDevice gets a device named name from the network.

func (Network) GetDevices

func (n Network) GetDevices() []*Device

GetDevices returns all known devices from the network.

func (Network) GetMatching

func (n Network) GetMatching(r Room, t Type) []*Device

GetMatching gets all devices with the provide room and type.

type Param

Param represents a parameter to a function, with specific minimum and maximum values.

type Param struct {
    Min int
    Max int
}

func (Param) String

func (p Param) String() string

type Room

Room represents various rooms a device could be placed in.

type Room int
const (
    Living Room = iota
    Dining
    Bed
    Bath
    Kitchen
    Foyer
    Closet
    OtherRoom
)

func RoomFromString

func RoomFromString(s string) (Room, error)

RoomFromString converts a room string (in the same form as one returned from room.String()) into a valid Room. Supports wildcard (*) for use in network.CallAll().

func (Room) String

func (r Room) String() string

type Type

Type represents the various types of devices that can exist on the network.

type Type int
const (
    Light Type = iota
    Outlet
    Speaker
    Screen
    Controller
    OtherType
)

func TypeFromString

func TypeFromString(s1 string) (Type, error)

TypeFromString converts a type string (in the same form as one returned from type.String()) into a valid Type. Supports wildcard (*) for use in network.CallAll().

func (Type) String

func (t Type) String() string

Subdirectories

Name Synopsis
..
examples
proto