ClearBlade IoT Enterprise and Edge

Troubleshooting MQTT Device Connection Issues

This guide covers common issues when connecting devices to ClearBlade via MQTT, along with diagnostic steps and resolutions derived from real customer cases.

This guide is focused on non-IoT Core devices. For IoT Core connection issues (Standard and Enterprise), see Troubleshooting IoT Core MQTT Device Connection Issues.

Connection Requirements Checklist

Before troubleshooting, verify your device meets all connection requirements:

Requirement

Expected Value

MQTT Broker URL

Customer-specific, assigned during onboarding

Ports

non-TLS ports are disabled by default. Contact ClearBlade support to enable those if needed. See MQTT Ports.

Authentication

Auth token, Asymmetric key (JWT), Basic auth, mTLS, or Shared Access Token. See MQTT Broker Authentication

Client ID

Any unique string. Must be unique per concurrent connection

System Key

Found on your system's Properties page in the ClearBlade console

QoS

0, 1, and 2 are supported

MQTT Version

3.1.1 or 5.0

Role Permissions

User/device must have a role with MQTT topic permissions. See Role topic permissions

MQTT Ports

Port

TLS

Purpose

Credentials

1883

No

MQTT Pub/Sub

User or device token

1884

Yes

MQTT Pub/Sub

User or device token

8903

No

WebSockets

Developer token

8904

Yes

WebSockets

Developer token

8905

No

Auth over MQTT (get token)

System Key, Secret, Client ID

8906

Yes

Auth over MQTT (get token)

System Key, Secret, Client ID

444

Yes

mTLS auth + MQTT via ALPN

Client certificate, System Key


Authentication Methods

ClearBlade IoT Enterprise supports multiple authentication methods. Choose the one that fits your device capabilities.

1. Auth Token (Two-Step Connection)

The most common method. The device first obtains a token, then uses it to connect.

Step 1 -- Get token (port 8905 or 8906):

Field

Value

URL

Your MQTT broker host

Port

8905 (non-TLS) or 8906 (TLS)

Username

System Key

Password

System Secret (deprecated -- some SDKs still require this field; any string can be passed)

Client ID

user_email:password for users, device_name:active_key for devices

Subscribe to the auth MQTT topic to receive a JWT token, or the v/1/auth topic to receive a shorter legacy token (useful for space-constrained devices).

Step 2 -- Connect to broker (port 1883 or 1884):

Field

Value

URL

Your MQTT broker host

Port

1883 (non-TLS) or 1884 (TLS)

Username

Token (from Step 1)

Password

System Key

Client ID

Any unique string

See MQTT Broker Authentication for full details including payload format.

2. Asymmetric Keys (JWT)

Device generates a JWT signed with its private key. Public key must be uploaded to the device record in the ClearBlade console.

JWT Claims:

Claim

Value

Required

iat

Current Unix timestamp (seconds)

Yes

exp

iat + up to 86400 (24 hours max). 10-minute skew allowed

Yes

sk

System Key

Yes

uid

Device ID

Yes

ut

Hard-coded to 3

Yes

MQTT Connect fields:

Field

Value

Username

-unused- (any value)

Password

JWT token with sk, uid, and ut claims

Client ID

Any unique string

Supported Algorithms: RS256 (RSA), ES256 (ECDSA P-256). See Creating key pairs.

Important: The JWT claims here differ from IoT Core. IoT Core uses aud (project ID). Here sk, uid, and ut are used. Using the wrong claims results in CONNACK return code 4.

3. Basic Authentication

Useful for constrained devices that cannot generate JWTs or store tokens.

Field

Value

Username

system_key:device_name

Password

Device active key

Notes:

  • No token is issued -- authentication is performed on every connection

  • Must be explicitly enabled by ClearBlade Support

  • Resource intensive during mass reconnection events due to per-connection authentication

4. mTLS (Mutual TLS)

