mqtt

package
v0.0.0-...-aad484d Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: MIT Imports: 13 Imported by: 1

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 paho.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, insecure bool, caCert, clientCert, clientKey string, opts ...Option) (*Client, error)

NewClient creates new Mqtt publisher

func RegisteredClient

func RegisteredClient(log *util.Logger, broker, user, password, clientID string, qos byte, insecure bool, caCert, clientCert, clientKey string, opts ...Option) (*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) Cleanup

func (m *Client) Cleanup(topic string, retained bool) error

Cleanup recursively removes a topic

func (*Client) ConnectionHandler

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

ConnectionHandler restores listeners

func (*Client) ConnectionLostHandler

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

ConnectionLostHandler logs cause of connection loss as warning

func (*Client) Listen

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

Listen attaches listener to slice of listeners for given topic

func (*Client) ListenSetter

func (m *Client) ListenSetter(topic string, callback func(string) error) error

ListenSetter creates a /set listener that resets the payload after handling

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(action, topic string, token paho.Token)

WaitForToken synchronously waits until token operation completed

type Config

type Config struct {
	Broker     string `json:"broker"`
	User       string `json:"user"`
	Password   string `json:"password"`
	ClientID   string `json:"clientID"`
	Insecure   bool   `json:"insecure"`
	CaCert     string `json:"caCert"`
	ClientCert string `json:"clientCert"`
	ClientKey  string `json:"clientKey"`
}

Config is the public configuration

type Option

type Option func(*paho.ClientOptions)

Jump to

Keyboard shortcuts

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