Documentation
¶
Overview ¶
Package mqtt is a minimal MQTT 3.1.1 client: enough to feed motion and status into mosquitto / Home Assistant / Frigate, and to hear another tool's motion (Subscribe), without pulling in a full client library. A Client publishes QoS 0 or QoS 1, reconnects on the next Publish after any error, and uses keep-alive 0 so an idle connection is never dropped by the broker; Subscribe keeps its own connection alive with pings.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Subscribe ¶ added in v0.2.3
func Subscribe(ctx context.Context, o SubscribeOptions, topics []string, fn func(topic string, payload []byte))
Subscribe listens on topics (QoS 0 and 1) and calls fn with each message until ctx ends, reconnecting and subscribing again whenever the connection drops. fn runs on the reading goroutine, so it should not block for long.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client publishes to a single broker. It is safe for concurrent use; each Publish is serialised. A dropped connection is re-established on the next Publish, so a broker restart heals itself.
func New ¶
New returns a client for broker addr ("host:port"). clientID must be unique on the broker; user and pass may be empty for an anonymous broker.
type SubscribeOptions ¶ added in v0.2.3
type SubscribeOptions struct {
Addr string
ClientID string
User string
Pass string
// Retry is the pause before reconnecting after the connection ends,
// 5 s when zero.
Retry time.Duration
// OnError, when set, hears why each connection ended.
OnError func(error)
}
SubscribeOptions is the broker and login for Subscribe.