buttonoff

package module
v0.0.0-...-8f9c55d Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2018 License: MIT Imports: 15 Imported by: 0

README

button: on,off - Button Press Packet Sniffing Daemon

This project aims to support the sniffing and publishing of detected press events to an MQTT broker.

Building

go get github.com/jahkeup/buttonoff/cmd/buttonoffd

Using

With configuration provided:

buttonoffd -interface eth0 -broker mqtt.example.com:1883 -config ./buttonoff.toml

Configuration can be generated with:

# Write a simple defualt config to ./generated-config.toml
buttonffd -write-default -config ./generated-config.toml

Some flags can be overriden in the configuration file. See the generated file for some examples.

The [general] section can specify dropunconfigured = true to drop sniffed events instead of publishing to the mqtt broker - the default is to publish all events to the broker.

Documentation

Index

Constants

View Source
const (
	DefaultDashButtonTopicTemplate          = "/buttonoff/{{.ButtonID}}/pressed"
	DefaultDashButtonPostPressSupressPeriod = time.Millisecond * 600
)

Variables

View Source
var (
	MQTTPublishTimeoutErr = errors.Errorf("MQTT Publish timeout after %s", mqttPublishTimeout)
	MQTTConnectTimeoutErr = errors.Errorf("MQTT Connect timeout after %s", mqttConnectTimeout)
	MQTTDisconnectedErr   = errors.New("Disconnected from MQTT Broker")
)

Functions

func NewPressRateLimiter

func NewPressRateLimiter(period time.Duration) *pressRateLimiter

func SetLogLevel

func SetLogLevel(lvl logrus.Level)

Types

type Accepter

type Accepter interface {
	Accept(key string) bool
}

type ButtonConfig

type ButtonConfig struct {
	ButtonID string
	HWAddr   string
}

type Config

type Config struct {
	General  GeneralConfig
	Listener ListenerConfig
	MQTT     MQTTConfig
	Buttons  []ButtonConfig
}

type DashButtonEventHandler

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

func NewDashButtonEventHandler

func NewDashButtonEventHandler(general GeneralConfig, buttons []ButtonConfig, publisher Publisher) (*DashButtonEventHandler, error)

func (*DashButtonEventHandler) HandleEvent

func (d *DashButtonEventHandler) HandleEvent(e Event) error

type Event

type Event struct {
	HWAddr    string
	Timestamp time.Time
}

type EventHandler

type EventHandler interface {
	HandleEvent(e Event) error
}

type GeneralConfig

type GeneralConfig struct {
	TopicTemplate          string
	DropUnconfigured       bool
	PostPressSupressPeriod time.Duration
}

type Listener

type Listener interface {
	UseEventHandler(eh EventHandler) error
}

type ListenerConfig

type ListenerConfig struct {
	Interface string
}

type MQTTConfig

type MQTTConfig struct {
	BrokerAddr string
	Username   string
	Password   string
}

type MQTTPublisher

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

func NewMQTTPublisher

func NewMQTTPublisher(conf MQTTConfig) (*MQTTPublisher, error)

func (*MQTTPublisher) Close

func (mp *MQTTPublisher) Close() error

func (*MQTTPublisher) Publish

func (mp *MQTTPublisher) Publish(msg Message) error

func (*MQTTPublisher) Run

func (mp *MQTTPublisher) Run(ctx context.Context) error

type Message

type Message struct {
	Topic   string
	Payload []byte
}

type PCAPListener

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

func NewPCAPListener

func NewPCAPListener(conf ListenerConfig) (*PCAPListener, error)

func (*PCAPListener) Run

func (pl *PCAPListener) Run(ctx context.Context) error

func (*PCAPListener) UseEventHandler

func (pl *PCAPListener) UseEventHandler(eh EventHandler) error

type Publisher

type Publisher interface {
	Publish(msg Message) error
	Close() error
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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