Devices authenticate using client certificates. ClearBlade handles TLS termination.

  • Device name must match the CN (Common Name) in the client certificate

  • Root CA must be uploaded via the /admin/settings/mtls API endpoint

  • For MQTT over ALPN (port 444), set ALPN protocol to clearblade_mqtt_mtls

  • Username: stringified JSON with device name, e.g. {"name": "myDevice"}

  • Password: System Key

See Mutual TLS - mTLS for full configuration.

5. Shared Access Token Signature

For devices using Azure-style shared access tokens. The token follows the Azure SAS token structure. The resource URI format is broker-domain/devices/system_key/device_name. The shared access key must be uploaded via the /admin/devices/private_keys/SYSTEM_KEY/DEVICE_NAME API endpoint.


Common Issues and Resolutions

1. Authentication Failure (CONNACK Return Code 4)

Symptoms:

  • MQTT CONNACK with return code 0x04 (Bad username or password)

  • Broker rejects connection after CONNECT packet

Possible Causes:

Cause

How to Identify

Resolution

Wrong port for auth step

Connecting to 1883/1884 without a token

Use port 8905/8906 first to obtain a token, then connect to 1883/1884

System Secret used on wrong port

Using System Secret as password on port 1883/1884

System Secret is only used on port 8905/8906. Use the token as username on 1883/1884

Expired token

Connection worked before but now fails

Obtain a new token. Check Device Session Token TTL in system properties

Wrong JWT claims (compared to IoT Core)

Using aud claim instead of sk, uid, ut

Use JWT claims sk (System Key), uid (Device ID), ut (3). See MQTT Broker Authentication

Client ID format wrong on auth port

Client ID not in name:key or email:password format on port 8905/8906

Format Client ID as device_name:active_key for devices or email:password for users

Basic auth not enabled

Using basic auth credentials but feature is not enabled

Contact ClearBlade Support to enable Basic Authentication

Key algorithm mismatch

JWT signed with ES256 but device has RS256 key or vice versa

Ensure JWT alg header matches the key type on the device record

2. Permission Denied on Subscribe or Publish

Symptoms:

  • Device connects successfully but gets disconnected when subscribing or publishing

  • Error: User cannot access resource

  • Messages not being received by subscribers

Possible Causes:

Cause

Resolution

No MQTT topic permission for role

Add the topic to the role's MQTT topic permissions in the Roles section of the console. See Role topic permissions

Wildcard mismatch

Ensure topic permission uses correct wildcards: + for single level, # for multi-level

Device not assigned to a role

Assign the device to a role that has the required topic permissions

Edge vs Platform topic routing

For cross-edge messaging, use the correct relay topic format. See Messaging with the native mqtt library

3. TLS Handshake Failure

Symptoms:

  • TCP RST during or immediately after TLS Client Hello

  • Connection works on non-TLS port (1883) but fails on TLS port (1884)

  • SSL certificate verification errors

Possible Causes:

Cause

How to Identify

Resolution

TLS version too low

PCAP shows TLS 1.0/1.1 in Client Hello

Configure device to use TLS 1.2 or higher

Wrong Root CA

Certificate verification fails after handshake

Use the correct Root CA for your environment. Contact ClearBlade for the appropriate certificate

Non-TLS on TLS port

Connecting to port 1884 without TLS

Either enable TLS or switch to port 1883

TLS on non-TLS port

Connecting to port 1883 with TLS

Either disable TLS or switch to port 1884

Carrier-side Deep Packet Inspection (DPI)

RST on rapid reconnect; different source IP on each retry

Implement exponential backoff. Contact your network provider about DPI heuristics

4. Unexpected Disconnections

Symptoms:

  • Device connects successfully but disconnects after some time

  • Broker log: closing client due to error: read tcp i/o timeout

  • Frequent reconnection cycles

Possible Causes:

Cause

How to Identify

Resolution

Token expired

Connection drops at token expiry time

Obtain a new token before expiration. Check Device Session Token TTL in system properties

JWT exp exceeded

For asymmetric key auth, connection drops at JWT expiry

