devmgmt

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: GPL-3.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// RequestIDSize is size of RequestID
	RequestIDSize = 16
)

Variables

View Source
var ErrDeviceTimeout = errors.New("device timeout")

ErrDeviceTimeout indicates that device had timeout

View Source
var ErrInvalidSignature = errors.New("invalid signature")

ErrInvalidSignature indicates that device sent back invalid signature of payload

Functions

This section is empty.

Types

type Devmgmt

type Devmgmt struct {
	Client paho.Client
	// contains filtered or unexported fields
}

Devmgmt is some abstraction layer over paho mqtt

func New

func New(opts Options) (Devmgmt, error)

New is constructor for MQTT, connects to broker

func (Devmgmt) FetchDeviceState

func (devmgmt Devmgmt) FetchDeviceState(ctx context.Context, device types.Device) (types.DeviceResponse, error)

FetchDeviceState sends rqeuest to device with question about his device state

func (Devmgmt) PublishWithResponse

func (devmgmt Devmgmt) PublishWithResponse(ctx context.Context, body []byte, topic ResponseTopic, pkey ed25519.PublicKey) ([]byte, error)

PublishWithResponse publishes message and waits for response and returns its body

func (Devmgmt) SendActionCommand

func (devmgmt Devmgmt) SendActionCommand(
	ctx context.Context,
	device types.Device,
	command string,
	params map[string]interface{},
) (types.DeviceResponse, error)

SendActionCommand sends action command and returns device response to it

type Options

type Options struct {
	// ClientID, required
	ClientID string

	// Default: "tcp://broker:1883"
	BrokerURL string

	// ServerPublicKey is servers public key
	//
	// *Required*
	ServerPublicKey ed25519.PublicKey

	// ServerPrivateKey is servers private key
	//
	// *Required*
	ServerPrivateKey ed25519.PrivateKey
}

Options of the Devmgmt

func (*Options) Parse

func (opts *Options) Parse()

Parse parses options to the defaults

type ResponseTopic

type ResponseTopic struct {
	Request  string
	Response string
}

ResponseTopic is type of topic which contains Request and Response

Jump to

Keyboard shortcuts

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