commit
631e1d1d9a
|
@ -26,6 +26,7 @@ type Adaptor struct {
|
||||||
clientCert string
|
clientCert string
|
||||||
clientKey string
|
clientKey string
|
||||||
autoReconnect bool
|
autoReconnect bool
|
||||||
|
cleanSession bool
|
||||||
client paho.Client
|
client paho.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ func NewAdaptor(host string, clientID string) *Adaptor {
|
||||||
name: gobot.DefaultName("MQTT"),
|
name: gobot.DefaultName("MQTT"),
|
||||||
Host: host,
|
Host: host,
|
||||||
autoReconnect: false,
|
autoReconnect: false,
|
||||||
|
cleanSession: true,
|
||||||
useSSL: false,
|
useSSL: false,
|
||||||
clientID: clientID,
|
clientID: clientID,
|
||||||
}
|
}
|
||||||
|
@ -46,6 +48,7 @@ func NewAdaptorWithAuth(host, clientID, username, password string) *Adaptor {
|
||||||
name: "MQTT",
|
name: "MQTT",
|
||||||
Host: host,
|
Host: host,
|
||||||
autoReconnect: false,
|
autoReconnect: false,
|
||||||
|
cleanSession: true,
|
||||||
useSSL: false,
|
useSSL: false,
|
||||||
clientID: clientID,
|
clientID: clientID,
|
||||||
username: username,
|
username: username,
|
||||||
|
@ -68,6 +71,12 @@ func (a *Adaptor) AutoReconnect() bool { return a.autoReconnect }
|
||||||
// SetAutoReconnect sets the MQTT AutoReconnect setting
|
// SetAutoReconnect sets the MQTT AutoReconnect setting
|
||||||
func (a *Adaptor) SetAutoReconnect(val bool) { a.autoReconnect = val }
|
func (a *Adaptor) SetAutoReconnect(val bool) { a.autoReconnect = val }
|
||||||
|
|
||||||
|
// CleanSession returns the MQTT CleanSession setting
|
||||||
|
func (a *Adaptor) CleanSession() bool { return a.cleanSession }
|
||||||
|
|
||||||
|
// SetCleanSession sets the MQTT CleanSession setting. Should be false if reconnect is enabled. Otherwise all subscriptions will be lost
|
||||||
|
func (a *Adaptor) SetCleanSession(val bool) { a.cleanSession = val }
|
||||||
|
|
||||||
// UseSSL returns the MQTT server SSL preference
|
// UseSSL returns the MQTT server SSL preference
|
||||||
func (a *Adaptor) UseSSL() bool { return a.useSSL }
|
func (a *Adaptor) UseSSL() bool { return a.useSSL }
|
||||||
|
|
||||||
|
@ -145,6 +154,7 @@ func (a *Adaptor) createClientOptions() *paho.ClientOptions {
|
||||||
opts.SetUsername(a.username)
|
opts.SetUsername(a.username)
|
||||||
}
|
}
|
||||||
opts.AutoReconnect = a.autoReconnect
|
opts.AutoReconnect = a.autoReconnect
|
||||||
|
opts.CleanSession = a.cleanSession
|
||||||
|
|
||||||
if a.UseSSL() {
|
if a.UseSSL() {
|
||||||
opts.SetTLSConfig(a.newTLSConfig())
|
opts.SetTLSConfig(a.newTLSConfig())
|
||||||
|
|
|
@ -36,6 +36,13 @@ func TestMqttAdaptorAutoReconnect(t *testing.T) {
|
||||||
gobottest.Assert(t, a.AutoReconnect(), true)
|
gobottest.Assert(t, a.AutoReconnect(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMqttAdaptorCleanSession(t *testing.T) {
|
||||||
|
a := initTestMqttAdaptor()
|
||||||
|
gobottest.Assert(t, a.CleanSession(), true)
|
||||||
|
a.SetCleanSession(false)
|
||||||
|
gobottest.Assert(t, a.CleanSession(), false)
|
||||||
|
}
|
||||||
|
|
||||||
func TestMqttAdaptorUseSSL(t *testing.T) {
|
func TestMqttAdaptorUseSSL(t *testing.T) {
|
||||||
a := initTestMqttAdaptor()
|
a := initTestMqttAdaptor()
|
||||||
gobottest.Assert(t, a.UseSSL(), false)
|
gobottest.Assert(t, a.UseSSL(), false)
|
||||||
|
|
Loading…
Reference in New Issue