devices

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TLS_PORT = 8883 // secure TLS port
	TCP_PORT = 1883 // not secure port

)

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device interface {
	// Connect connects Device object to HC gateway
	Connect() error
	// Disconnect disconnects Device from HC gateway
	Disconnect()
	// AddEndpoint adds new endpoint to MQTT Device
	AddEndpoint(enp endpoints.Endpoint)
	// GetEndpoint returns endpoint with given ID
	GetEndpoint(uid string) endpoints.Endpoint
	// RegisterOnConnectCb registers handler that is invoked when the connection is established
	RegisterOnConnectCb(cb func())
	// RegisterOnConnectionLostCb registers handler that is invoked when connection is lost
	RegisterOnConnectionLostCb(cb func(err error))
}

Device interface that collects methods needed to connect MQTT device to HC Gateway

func NewMqttDevice

func NewMqttDevice(
	hostname string,
	uid string,
	username string,
	password string,
	isSecure bool,
	deviceName string,
) (Device, error)

NewMqttDevice constructs Mqtt device

type MqttDevice

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

MqttDevice struct that defines all method needed to connect and communicate with HC GW

func (*MqttDevice) AddEndpoint

func (obj *MqttDevice) AddEndpoint(enp endpoints.Endpoint)

AddEndpoint adds new endpoint to MQTT Device

func (*MqttDevice) Connect

func (obj *MqttDevice) Connect() error

Connect connects Device object to HC gateway

func (*MqttDevice) Disconnect

func (obj *MqttDevice) Disconnect()

Disconnect disconnects Device from HC gateway

func (*MqttDevice) GetEndpoint

func (obj *MqttDevice) GetEndpoint(uid string) endpoints.Endpoint

func (*MqttDevice) RegisterOnConnectCb

func (obj *MqttDevice) RegisterOnConnectCb(cb func())

RegisterOnConnectCb registers external handler that is invoked when mqtt device is connected

func (*MqttDevice) RegisterOnConnectionLostCb

func (obj *MqttDevice) RegisterOnConnectionLostCb(cb func(err error))

RegisterOnConnectionLostCb register external handler that is invoked when connection is lost

func (*MqttDevice) SendConfigs

func (obj *MqttDevice) SendConfigs()

SendConfigs sends config for each endpoint

Jump to

Keyboard shortcuts

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