Connecting several devices with same credentials (how to avoid MQTT connection replace, connection replacement)


#1

1. About skip connection replace

This is very good question because it touches a particular MQTT behavior related to connection replace when connecting for second time using same credentials.

http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html

This is useful to protect devices from been blocked by stalled connections due to NAT problems.

However, as you have noticed, it creates problems in environments where the same clientId+userName is used to connect (and subscribe) and to PUBLISH.

It also creates problems with integrations where same user/credentials are used to publish several messages at the same time in a concurrent manner. For example, a web page triggering PUBLISH by every visit. It is likely several visits can happen at the same time.

As you can see it has pros and cons. Now, to solve the issue you can:

  1. Use different users to publish and subscribe, paying attention not to reuse them (only one time per credential).

  2. Or, disable “Connection replace” so you can connect several times without closing previous connection.

2. How to avoid connection replace: enable skip connection replace

  1. If you opt for second option, here is how. Go and click on the device where you want to skip connection replace:

  2. After clicking and enabling “skip connection replace”, save device options.

3. Some notes about disabling connection replace

  1. It is not standard :slight_smile:

  2. Every device connected with these credentials will receive a virtual temporal clientId with cleanSession enforced to true (subscriptions will be lost for example, so you have to resend them).

  3. Devices connected with skip connection replace on will have no support for unconfirmed messages storage ( see “showing and cleaning unconfirmed messages”).


Publish without Device Registration?
Publish without Device Registration?