nRF9160DK: MQTT Connection Error - Azure IoT Hub

Hi, 

I have been using the nRF9160-DK sample code to connect my dk to my hosted Azure IoT Hub. I have followed the documentation for creating the certificates for both the CA Cert to put on my IoT Hub and as well the client-side certificate. I used the AT Client to turn off the modem before updating the certificates as told to do so in the documentation and as well testing the certificates using the sample verification and data from that simulation was able to send. However, when trying to do so from the device failed. I am not sure whether this is a certificate issue or a code issue. Please advise. I am not using DPS fyi

I have been troubleshooting for a couple of days now and I can't seem to understand where this issue is coming from. Below is the logging information for what is happening to my device. 

Thanks in advance! 

/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Logging.jpg_2D00_640x480.jpg

*** Booting Zephyr OS build v3.2.99-ncs2 ***
[00:00:00.531,005] <inf> azure_iot_hub_sample: Azure IoT Hub sample started
[00:00:00.531,127] <inf> azure_iot_hub_sample: Connecting to LTE network
+CEREG: 2,"3BC5","03090216",7
+CSCON: 1
[00:00:16.855,957] <inf> azure_iot_hub_sample: LTE cell changed: Cell ID: 50922006, Tracking area: 15301
[00:00:17.616,760] <inf> azure_iot_hub_sample: RRC mode: Connected
+CEREG: 5,"3BC5","03090216",7,,,"00001010","11000001"
[00:00:20.076,843] <inf> azure_iot_hub_sample: Network registration status: Connected - roaming
[00:00:20.076,995] <inf> azure_iot_hub_sample: Connected to LTE network
[00:00:20.077,056] <dbg> azure_iot_hub: iot_hub_state_set: State transition: STATE_UNINIT --> STATE_DISCONNECTED
[00:00:20.077,056] <inf> azure_iot_hub_sample: Azure IoT Hub library initialized
[00:00:20.077,117] <dbg> azure_iot_hub: iot_hub_state_set: State transition: STATE_DISCONNECTED --> STATE_CONNECTING
[00:00:20.077,148] <inf> azure_iot_hub_sample: AZURE_IOT_HUB_EVT_CONNECTING
[00:00:20.077,239] <dbg> azure_iot_hub: azure_iot_hub_connect: User name: HubIoTSZGP.azure-devices.net/iotdemodevice/?api-version=2020-09-30&DeviceClientType=azsdk-c%2F1.4.0-beta.2
[00:00:20.077,270] <dbg> azure_iot_hub: azure_iot_hub_connect: User name buffer size is 128, actual user name size is: 106
[00:00:20.078,521] <inf> azure_iot_hub_sample: PSM parameter update: TAU: 1152000, Active time: 20
[00:00:20.577,545] <err> mqtt_helper: mqtt_connect, error: -111
[00:00:20.577,545] <err> azure_iot_hub: mqtt_helper_connect failed, error: -111
[00:00:20.577,606] <dbg> azure_iot_hub: iot_hub_state_set: State transition: STATE_CONNECTING --> STATE_DISCONNECTED
[00:00:20.577,636] <err> azure_iot_hub_sample: azure_iot_hub_connect failed: -111
+CSCON: 0
[00:00:27.182,922] <inf> azure_iot_hub_sample: RRC mode: Idle