Generate a new JWT and reconnect before expiration. Max lifetime is 24 hours

Keep-alive timeout

No MQTT PINGREQ sent within the keep-alive interval

Ensure PINGREQs are sent before keep-alive timeout, or increase the timeout

Duplicate client ID

Another client connected with the same client ID

Ensure unique client IDs per concurrent connection. See duplicate client ID behavior below

Network instability

IP address changes between connections; modem resets

Implement reconnection logic with exponential backoff

Server maintenance

All clients disconnect simultaneously

Implement automatic reconnection. Check with ClearBlade Support for maintenance windows

OOM / pod restart

All clients disconnect; correlates with container restart events

Contact ClearBlade Support for pod health investigation

Duplicate Client ID Behavior:

The broker can be configured in one of two ways:

  1. New client connects, existing client is kicked off (MQTT spec-conformant, default)

  2. Existing client is maintained, new client is rejected

This is configured per environment at deployment time and applies to all systems. If two clients repeatedly fight over the same client ID, they will enter a connect/disconnect loop.

5. Non-Acknowledged Messages (QoS 1/2)

Symptoms:

  • Device sends QoS 1 messages but does not receive PUBACK

  • Messages eventually arrive at the backend but with a delay

  • Device retransmits messages due to missing acknowledgment

Possible Causes:

Cause

Resolution

Platform latency

Check with ClearBlade Support for server-side latency during the affected time window

Network congestion

Monitor network path between device and broker. Consider reducing message frequency

Broker overloaded

If many devices are affected simultaneously, contact ClearBlade Support for capacity investigation

6. Persistent Session Messages Not Delivered

Symptoms:

  • Device reconnects after ungraceful disconnect but does not receive stored messages

  • Messages sent while device was offline are lost

Possible Causes:

Cause

Resolution

clean_session set to true

Set clean_session (or clean_start in MQTT 5.0) to false in the MQTT connect options

History Storage not configured

Configure Message History Storage in the ClearBlade console: Messages page, History Storage tab. See Persistent sessions

Subscriptions were QoS 0

Use QoS 1 or 2 for subscriptions that require message storage

Max Rows or Max Time exceeded

Increase the limits in History Storage configuration. Do not set to Infinite or Forever


MQTT Error Code Quick Reference

CONNACK Return Codes (MQTT 3.1.1)

Code

Meaning

Common Cause

0x00

Connection Accepted

--

0x01

Unacceptable Protocol Version

Using MQTT version below 3.1.1

0x02

Client Identifier Rejected

Duplicate client ID (depending on environment configuration)

0x03

Server Unavailable

Server starting up, shutting down, or pod restarting

0x04

Bad Username or Password

Invalid token, wrong System Key, expired credentials, wrong auth method

0x05

Not Authorized

Role does not have required permissions


Diagnostic Steps

Run these from the device or a host on the same network as the device. Replace YOUR-BROKER-HOST with your actual MQTT broker hostname.

1. Verify TLS Connectivity (for TLS ports): Use openssl s_client to connect to YOUR-BROKER-HOST on port 1884 with the -showcerts flag. Expected result: successful TLS handshake showing the certificate chain.

2. Verify DNS Resolution: Use nslookup on YOUR-BROKER-HOST. Expected result: resolves to a valid IP address.

3. Check Port Accessibility: Use nc -zv to test connectivity to YOUR-BROKER-HOST on the relevant port (1883, 1884, 8905, 8906, or 444). Expected result: connection succeeded.

4. Test Auth Token Retrieval: Connect to port 8905/8906 with your System Key, System Secret, and Client ID in the format device_name:active_key. Subscribe to the auth topic. Expected result: receive a token in the auth topic payload.

5. Verify Role Permissions: In the ClearBlade console, check that the device's role has MQTT topic permissions for the topics the device needs to publish/subscribe to.

6. Check System Key and Device Active Key: In the ClearBlade console, verify the System Key on the system Properties page, and the device Active Key on the device Settings page.


