mqtt

package
v0.0.0-...-a90edd0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2019 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Broker             string // Broker URL to connect
	User               string // Broker User name for authentication
	Password           string // Broker password for authentication
	ClientId           string // Client ID
	CleanSession       bool   // Clear session at Broker on connect, default false
	Qos                int    // Quality of Service, (i.e, 0: QOS0, 1 QOS1, 2 QOS2)
	DisconnectInterval uint   // Client will disconnect after wait of this period, default 0

	MessageArrived Receiver // Subscribe receiver handler for this client object
	// contains filtered or unexported fields
}

Client struct contains MQTT client configuration and handle of client connection for further access of publish and subscriptions. There is not any restriction on number of client instances. User can define multiple instances for same broker or different brokers in single application.

func (*Client) Alive

func (client *Client) Alive() bool

Alive returns true if client is connected to broker. It returns true even if client is in reconnecting state.

This can be used to check whether client is connected to broker or not regardless of various MQTT connection stages.

func (*Client) Connect

func (client *Client) Connect() (err error)

Connect initiates MQTT Connect sequence as per MQTT protocol. On receiving CONN ACK from broker, it changes state to connected. On failure returns error.

func (*Client) Connected

func (client *Client) Connected() bool

Connected returns true if client is connected to broker actively. It returns false if client is in reconnect or disconnected mode

This can be used to get absolute connection state to broker.

func (*Client) Disconnect

func (client *Client) Disconnect()

Disconnect drops connection to MQTT broker.

func (*Client) Init

func (client *Client) Init() (err error)

Init is an initialization function for defined Client object. Each client object has Init function which must be called before accessing any other member functions of struct Client.

func (*Client) Publish

func (client *Client) Publish(topic string, qos byte, retain bool, payload interface{}) (err error)

Publish sends given message to specific topic on MQTT broker.

func (*Client) Subscribe

func (client *Client) Subscribe(topic string, qos byte) (err error)

Subscribe performs subscription on MQTT broker for specific topic with QOS Client library will call message handler on reception of any message on subscribed topic.

func (*Client) Unsubscribe

func (client *Client) Unsubscribe(topic string)

Unsubscribe is used to remove subscription of specific topic from MQTT broker. After this operation, client will not receive any message published on unsubscribed topic.

type Receiver

type Receiver func(*Client, string, []byte)

Receiver type allows user to receive subscribed messages in application layer. User can define multiple handles of Receiver for various subscriptions.

Jump to

Keyboard shortcuts

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