Parents
  • **Update It seems like I have fixed the certificate issue. I am now getting this in my logs however and I still don't see the data in my Azure IoT Hub. 

    *** Booting Zephyr OS build v3.2.99-ncs2 ***
    [00:00:00.522,186] <inf> azure_iot_hub_sample: Azure IoT Hub sample started
    [00:00:00.522,308] <inf> azure_iot_hub_sample: Connecting to LTE network
    +CEREG: 2,"3BEB","01610D04",7
    +CSCON: 1
    +CEREG: 2,"3BEB","01610D04",7,0,11
    [00:00:20.043,518] <inf> azure_iot_hub_sample: LTE cell changed: Cell ID: 23137540, Tracking area: 15339
    [00:00:20.311,553] <inf> azure_iot_hub_sample: RRC mode: Connected
    +CSCON: 0
    +CEREG: 2,"874A","0B78580F",7
    [00:00:21.653,564] <inf> azure_iot_hub_sample: RRC mode: Idle
    [00:00:22.121,490] <inf> azure_iot_hub_sample: LTE cell changed: Cell ID: 192436239, Tracking area: 34634
    +CSCON: 1
    +CEREG: 2,"874A","0B78580F",7,0,11
    [00:00:22.696,289] <inf> azure_iot_hub_sample: RRC mode: Connected
    +CSCON: 0
    +CEREG: 2,"874A","0B78580F",7
    +CSCON: 1
    [00:00:24.092,559] <inf> azure_iot_hub_sample: RRC mode: Idle
    [00:00:24.284,332] <inf> azure_iot_hub_sample: RRC mode: Connected
    +CEREG: 5,"874A","0B78580F",7,,,"00001010","11000001"
    [00:00:28.785,552] <inf> azure_iot_hub_sample: Network registration status: Connected - roaming
    [00:00:28.785,736] <inf> azure_iot_hub_sample: Connected to LTE network
    [00:00:28.785,766] <dbg> azure_iot_hub: iot_hub_state_set: State transition: STATE_UNINIT --> STATE_DISCONNECTED
    [00:00:28.785,797] <inf> azure_iot_hub_sample: Azure IoT Hub library initialized
    [00:00:28.785,858] <dbg> azure_iot_hub: iot_hub_state_set: State transition: STATE_DISCONNECTED --> STATE_CONNECTING
    [00:00:28.785,858] <inf> azure_iot_hub_sample: AZURE_IOT_HUB_EVT_CONNECTING
    [00:00:28.786,071] <dbg> azure_iot_hub: azure_iot_hub_connect: User name: HubIoTSZGP.azure-devices.net/iotdemodevice/?api-version=2020-09-30&DeviceClientType=azsdk-c%2F1.4.0-beta.2
    [00:00:28.786,071] <dbg> azure_iot_hub: azure_iot_hub_connect: User name buffer size is 128, actual user name size is: 106
    [00:00:28.787,170] <inf> azure_iot_hub_sample: PSM parameter update: TAU: 1152000, Active time: 20
    [00:00:32.657,501] <inf> azure_iot_hub_sample: Connection request sent to IoT Hub
    [00:00:32.897,613] <dbg> azure_iot_hub: iot_hub_state_set: State transition: STATE_CONNECTING --> STATE_CONNECTED
    [00:00:32.897,613] <dbg> azure_iot_hub: on_connack: MQTT mqtt_client connected
    [00:00:32.898,712] <dbg> azure_iot_hub: topic_subscribe: Successfully subscribed to default topics
    [00:00:32.898,712] <inf> azure_iot_hub_sample: AZURE_IOT_HUB_EVT_CONNECTED
    [00:00:33.050,872] <inf> azure_iot_hub_sample: AZURE_IOT_HUB_EVT_READY
    [00:00:33.050,994] <dbg> azure_iot_hub: request_id_create_and_get: Request ID not specified, using "330"
    [00:00:33.051,269] <inf> azure_iot_hub_sample: Sending event:{"temperature":25.1,"timestamp":33051}
    [00:00:33.051,757] <dbg> azure_iot_hub: device_twin_request: Device twin requested
    [00:00:33.052,307] <inf> azure_iot_hub_sample: Event was successfully sent
    [00:00:33.052,337] <inf> azure_iot_hub_sample: Next event will be sent in 20 seconds
    [00:00:33.187,774] <wrn> azure_iot_hub: DISCONNECT, result: -128
    [00:00:33.187,835] <dbg> azure_iot_hub: iot_hub_state_set: State transition: STATE_CONNECTED --> STATE_DISCONNECTED
    [00:00:33.187,866] <inf> azure_iot_hub_sample: AZURE_IOT_HUB_EVT_DISCONNECTED
    [00:00:33.187,896] <err> mqtt_helper: Cloud MQTT input error: -128
    +CSCON: 0
    [00:00:38.900,634] <inf> azure_iot_hub_sample: RRC mode: Idle

  • Hey Sam,

    I am currently experiencing the same problem you encountered.

    Therefore I am curious to know how you solved your error: -128. Cant seem to get beyond this issue so it would be a huge help if you could share some information as to how you have resolved the issue.

    Kind regards

    Reimer    

  • I see, 

    When I used my device, I did not enable DPS. I had DPS disabled. 

    Also, at first, I thought I needed to flash the device with the CA root certificate I created. However, this did not work for me. Instead, I flashed the device with ONLY the Baltimore Certificate and uploaded the CA root Certificate to the Azure IoT Certificate upload and from there I verified the certificate from Azure Cloud. 

    You may have the correct certificates but placed them in the wrong place. That was the same issue I faced. I am not certain of the advice I am giving you since it was once again 6 months ago, but I am almost certain that error -128 has something to do with the certificate. 

    Some good news is that this was the last error I faced until I saw data coming into my Azure IoT Hub. You just need to somehow get the certificate to work from the device to Azure IoT Hub and that's all I remember to be frank with you. 


    Sorry in advance if this did not help. 

  • Hey Sam,

    If possible could you tell/show how you have setup you certificates up if you still have access/can remember? 

    I was wondering if I might have to use subordinate certificates from Microsoft: https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/security/fundamentals/azure-CA-details.md#root-and-subordinate-certificate-authority-chains

    Kind regards,

    Reimer

  • On my nRF device I used the "Baltimore CyberTrust Root" certificate and then on my Azure IoT Hub, I uploaded myself generated CA root certificate. I verified that certificate on Azure IoT Hub and added the device to the device manager on Azure IoT Hub. 

    When you add your device to Azure IoT Hub make sure you have it set for x.509 CA.

    Make sure your device name on Azure IoT Hub matches your code, and as well the Azure IoT Hub host name matches. 

    Try looking at the images I attached. 


    From there the device started working. 

  • Hey Sam

    Though I already had set it up like that it made me look my IoT hub through again and found out i had a "basic" subscription and when i changed it to "standard" it just worked. 

    Really appreciate you taking the time to help me!

    Kind regards,

    Reimer

  • Happy to hear that! Best of luck to you. 

Reply Children
No Data
Related