Skip to content

Commit 0667010

Browse files
committed
fix nil error in subscription
Signed-off-by: Jeeva Kandasamy <jkandasa@gmail.com>
1 parent 42c11a7 commit 0667010

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

plugin/device/mqtt/device.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,14 @@ func NewDevice(ID string, config cmap.CustomMap, rxFunc func(msg *model.Message)
8383
tlsConfig := &tls.Config{InsecureSkipVerify: cfg.InsecureSkipVerify}
8484
opts.SetTLSConfig(tlsConfig)
8585

86-
c := paho.NewClient(opts)
87-
token := c.Connect()
86+
endpoint.Client = paho.NewClient(opts)
87+
token := endpoint.Client.Connect()
8888
for !token.WaitTimeout(3 * time.Second) {
8989
}
9090
if err := token.Error(); err != nil {
9191
return nil, err
9292
}
9393

94-
// adding client
95-
endpoint.Client = c
96-
9794
zap.L().Debug("mqtt client connected successfully", zap.Any("adapterName", ID), zap.String("timeTaken", time.Since(start).String()), zap.Any("clientConfig", cfg))
9895
return endpoint, nil
9996
}
@@ -183,8 +180,10 @@ func (ep *Endpoint) Subscribe(topicsStr string) error {
183180
token := ep.Client.Subscribe(topic, 0, ep.getCallBack())
184181
token.WaitTimeout(3 * time.Second)
185182
if token.Error() != nil {
183+
zap.L().Error("error on subscription", zap.String("adapterName", ep.ID), zap.String("topic", topic), zap.Error(token.Error()))
186184
return token.Error()
187185
}
186+
zap.L().Debug("subscribed a topic", zap.String("adapterName", ep.ID), zap.String("topic", topic))
188187
}
189188
return nil
190189
}

0 commit comments

Comments
 (0)