JWT token expiry leads to device disconnects in device-shadow implementation

We’re implementing device shadows for our IoT fleet using ThingWorx 9.5 and the Java Device SDK. Devices are authenticating with JWT tokens, but we’re seeing periodic disconnects when the tokens expire after the configured lifetime.

The JWT token lifecycle seems to be the issue - devices lose connection and don’t automatically reconnect. We’re losing critical telemetry data during these disconnect periods, and devices require manual restart to re-establish connection.

Current token configuration:

ClientConfigurator config = new ClientConfigurator();
config.setAppKey(jwtToken); // 2-hour expiry
config.ignoreSSLErrors(false);

I’ve looked at the Device SDK documentation but can’t find clear guidance on implementing device-side token refresh or automatic reconnection logic. How should we handle JWT expiry to maintain persistent device connectivity?

Thanks for the feedback. So I need to track the token expiry timestamp and refresh proactively. But how do I get a new JWT token from ThingWorx? Do I need to call a specific API endpoint, or does the Device SDK provide a method for this?

Don’t forget about the automatic reconnection logic. Even with token refresh, you should implement robust reconnection handling for network interruptions. The Device SDK has connection state callbacks that you can use to detect disconnects and trigger reconnection attempts. We use a combination of token refresh every 90 minutes (for 2-hour tokens) and reconnection logic with exponential backoff up to 5 minutes between attempts.

You’ll need to call the TokenService on ThingWorx to get a new token. Make sure your device has credentials or a refresh token to authenticate the renewal request. Also consider implementing exponential backoff for reconnection attempts in case of network issues or service unavailability.