uiot

package module
v0.0.0-...-64a008b Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: GPL-3.0 Imports: 14 Imported by: 0

README

u-iot

u-iot

The Go gopher was designed by Renee French. The design is licensed under the Creative Commons 3.0 Attributions license. Read this article for more details.

A framework and protocol for building your own smart home devices and applications. Intended to provide complete freedom in device functionality, u-iot supportS applications on host operating systems, as well as embedded devices with user-defined functions and parameters on Raspberry Pi.

u-iot is written in Go, with more languages coming in the future.

Installation

Golang

If you are using modules:

import uiot github.com/TrevorFarrelly/u-iot

then build when you are ready.

Or, if you are using dep:

import uiot github.com/TrevorFarrelly/u-iot
$ dep ensure
Python

TBD

Reference

GoDoc-style documentation can be found at TrevorFarrelly.github.io/u-iot/.

Using Raspberry Pi GPIO

A Golang wrapper of WiringPi can be found here.

I have also forked this repo and hacked in PWM support, see here.

More info on Pi installation can be found in examples

Progress

u-iot's Golang library is usable and firmly within the realm of a "minimum viable product." That said, there is lots of functionality I plan on implementing in the future. See the checklist below for progress on these features.

Golang Feature Breaking? Completion Python Feature Breaking? Completion
Device Creation No Device Creation No
Basic Device Tags No Basic Device Tags No
Multicasting No Multicasting No
RPC server No RPC Server No
Bootstrapping No Bootstrapping No
v0.1 Function Calls No Function Calls No
Return Values No Return Values No
More arg types Yes More arg types Yes
User Device Tags Maybe User Device Tags Maybe
Security Maybe Security Maybe

Anyone is welcome to work on these features. Please check out CONTRIBUTING.md if you are interested.

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

type Device

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

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

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

type Event struct {
	Type EventType
	Dev  *Device
}

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 EventType

type EventType int

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

const (
	Connect EventType = iota
	Disconnect
)

func (EventType) String

func (t EventType) String() string

type Func

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

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

func (Func) String

func (f Func) String() string

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

type Network

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

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

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

type Param struct {
	Min int
	Max int
}

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

func (Param) String

func (p Param) String() string

type Room

type Room int

Room represents various rooms a device could be placed in.

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 Type int

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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