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


#1

1. About skip connection replace

This is a 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”).


How to create_Broker -- Connecting to MyQttHub.com
How to send and receive messages with mosquitto_sub and mosquitto_pub to MyQttHub.com
Using MQTT bootstrap auth to authenticate devices without knowin clientID beforehand
Sonoff "mini" with Tasmota 6.5.0 seems to have a problem with MyQttHub
[feature-request] Replace-indication
Connecting Chrome MQTTlens to MyQttHub
Devices lost connection to MyQttHub
Hubitat MyQTTHub
Publish without Device Registration?