mqtt

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package mqtt provides functionalities to handle the client connection to the broker using MQTT

Package mqtt provides functionalities to handle the client connection to the broker using MQTT

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitClientData added in v1.1.5

func InitClientData()

InitClientData creates an initialized hashmap

func StartMQTTClient

func StartMQTTClient(brokerURL string, clientID string) string

StartMQTTClient is used to initiate the client and set the configuration

Types

type Client

type Client struct {
	ID   string
	Host string
	URL  string
	Port uint
	Qos  byte
	sync.RWMutex
	ClientOptions *MQTT.ClientOptions
	MQTT.Client
}

Client is a wrapper on top of `MQTT.Client`

func CheckifClientExist added in v1.1.5

func CheckifClientExist(clientID string) *Client

CheckifClientExist used to check if the client conn object exist

func NewClient

func NewClient(configs ...Config) (*Client, error)

NewClient returns a configured `Client`. Is mandatory

func (*Client) Connect

func (client *Client) Connect() error

Connect creates a new mqtt client and uses the ClientOptions generated in the NewClient function to connect with the provided host and port.

func (*Client) Disconnect added in v1.1.4

func (client *Client) Disconnect(quiesce uint)

Disconnect disconnects the connection

func (*Client) IsConnected added in v1.1.4

func (client *Client) IsConnected() bool

IsConnected checks if the client is connected or not

func (*Client) Publish added in v1.1.4

func (client *Client) Publish(message Message, topic string) error

Publish is used to publish the client data to the cloud

func (*Client) SetBrokerURL

func (c *Client) SetBrokerURL(protocol string) string

SetBrokerURL returns the broker url for connection

type Config

type Config func(*Client)

Config represents an attribute config setter for the `Client`.

func SetClientID

func SetClientID(id string) Config

SetClientID sets the mqtt client id.

func SetHost

func SetHost(host string) Config

SetHost sets the host where to connect.

func SetPort

func SetPort(port uint) Config

SetPort sets the port where to connect.

type Message

type Message struct {
	AppID   string
	Payload string
}

Message is used to wrap the app id and payload into one and publish to broker

Jump to

Keyboard shortcuts

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