mqtt

package
v0.0.0-...-e6e1b3f Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientID

func ClientID() string

ClientID created unique mqtt client id

Types

type Client

type Client struct {
	Client mqtt.Client

	Qos byte
	// contains filtered or unexported fields
}

Client encapsulates mqtt publish/subscribe functions

var Instance *Client

Instance is the paho Mqtt client singleton

func NewClient

func NewClient(log *util.Logger, broker, user, password, clientID string, qos byte) (*Client, error)

NewClient creates new Mqtt publisher

func RegisteredClient

func RegisteredClient(log *util.Logger, broker, user, password, clientID string, qos byte) (*Client, error)

RegisteredClient reuses an registered Mqtt publisher or creates a new one

func RegisteredClientOrDefault

func RegisteredClientOrDefault(log *util.Logger, cc Config) (*Client, error)

RegisteredClientOrDefault reuses an registered Mqtt publisher or creates a new one. If no publisher is configured, it uses the default instance.

func (*Client) ConnectionHandler

func (m *Client) ConnectionHandler(client mqtt.Client)

ConnectionHandler restores listeners

func (*Client) ConnectionLostHandler

func (m *Client) ConnectionLostHandler(client mqtt.Client, reason error)

ConnectionLostHandler logs cause of connection loss as warning

func (*Client) Listen

func (m *Client) Listen(topic string, callback func(string))

Listen validates uniqueness and registers and attaches listener

func (*Client) Publish

func (m *Client) Publish(topic string, retained bool, payload interface{}) error

Publish synchronously publishes payload using client qos

func (*Client) WaitForToken

func (m *Client) WaitForToken(token mqtt.Token)

WaitForToken synchronously waits until token operation completed

type Config

type Config struct {
	Broker   string
	User     string
	Password string
}

Config is the public configuration

Jump to

Keyboard shortcuts

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