From 0667010e106bc840db78c3b8d157498d8e116856 Mon Sep 17 00:00:00 2001 From: Jeeva Kandasamy Date: Fri, 27 May 2022 13:39:38 +0530 Subject: [PATCH] fix nil error in subscription Signed-off-by: Jeeva Kandasamy --- plugin/device/mqtt/device.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugin/device/mqtt/device.go b/plugin/device/mqtt/device.go index 09b4c0a..a4a2d4b 100644 --- a/plugin/device/mqtt/device.go +++ b/plugin/device/mqtt/device.go @@ -83,17 +83,14 @@ func NewDevice(ID string, config cmap.CustomMap, rxFunc func(msg *model.Message) tlsConfig := &tls.Config{InsecureSkipVerify: cfg.InsecureSkipVerify} opts.SetTLSConfig(tlsConfig) - c := paho.NewClient(opts) - token := c.Connect() + endpoint.Client = paho.NewClient(opts) + token := endpoint.Client.Connect() for !token.WaitTimeout(3 * time.Second) { } if err := token.Error(); err != nil { return nil, err } - // adding client - endpoint.Client = c - zap.L().Debug("mqtt client connected successfully", zap.Any("adapterName", ID), zap.String("timeTaken", time.Since(start).String()), zap.Any("clientConfig", cfg)) return endpoint, nil } @@ -183,8 +180,10 @@ func (ep *Endpoint) Subscribe(topicsStr string) error { token := ep.Client.Subscribe(topic, 0, ep.getCallBack()) token.WaitTimeout(3 * time.Second) if token.Error() != nil { + zap.L().Error("error on subscription", zap.String("adapterName", ep.ID), zap.String("topic", topic), zap.Error(token.Error())) return token.Error() } + zap.L().Debug("subscribed a topic", zap.String("adapterName", ep.ID), zap.String("topic", topic)) } return nil }