catbus

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2020 License: MIT Imports: 7 Imported by: 0

README

Catbus client library for Go

Catbus is a home automation platform built on MQTT. This library wraps Paho MQTT for convenience, and some behavior additions.

Rebroadcast on connect

To announce that a non-observing actuator exists, the actuator will need to broadcast an initial value on connect. It does so using either a default value, or the last seen value put onto the bus, and will publish it after some delay after connecting.

Documentation

Overview

Package catbus is a convenience wrapper around MQTT for use with Catbus.

Index

Constants

View Source
const (
	Retain     = Retention(true)
	DontRetain = Retention(false)
)
View Source
const (
	DefaultOnconnectDelay  = 1 * time.Minute
	DefaultOnconnectJitter = 15 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Connect() error
	Subscribe(topic string, f MessageHandler) error
	Publish(topic string, retention Retention, payload string) error
}

func NewClient

func NewClient(brokerURI string, options ClientOptions) Client

type ClientOptions

type ClientOptions struct {
	DisconnectHandler func(Client, error)
	ConnectHandler    func(Client)

	// SubscribeEveryMessage determines if the Subscribe callback will be called for all incoming messages.
	// When SubscribeEveryMessage is false, the Subscribe callback will only trigger when the value changes.
	SubscribeEveryMessage bool

	// Publish previously seen or default values on connecting after OnconnectDelay ± [0,OnconnectJitter).
	OnconnectDelay  time.Duration
	OnconnectJitter time.Duration

	// DefaultPayloadByTopic are optional values to publish on connect if no prior values are seen.
	// E.g. unless we've been told otherwise, assume a device is off.
	DefaultPayloadByTopic map[string]string
}

type Message

type Message struct {
	Payload   string
	Retention Retention
	Topic     string
}

type MessageHandler

type MessageHandler func(Client, Message)

type Retention

type Retention bool

Retention is whether or not the MQTT broker should retain the message.

Jump to

Keyboard shortcuts

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