mqtt

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: Apache-2.0 Imports: 10 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

View Source
var (

	//URLData stores the urls mapped to app id
	URLData map[string][]string //to store the appids maped to urls
	//MQTTClient stores the Client object mapped to urls
	MQTTClient map[string]*Client //to store Homeedge client object for every url

)

Functions

func GetPublishedData added in v1.1.13

func GetPublishedData(topic string, clientID string, host string) string

GetPublishedData is used to get the data for topic subscribed

func InitMQTTData added in v1.1.11

func InitMQTTData()

InitMQTTData creates an initialized hashmap

func NewTLSConfig added in v1.1.7

func NewTLSConfig(certsPath string) (*tls.Config, error)

NewTLSConfig creates a tls config for mqtt client

func StartMQTTClient

func StartMQTTClient(brokerURL string, appID string, mqttPort uint) 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
	// contains filtered or unexported fields
}

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

func CheckifClientExist added in v1.1.5

func CheckifClientExist(url 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 string, topic string) error

Publish is used to publish the client data to the cloud

func (*Client) SetBrokerURL

func (c *Client) SetBrokerURL() string

SetBrokerURL returns the broker url for connection

func (*Client) Subscribe added in v1.1.9

func (client *Client) Subscribe(topic string, appID string) error

Subscribe is used to subscribe to a topic

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 Key added in v1.1.12

type Key struct {
	// contains filtered or unexported fields
}

Key is composite key for storing topic with url

Jump to

Keyboard shortcuts

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