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 ¶
- Variables
- type Config
- type MQTT
- func (c *MQTT) Connect() error
- func (c *MQTT) Disconnect() error
- func (c *MQTT) PublishDownlink(message *types.DownlinkMessage) error
- func (c *MQTT) SubscribeConnect() (<-chan *types.ConnectMessage, error)
- func (c *MQTT) SubscribeDisconnect() (<-chan *types.DisconnectMessage, error)
- func (c *MQTT) SubscribeStatus(gatewayID string) (<-chan *types.StatusMessage, error)
- func (c *MQTT) SubscribeUplink(gatewayID string) (<-chan *types.UplinkMessage, error)
- func (c *MQTT) UnsubscribeConnect() error
- func (c *MQTT) UnsubscribeDisconnect() error
- func (c *MQTT) UnsubscribeStatus(gatewayID string) error
- func (c *MQTT) UnsubscribeUplink(gatewayID string) error
Constants ¶
This section is empty.
Variables ¶
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.
var ( ConnectTopicFormat = "connect" DisconnectTopicFormat = "disconnect" UplinkTopicFormat = "%s/up" DownlinkTopicFormat = "%s/down" StatusTopicFormat = "%s/status" )
Topic formats for connect, disconnect, uplink, downlink and status messages
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 )
var BufferSize = 10
BufferSize indicates the maximum number of MQTT messages that should be buffered
var PublishTimeout = 50 * time.Millisecond
PublishTimeout is the timeout before returning from publish without checking error
Functions ¶
This section is empty.
Types ¶
type MQTT ¶
type MQTT struct {
// contains filtered or unexported fields
}
MQTT side of the bridge
func (*MQTT) PublishDownlink ¶
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 (*MQTT) SubscribeUplink ¶
func (c *MQTT) SubscribeUplink(gatewayID string) (<-chan *types.UplinkMessage, error)
SubscribeUplink handles uplink messages for the given gateway ID
func (*MQTT) UnsubscribeConnect ¶
UnsubscribeConnect unsubscribes from connect messages
func (*MQTT) UnsubscribeDisconnect ¶
UnsubscribeDisconnect unsubscribes from disconnect messages
func (*MQTT) UnsubscribeStatus ¶
UnsubscribeStatus unsubscribes from status messages for the given gateway ID
func (*MQTT) UnsubscribeUplink ¶
UnsubscribeUplink unsubscribes from uplink messages for the given gateway ID