Client IDs & sessions
Every MQTT connection carries a client ID. On ConnectMQ the client ID is tied to your credentials, so it is worth getting right before you roll out many devices.
The rule
Each credential set has an issued Client ID, shown on the MQTT Connection Settings page, for example connectmq_client_594592. A client using those credentials must connect with:
- the issued client ID itself:
connectmq_client_594592, or - the issued client ID, an underscore and any suffix:
connectmq_client_594592_<suffix>.
| Client ID sent | Result |
|---|---|
connectmq_client_594592 | Accepted |
connectmq_client_594592_sensor-01 | Accepted |
connectmq_client_594592_gateway_line1 | Accepted |
sensor-01 | Refused: Client identifier not valid (0x85) |
connectmq_client_59459 | Refused (0x85) |
One credential set, many devices
You do not need a credential set per device. Give each device the same username and password, and a unique suffix: connectmq_client_594592_ + serial number, MAC address or device name. Create extra credential sets with Add credentials when you want to separate device groups or revoke access independently.
Client IDs must be unique
MQTT allows only one connection per client ID. If a second client connects with an ID that is already connected, the broker closes the first connection with Session taken over (0x8E). Two devices that share a client ID keep kicking each other off, which looks like a connection that drops every few seconds.
Make each suffix unique, for example:
connectmq_client_594592_esp32-a4cf12e8b1
connectmq_client_594592_plc-line1
connectmq_client_594592_backend-1ConnectMQ's own tools already follow this rule. The web console connects as <client ID>_web_<random>, ConnectMQ Edge as <client ID>_edge_<random>, the Home Assistant integration as <client ID>_homeassistant and the GitHub Action as <client ID>_gha-<run id>-<random>. None of them disconnect your devices.
Sessions
- Clean start / clean session: when set, the broker discards any previous session for the client ID.
- Persistent sessions: connect with clean start off (MQTT 5: also set a session expiry interval) and the broker keeps the client's subscriptions and queues QoS 1 and 2 messages while it is offline. The maximum session expiry and the number of queued messages depend on your plan, see Plans & broker limits.
- Keep alive: the client pings the broker when it has nothing else to send. 30–60 seconds suits most devices; the broker drops a client that stays silent for 1.5 × the keep-alive.
- Last Will and Testament (LWT): set a will message on connect (for example
{"state":"offline"}on.../status, retained) and the broker publishes it if the device disappears without disconnecting.
Connections count against your plan
Every open connection counts towards your plan's concurrent connections (Free: 5, Basic: 100, Scale: 1,000), including the console tab you have open and tools such as ConnectMQ Edge. Each minute a client stays connected uses one session minute. See Plans & broker limits and the pricing page.