mqtt

package
v2.3.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2018 License: MIT Imports: 12 Imported by: 4

Documentation

Overview

Package mqtt connects to an MQTT broker in order to communicate with a gateway.

Connection/Disconnection of gateways is done by publishing messages to the "connect" and "disconnect" topics. When a gateway connects, it (or a plugin of the MQTT broker) should publish a protocol buffer of the type types.ConnectMessage containing the gateway's ID and either a key or a token to the "connect" topic.

The gateway (or the plugin) can also set a will with the MQTT broker for when it disconnects. This will should be a protocol buffer of the type types.DisconnectMessage containing the gateway's ID on the "disconnect" topic.

Uplink messages are sent as protocol buffers on the "[gateway-id]/up" topic. The bridge should call `SubscribeUplink("gateway-id")` to subscribe to this topic. It is also possible to subscribe to a wildcard gateway by passing "+".

Downlink messages are sent as protocol buffers on the "[gateway-id]/down" topic. The bridge should call `PublishDownlink(*types.DownlinkMessage)` in order to send the downlink to the gateway.

Gateway status messages are sent as protocol buffers on the "[gateway-id]/status" topic. The bridge should call `SubscribeStatus("gateway-id")` to subscribe to this topic. It is also possible to subscribe to a wildcard gateway by passing "+".

Index

Constants

This section is empty.

Variables

View Source
var (
	PublishQoS   byte = 0x00
	SubscribeQoS byte = 0x00
)

QoS indicates the MQTT Quality of Service level. 0: The broker/client will deliver the message once, with no confirmation. 1: The broker/client will deliver the message at least once, with confirmation required. 2: The broker/client will deliver the message exactly once by using a four step handshake.

View Source
var (
	ConnectTopicFormat    = "connect"
	DisconnectTopicFormat = "disconnect"
	UplinkTopicFormat     = "%s/up"
	DownlinkTopicFormat   = "%s/down"
	StatusTopicFormat     = "%s/status"
)

Topic formats for connect, disconnect, uplink, downlink and status messages

View Source
var (
	// ConnectRetries says how many times the client should retry a failed connection
	ConnectRetries = 10
	// ConnectRetryDelay says how long the client should wait between retries
	ConnectRetryDelay = time.Second
)
View Source
var BufferSize = 10

BufferSize indicates the maximum number of MQTT messages that should be buffered

View Source
var PublishTimeout = 50 * time.Millisecond

PublishTimeout is the timeout before returning from publish without checking error

Functions

This section is empty.

Types

type Config

type Config struct {
	Brokers   []string
	Username  string
	Password  string
	TLSConfig *tls.Config
}

Config contains configuration for MQTT

type MQTT

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

MQTT side of the bridge

func New

func New(config Config, ctx log.Interface) (*MQTT, error)

New returns a new MQTT

func (*MQTT) Connect

func (c *MQTT) Connect() error

Connect to MQTT

func (*MQTT) Disconnect

func (c *MQTT) Disconnect() error

Disconnect from MQTT

func (c *MQTT) PublishDownlink(message *types.DownlinkMessage) error

PublishDownlink publishes a downlink message

func (*MQTT) SubscribeConnect

func (c *MQTT) SubscribeConnect() (<-chan *types.ConnectMessage, error)

SubscribeConnect subscribes to connect messages

func (*MQTT) SubscribeDisconnect

func (c *MQTT) SubscribeDisconnect() (<-chan *types.DisconnectMessage, error)

SubscribeDisconnect subscribes to disconnect messages

func (*MQTT) SubscribeStatus

func (c *MQTT) SubscribeStatus(gatewayID string) (<-chan *types.StatusMessage, error)

SubscribeStatus handles status messages for the given gateway ID

func (c *MQTT) SubscribeUplink(gatewayID string) (<-chan *types.UplinkMessage, error)

SubscribeUplink handles uplink messages for the given gateway ID

func (*MQTT) UnsubscribeConnect

func (c *MQTT) UnsubscribeConnect() error

UnsubscribeConnect unsubscribes from connect messages

func (*MQTT) UnsubscribeDisconnect

func (c *MQTT) UnsubscribeDisconnect() error

UnsubscribeDisconnect unsubscribes from disconnect messages

func (*MQTT) UnsubscribeStatus

func (c *MQTT) UnsubscribeStatus(gatewayID string) error

UnsubscribeStatus unsubscribes from status messages for the given gateway ID

func (c *MQTT) UnsubscribeUplink(gatewayID string) error

UnsubscribeUplink unsubscribes from uplink messages for the given gateway ID

Jump to

Keyboard shortcuts

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