chik

package module
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: GPL-3.0 Imports: 18 Imported by: 2

README

Chik

Chik is the sound my child makes when he runs touching everything around the house

Tag Build status Documentation

Framework that allows to create a simple network of remotely connected IOT devices.

The framework allows to compose applications that are instantiating an event loop and a communication bus on top of which a series of handlers operates. Each handler is providing a different functionality to the application.

The framework includes an API to get a TLS encrypted network setup with automatic cert renewal using Smallstep CA APIs (see client and server implementations)

Available handlers are:

  • Actor: allows to execute some actions in reaction to a state change or to a series of conditions
  • Heartbeat: sends a periodic heartbeat to check for network connectivity and server availability
  • IO: allows to communicate with various kind of IO devices and protocols (modbus, GPIO, 1wire and pure software devices)
  • Router: allows to route messages between two devices (handler used in the relay server app)
  • Status: stores a global status comphrensive of every handler state and allows to register remote devices as listener for status changes within the application
  • Datetime: allows to execute an action at a certain date and time or at sunrise/sunset
  • Version: stores the version of the application
  • Telegram: allows to send telegram messages in reaction to a state change
  • Heating: manages zone based heating systems allowing to group small zones together

Ready made applications:

Documentation

Index

Constants

View Source
const BufferSize = 10

BufferSize is the size of channel buffers

View Source
const MaxIdleTime = 2 * time.Minute

MaxIdleTime is the maximum time to wait before closing a connection for inactivity

Variables

View Source
var LoopbackID = uuid.Nil

LoopbackID is the id internal only messages are sent to

Functions

func Equal

func Equal(v1, v2 *Message) bool

Equal compares two messages

func StartRemote added in v1.7.0

func StartRemote(controller *Controller, conn net.Conn, readTimeout time.Duration) (context.Context, context.CancelFunc)

Start starts a new remote and returns a context and a cancel function to stop remote operations. The returned context can also be closed by an error or a timeout in the send/receive routine

Types

type BaseHandler added in v1.5.0

type BaseHandler struct{}

func (*BaseHandler) Dependencies added in v1.5.0

func (s *BaseHandler) Dependencies() []string

func (*BaseHandler) HandleChannelEvent added in v1.6.0

func (s *BaseHandler) HandleChannelEvent(event interface{}, controller *Controller) error

func (*BaseHandler) HandleMessage added in v1.5.0

func (s *BaseHandler) HandleMessage(message *Message, controller *Controller) error

func (*BaseHandler) HandleTimerEvent added in v1.5.0

func (s *BaseHandler) HandleTimerEvent(tick time.Time, controller *Controller) error

func (*BaseHandler) Setup added in v1.5.0

func (s *BaseHandler) Setup(controller *Controller) (Interrupts, error)

func (*BaseHandler) String added in v1.5.0

func (s *BaseHandler) String() string

func (*BaseHandler) Teardown added in v1.5.0

func (s *BaseHandler) Teardown()

func (*BaseHandler) Topics added in v1.5.0

func (s *BaseHandler) Topics() []types.CommandType

type Controller

type Controller struct {
	ID uuid.UUID
	// contains filtered or unexported fields
}

func NewController

func NewController() *Controller

NewController creates a new controller

func (*Controller) Pub

func (c *Controller) Pub(command *types.Command, receiverID uuid.UUID)

Pub publishes a Message composed by the given Command

func (*Controller) PubMessage

func (c *Controller) PubMessage(message *Message, topics ...string)

PubMessage publishes a Message

func (*Controller) Reply

func (c *Controller) Reply(request *Message, replyType types.CommandType, replyContent interface{})

Reply sends back a reply message

func (*Controller) Start

func (c *Controller) Start(ctx context.Context, handlers []Handler)

Start starts every registered handler

func (*Controller) Sub

func (c *Controller) Sub(topics ...string) chan interface{}

Sub Subscribes to one or more message types

func (*Controller) SubOnce

func (c *Controller) SubOnce(topics ...string) chan interface{}

SubOnce subscribes to the first event of one of the given topics, then it deletes the subscription

func (*Controller) Unsub added in v1.7.0

func (c *Controller) Unsub(subscription chan interface{})

type Handler

type Handler interface {
	fmt.Stringer
	Dependencies() []string
	Topics() []types.CommandType
	Setup(controller *Controller) (Interrupts, error)
	HandleMessage(message *Message, controller *Controller) error
	HandleTimerEvent(tick time.Time, controller *Controller) error
	HandleChannelEvent(event interface{}, controller *Controller) error
	Teardown()
}

Handler is the interface that handles network messages and optionally can return a reply

type Interrupts added in v1.6.0

type Interrupts struct {
	Timer Timer
	Event <-chan interface{}
}

type Message

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

func NewMessage

func NewMessage(receiver uuid.UUID, command *types.Command) *Message

NewMessage creates a new message

func ParseMessage

func ParseMessage(reader io.Reader) (*Message, error)

ParseMessage handles incoming data and creates a Message object

func (*Message) Bytes

func (m *Message) Bytes() ([]byte, error)

Bytes returns the binary rapresentation of the message

func (*Message) Command

func (m *Message) Command() *types.Command

Command returns message content as a Command object

func (*Message) ReceiverUUID

func (m *Message) ReceiverUUID() (uuid.UUID, error)

ReceiverUUID returns the receiver identity

func (*Message) SenderUUID

func (m *Message) SenderUUID() uuid.UUID

SenderUUID returns the sender identity

func (Message) String

func (m Message) String() string

type Remote

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

Remote represents a remote endpoint, data are sent via Controller.Pub() and received directly by the interested Handler

type StatusHolder

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

StatusHolder is a struct that stores status of an handler that needs to trigger status changes when something happens

func NewStatusHolder

func NewStatusHolder(moduleName string) *StatusHolder

NewStatusHolder creates a StatusHolder

func (*StatusHolder) Edit

func (s *StatusHolder) Edit(controller *Controller, editFunction func(interface{}) (interface{}, bool))

Edit the current status via editFunction

func (*StatusHolder) Get added in v1.9.0

func (s *StatusHolder) Get() interface{}

func (*StatusHolder) Set

func (s *StatusHolder) Set(status interface{}, controller *Controller)

Set stores the status and emits it if it is changed

type Timer added in v1.4.0

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

func NewEmptyTimer added in v1.4.0

func NewEmptyTimer() Timer

NewEmptyTimer creates a timer that does never fire

func NewStartupActionTimer added in v1.6.0

func NewStartupActionTimer() Timer

NewStartupActionTimer creates a timer that fires only at start and then never triggers again

func NewTimer added in v1.4.0

func NewTimer(interval time.Duration, triggerAtStart bool) Timer

NewTimer creates a new timer given an interval and the option to fire when started

Directories

Path Synopsis
handlers
io
systemd
Code generated by dbus-codegen-go DO NOT EDIT.
Code generated by dbus-codegen-go DO NOT EDIT.

Jump to

Keyboard shortcuts

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