diff --git a/mqtt.go b/mqtt.go index 31e4208..a8b3869 100644 --- a/mqtt.go +++ b/mqtt.go @@ -69,22 +69,9 @@ type Config struct { Retained bool KeepAlive time.Duration MsgChanDept uint + WillMessage PubMessage } -// return &Config{ -// Host: host, -// Port: port, -// Username: username, -// Password: password, -// ClientID: clientId, -// CleanSession: true, -// AutoReconnect: true, -// Retained: false, -// KeepAlive: 15 * time.Second, -// MsgChanDept: 100, -// } -// } - type Client struct { Config Config pahoClient paho.Client @@ -103,6 +90,11 @@ func New(conf Config) *Client { opts.SetAutoReconnect(conf.AutoReconnect) opts.SetKeepAlive(conf.KeepAlive) opts.SetMessageChannelDepth(conf.MsgChanDept) + + if conf.WillMessage != nil { + m := conf.WillMessage + opts.SetBinaryWill(m.Topic(), m.Payload(), m.Qos(), m.Retained()) + } if conf.AutoReconnect { opts.SetResumeSubs(true) }