agent

package
v0.0.0-...-c82b7d9 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Topic   string
	Payload string
	QoS     byte
	Retain  bool
}

type Agent

type Agent interface {
	Connect() bool
	Subscribe() bool
	Listen()
	Disconnect()

	HandleMessage(topic string, payload []byte)

	SetParameterFromString(name string, value string)
	SetParameter(name string, param Parameter)
	GetParameterValue(parameter string) interface{}
	TriggerParameterUpdate(parameter string, value string)
	EvalExpressionsInString(in string, functions map[string]govaluate.ExpressionFunction) string

	AddParameterSubscription(topic string, parameter string)
	RemoveParameterSubscription(topic string, parameter string)

	AddRuleFromString(ruleset string, rule string, value string)
	AddRule(ruleset string, rule string, r Rule)
	GetRule(ruleset string, rule string) *Rule
	AddRuleSubscription(topic string, ruleset string, rule string)
	RemoveRuleSubscription(topic string, ruleset string, rule string)

	ExecuteRule(ruleset string, rule string, triggerPayload string)
	Publish(topic string, qos byte, retained bool, payload string)
	IsSubscribed(topic string) bool
	InjectConfigFile(c ConfigFile)
}

Agent implements the main rules agent

func New

func New(mqttClient MqttClient, prefix string) Agent

Creates and initializes a new MQTT rules client

type Config

type Config struct {
	Broker             string
	ClientID           string
	Username           string
	Password           string
	Prefix             string
	DisableRulesUpdate bool
	Loglevel           string
}

type ConfigFile

type ConfigFile struct {
	Config     Config
	Parameters map[string]Parameter
	Rules      map[string]map[string]Rule
}

func ConfigFromFile

func ConfigFromFile(path string) (configFile *ConfigFile, e error)

type MessageHandler

type MessageHandler func(topic string, payload string)

type MqttClient

type MqttClient interface {
	IsConnected() bool
	Connect() bool
	Disconnect()
	SetSubscriptionCallback(callback func(string, string))
	Publish(topic string, qos byte, retained bool, payload interface{}) bool
	Subscribe(topic string, qos byte) bool
	Unsubscribe(topics ...string) bool
}

MqttClient provides the interface to a MQTT Client implementation. This interface is provided to enable tests with a mock client

type PahoClient

type PahoClient interface {
	IsConnected() bool
	Connect() bool
	Disconnect()
	SetSubscriptionCallback(callback func(string, string))
	Publish(topic string, qos byte, retained bool, payload interface{}) bool
	Subscribe(topic string, qos byte) bool
	Unsubscribe(topics ...string) bool
}

func NewPahoClient

func NewPahoClient(o *mqtt.ClientOptions) PahoClient

type Parameter

type Parameter struct {
	Value      interface{}
	Topic      string
	Expression string
}

Parameter used in MQTT rules; can be updated from incoming MQTT messages

type Rule

type Rule struct {
	Trigger   string
	Schedule  string
	Condition string
	Actions   []Action
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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