Hello @Mohit patel,
Thank you for reaching out. Based on the behavior you described, the device is successfully establishing a TLS connection, which confirms that network connectivity and endpoint resolution are working correctly. The failure is occurring during SAS token authentication, which typically indicates an issue with token generation or connection configuration while connecting to Azure IoT Central.
Please review the following checks to help isolate and resolve the issue:
1. Verify Device Registration
Ensure that the device is properly created in IoT Central:
Navigate to Devices → + New
Confirm the following details:
- Device ID (case-sensitive and must match exactly)
- Scope ID (ID Scope)
- Primary/Secondary Key
Ensure the device status is Enabled
2. Validate SAS Token Generation
The SAS token must follow the correct structure:
SharedAccessSignature sr={scopeId}/devices/{deviceId}&sig={signature}&se={expiry}
Key validations:
Resource URI (sr) must be:
{scopeId}/devices/{deviceId}
String-to-sign:
{scopeId}/devices/{deviceId}\n{expiry}
Signature (sig):
Generated using HMAC-SHA256
Use Base64-decoded device key
Output must be Base64 encoded and URL encoded
Expiry (se):
Must be a future UNIX timestamp
Common issues observed:
- Incorrect resource URI
- Signature not URL encoded
- Using incorrect device key
- Expired token
3. Check Device Time Synchronization
SAS tokens are time-sensitive.
- Ensure the gateway system clock is synchronized
- A time drift of more than a few minutes can result in authentication failure
4. Confirm MQTT Configuration
Please ensure the MQTT client is configured as follows:
- Host:
{yourAppName}.azure-devices.net
- Port:
8883
- Client ID:
<deviceId>
- Username:
{scopeId}/?api-version=2018-06-30
- Password: SAS token
Any deviation in these parameters can lead to authentication failure after TLS handshake.
5. Network and Access Validation
Confirm there are no firewall or private endpoint restrictions blocking the device
Ensure outbound connectivity to Azure IoT endpoints is allowed
6. Enable Diagnostic Logging
- Enable verbose logging on your gateway or SDK
- Check for MQTT connection response codes (e.g., 401 Unauthorized, invalid token)
- Review device-level diagnostics in IoT Central if available
7. Isolate Using a Known Working Tool
As a validation step Attempt to connect using a tool such as IoT Explorer with the same device credentials
If successful, this confirms the issue is with SAS token generation or device-side configuration
Since TLS connectivity is successful, the issue is most likely related to:
- Incorrect SAS token generation
- Device time synchronization issues
- Incorrect MQTT configuration
Please refer this
Troubleshoot connection failures → https://docs.microsoft.com/azure/iot-central/core/troubleshoot-connection • Control access with SAS → https://docs.microsoft.com/azure/iot-hub/iot-hub-dev-guide-sas
I hope this will help you. Please feel free to let me know if you have any other queries.
Thank you!