From fb2aef2ce65d605cf0e56c3ab926be01545d2c58 Mon Sep 17 00:00:00 2001 From: Plamen Todorov Date: Sun, 6 Oct 2019 22:08:43 +0300 Subject: [PATCH] MQTT clientId should be unique Each mqtt hook establishes separate connection to the MQTT broker. If their clientIds are all equal the MQTT broker will disconnect the clients - the protocol does not allow 2 connected clients with the same name --- internal/endpoint/mqtt.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/endpoint/mqtt.go b/internal/endpoint/mqtt.go index eea4682f..3bd6431f 100644 --- a/internal/endpoint/mqtt.go +++ b/internal/endpoint/mqtt.go @@ -83,7 +83,9 @@ func (conn *MQTTConn) Send(msg string) error { } ops = ops.SetTLSConfig(&config) } - ops = ops.SetClientID("tile38").AddBroker(uri) + nano := time.Now().UnixNano() + clientID := fmt.Sprintf("tile38_%x", nano) //the id of connected clients should be unique + ops = ops.SetClientID(clientID).AddBroker(uri) c := paho.NewClient(ops) if token := c.Connect(); token.Wait() && token.Error() != nil {