nRF9160: MQTT to Azure IoT Hub with SAS Token

I am attempting to demonstrate connectivity from the nRF9160-DK to an Azure IoT Hub via SAS Token authentication.  My main reference was this tutorial from Microsoft:

https://learn.microsoft.com/en-us/azure/iot-develop/tutorial-use-mqtt

I was able to successfully follow this tutorial to demonstrate MQTT / SAS Token connectivity between a Raspberry Pi and my Azure IoT Hub.

I then wanted to demonstrate the same connectivity with the nRF9160-DK talking across the cellular network to my IoT Hub.  I started with the MQTT code example from Lesson 4 Exercise 2 of the of the Cellular IoT fundamental Dev Academy course:

https://academy.nordicsemi.com/topic/lesson-4-exercise-2/  

I added a new header file "azure_mqtt.h" with the same Azure device name, SAS Token, etc., as was used in the Raspberry PI IoT device.

I then modified the mqtt_connection.cpp file to use a username and password to log into the IoT hub, similar to what worked in the Raspberry Pi application:

The modified application built and flashed to the device correctly.  However, when the application runs, it gives the following error messages:

<err> nrf_modem: Modem error: 0x4, PC: 0xedffc

<wrn> modem_key_mgmt: Failed to retrieve CMEE status, err -1

<err> Lesson4_Exercise2: Failed to provision CA certificate: -1

I can see that this error is happening at the step where the code is provisioning the device certification, which is prior to connecting to the IoT hub.  How can I fix this?

Related