This has been a recurring issue with this SDK. I've double/triple checked all the parameters regarding the deviceID, template DTMI, and DPS provisioning ID are correct. I'm using the SAS primary key from a Device Connection Group I created in IOTC. This key is used to generate a token in the Azure CLI prompt with the following command:
az iot central device compute-device-key --primary-key <enrollment group primary key> --device-id <device ID>
Here is the log generated running the code in Arduino:
1970/1/1 00:00:01 [INFO] WiFi connected, IP address: 192.168.40.73
1970/1/1 00:00:01 [INFO] Setting time using SNTP
........
2024/9/10 14:11:14 [INFO] Time initialized!
2024/9/10 14:11:14 [INFO] Azure IoT client initialized (state=2)
2024/9/10 14:11:15 [INFO] MQTT client target uri set to 'mqtts://global.azure-devices-provisioning.net'
2024/9/10 14:11:15 [INFO] MQTT client connecting.
2024/9/10 14:11:16 [INFO] MQTT client connected (session_present=0).
2024/9/10 14:11:16 [INFO] MQTT client subscribing to '$dps/registrations/res/#'
2024/9/10 14:11:16 [INFO] MQTT topic subscribed (message id=12954).
2024/9/10 14:11:16 [INFO] MQTT client publishing to '$dps/registrations/PUT/iotdps-register/?$rid=1'
2024/9/10 14:11:16 [INFO] MQTT message received.
2024/9/10 14:11:16 [ERROR] Device provisisioning failed.
2024/9/10 14:11:16 [ERROR] Azure IoT client is in error state.
2024/9/10 14:11:16 [INFO] MQTT client being disconnected.
EDIT:
Discovered the issue, i had brackets around the primary key and device ID for this statement to get the SAS tokens.
az iot central device compute-device-key --pk primary-key-here --device-id device-ID-here