Information to Provide When Opening a Support Ticket

To expedite resolution, include:

  1. Environment URL -- your ClearBlade broker hostname

  2. System Key -- found on the system Properties page

  3. Device name(s) -- the specific device(s) having issues

  4. Authentication method -- which auth method is being used (token, JWT, basic, mTLS)

  5. Port -- which port the device is connecting to

  6. Timestamp of failure -- exact date, time, and timezone

  7. Error message or code -- CONNACK code, broker logs, or client error output

  8. PCAP capture (if TLS/network issue) -- capture around the failure event

  9. Device connection code snippet -- the MQTT client configuration

  10. ClearBlade Platform version -- if known (relevant for feature availability)


FAQ

Q: What are the differences compared to IoT Core MQTT authentication?

IoT Core uses a single-step connection: device generates a JWT with aud (project ID) claim and connects directly on port 8883. Multiple auth methods are supported for non-IoT Core devices. These methods typically use a two-step flow: get a token on port 8905/8906, then connect on port 1883/1884. JWT claims also differ: sk, uid, and ut claims are required instead of aud.

Q: My device gets disconnected when it tries to subscribe or publish. Why?

The device's role does not have MQTT topic permissions for the topic it is trying to use. In the ClearBlade console, go to Roles, find the role assigned to the device, and add the required MQTT topic permissions under Message Topics.

Q: Which port should I use?

Use 8905 (non-TLS) or 8906 (TLS) for the initial auth connection to get a token. Then use 1883 (non-TLS) or 1884 (TLS) for the persistent MQTT connection. Use 444 for mTLS with ALPN.

Q: My device is too constrained to generate JWTs. What are my options?

Use Basic Authentication (username = system_key:device_name, password = device active key). Basic auth must be enabled by ClearBlade Support. Alternatively, use the two-step token auth flow and subscribe to the v/1/auth topic to receive a shorter legacy token (under 100 characters).

Q: Can two connections use the same client ID simultaneously?

No. The broker handles conflicting client IDs between an existing connection and a new one based on the environment configuration: either the new client connects and the old one is kicked off (MQTT spec default), or the existing client is maintained and the new one is rejected (optional and not recommended for most environments). This is set per environment at deployment time.

Q: How do I store messages for devices that disconnect unexpectedly?

Configure Message History Storage in the ClearBlade console (Messages page, History Storage tab). Devices must connect with clean_session = false and subscribe with QoS 1 or 2. Set reasonable Max Rows and Max Time limits. See Persistent sessions.

Q: My Python SDK connections are failing. What port and TLS settings should I use?

For the ClearBlade Python SDK, specify both port and use_tls: port 1883 with use_tls=False for non-TLS, or port 1884 with use_tls=True for TLS.

Q: What are the tradeoffs between Basic Authentication and using tokens?

Basic Authentication is simpler to implement -- no two-step connection flow, no token management, and no token expiry handling. It works well for constrained devices that cannot generate JWTs or manage token lifecycles. However, non-token authentication means high CPU and memory usage on every device connection, since the platform must fully authenticate credentials each time. This becomes especially costly during mass reconnection events (e.g., after a server restart or network outage where hundreds of devices reconnect simultaneously). Basic auth must also be explicitly enabled by ClearBlade Support.

Token-based auth (two-step flow) requires more initial setup -- the device must first connect to port 8905/8906 to obtain a token, then reconnect to port 1883/1884 with that token. But the token is reused for the entire session lifetime, so subsequent reconnections within the token's TTL only require step 2 -- a lightweight token validation instead of full authentication. This significantly reduces CPU and memory overhead at scale. Tokens have a configurable TTL (Device Session Token TTL in system properties), so devices must handle token refresh before expiry. Token auth is available by default and does not require special enablement.

Summary: For small fleets or highly constrained devices, Basic Auth is often the simpler choice. For large fleets with frequent reconnections, token-based auth is recommended due to lower per-connection CPU and memory cost.