Documentation ¶
Overview ¶
Package mqtt provides easy-to-use MQTT connection for projects.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Brokers []string // MQTT Broker address. Format: scheme://host:port ClientID string // Client ID Username string // Username to connect the broker(s) Password string // Password to connect the broker(s) Topics []string // Topics for subscription QoS int // QoS Retained bool // Retain Message AutoReconnect bool // Reconnect if connection is lost MaxReconnectInterval time.Duration // Maximum time that will be waited between reconnection attempts PersistentSession bool // Set persistent(clean start for v5) of session KeepAlive uint16 // Keep Alive time in sec TLSCA string // CA file path TLSCert string // Cert file path TLSKey string // Key file path Version Version // MQTT Version of client }
Config contains configurable options for connecting to broker(s).
func (*Config) CreateConnection ¶
CreateConnection will automatically create connection to broker(s) with MQTTConfig parameters.
type ConnectionState ¶
type ConnectionState int
ConnectionState of the Client
const ( // Disconnected : no connection to broker Disconnected ConnectionState = iota // Connected : connection established to broker Connected )
type MQTT ¶
type MQTT interface { // Handle handles new messages to subscribed topics. Handle(handler) // Publish sends a message to broker with a specific topic. Publish(string, interface{}) error // Request sends a message to broker and waits for the response. Request(string, interface{}, time.Duration, handler) error // RequestWith sends a message to broker with specific response topic, // and waits for the response. RequestWith(string, string, interface{}, time.Duration, handler) error // SubscribeResponse creates new subscription for response topic. SubscribeResponse(string) error // Respond sends message to response topic with correlation id (use inside HandleRequest). Respond(string, interface{}, []byte) error // HandleRequest handles imcoming request. HandleRequest(responseHandler) // GetConnectionStatus returns the connection status: Connected or Disconnected GetConnectionStatus() ConnectionState // Disconnect will close the connection to broker. Disconnect() }
MQTT is an interface for mqttv3 and mqttv5 structs.
Click to show internal directories.
Click to hide internal directories.