nrf9160: MQTT connect fails with IPv6 (AF_INET6)

We are trying to connect MQTT over IPv6 with nrf9160dk and custom board. We are using mqtt_simple sample.

Software NCS version: NCS main (latest)

Changes in the code: MQTT Broker is AWS

As seen in the below log, we are able to resolve the IPv6 address and not able to connect with mqtt_connect.

Any help is highly appreciated!

```
*** Booting Zephyr OS build v3.0.99-ncs1-13-g85a003480961  ***
I: Starting bootloader
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Swap type: none
I: Bootloader chainload address offset: 0x10000
*** Booting Zephyr OS build v3.0.99-ncs1-13-g85a003480961  ***
MQTT AWS Jobs FOTA Sample, version: v1.0.0
LTE Link Connecting ...
+CEREG: 2,"55F2","004F3902",7
+CSCON: 1
+CEREG: 5,"55F2","004F3902",7,,,"11100000","00101100"
LTE Link Connected!
IPv6 Address 2406:da00:ff00::3448:4f7b
client_id: your_client_id
ERROR: mqtt_connect -114
+CSCON: 0
```

Parents Reply Children
  • Thanks for your response. Am using MQTT with X.509 client certificate and the port is 8883.

    Thanks,

    Parthiban N

  • Thanks for clarifying. Can you please provide what settings you have edited in your project? Are you able to test with tag v2.0.0? 

    Kind regards,
    Øyvind

  • nrf/samples/nrf9160/aws_fota$ git diff .
    diff --git a/samples/nrf9160/aws_fota/Kconfig b/samples/nrf9160/aws_fota/Kconfig
    index 90fe11e14..731dd090f 100644
    --- a/samples/nrf9160/aws_fota/Kconfig
    +++ b/samples/nrf9160/aws_fota/Kconfig
    @@ -12,7 +12,7 @@ config APP_VERSION
     
     config  CERT_SEC_TAG
            int "Security tag for TLS credentials"
    -       default 12345678
    +       default 100
            help
              Security tag where the certificates for the AWS IoT MQTT broker
              are stored.
    @@ -28,7 +28,7 @@ config CLIENT_ID
     
     config MQTT_BROKER_HOSTNAME
            string "AWS IoT MQTT broker hostname"
    -       default "your_aws_mqtt_broker_hostname.amazonaws.com"
    +       default "a25rymalyfdr5r-ats.iot.us-east-1.amazonaws.com"
            help
              Address to your AWS IoT MQTT broker.
     
    diff --git a/samples/nrf9160/aws_fota/src/main.c b/samples/nrf9160/aws_fota/src/main.c
    index 9a431f51c..0d060abe8 100644
    --- a/samples/nrf9160/aws_fota/src/main.c
    +++ b/samples/nrf9160/aws_fota/src/main.c
    @@ -186,7 +186,7 @@ static void broker_init(const char *hostname)
            struct addrinfo *result;
            struct addrinfo *addr;
            struct addrinfo hints = {
    -               .ai_family = AF_INET,
    +               .ai_family = AF_INET6,
                    .ai_socktype = SOCK_STREAM
            };
     

    Here are the changes. Yes, tried with both ncs main branch latest and also with v2.0.0 tag and the results are same.

  • The DevZone team is currently entering summer vacation period, some delays in answers must be expected.


    Thanks for providing this information. Are you using the mqtt_simple or aws_fota? 

    I tried adding a new thing using to AWS IoT Core, reprovisioning the certificates and adding IPv6 support in the AWS_FOTA sample. It connected succesfully. 

    2022-07-04T10:48:09.721Z DEBUG modem << *** Booting Zephyr OS build v3.0.99-ncs1  ***
    2022-07-04T10:48:09.727Z DEBUG modem << MQTT AWS Jobs FOTA Sample, version: v1.0.0
    2022-07-04T10:48:09.728Z DEBUG modem << LTE Link Connecting ...
    2022-07-04T10:48:11.014Z DEBUG modem << +CEREG: 2,"7AA9","01172803",7
    2022-07-04T10:48:11.057Z DEBUG modem << +CSCON: 1
    2022-07-04T10:48:12.155Z DEBUG modem << +CEREG: 1,"7AA9","01172803",7,,,"00001010","11000001"
    2022-07-04T10:48:12.167Z DEBUG modem >> AT+COPS=3,2
    2022-07-04T10:48:12.168Z DEBUG modem << LTE Link Connected!
    2022-07-04T10:48:12.171Z DEBUG modem << OK
    2022-07-04T10:48:12.174Z DEBUG modem >> AT+COPS?
    2022-07-04T10:48:12.184Z DEBUG modem << +COPS: 0,2,"24201",7
    2022-07-04T10:48:12.185Z DEBUG modem << OK
    2022-07-04T10:48:12.188Z DEBUG modem >> AT%XCBAND
    2022-07-04T10:48:12.192Z DEBUG modem << %XCBAND: 20
    2022-07-04T10:48:12.194Z DEBUG modem << 
    2022-07-04T10:48:12.195Z DEBUG modem << OK
    2022-07-04T10:48:12.204Z DEBUG modem >> AT+CGDCONT?
    2022-07-04T10:48:12.218Z DEBUG modem << +CGDCONT: 0,"IPV4V6","telenor.iot","10.240.108.158 2A02:2121:0201:EF11:0000:0072:6AE2:5401",0,0
    2022-07-04T10:48:12.219Z DEBUG modem << OK
    2022-07-04T10:48:12.222Z DEBUG modem >> AT+CGACT?
    2022-07-04T10:48:12.226Z DEBUG modem << +CGACT: 0,1
    2022-07-04T10:48:12.227Z DEBUG modem << OK
    2022-07-04T10:48:12.256Z DEBUG modem << IPv6 Address 2a05:d000:6000::1010:172f
    2022-07-04T10:48:12.258Z DEBUG modem << client_id: 291542_aws
    2022-07-04T10:48:15.454Z DEBUG modem << [mqtt_evt_handler:110] MQTT client connected!
    2022-07-04T10:48:15.570Z DEBUG modem << [mqtt_evt_handler:167] SUBACK packet id: 2112
    2022-07-04T10:48:15.598Z DEBUG modem << [mqtt_evt_handler:167] SUBACK packet id: 2114
    2022-07-04T10:48:15.671Z DEBUG modem << [mqtt_evt_handler:157] PUBACK packet id: 10011
    2022-07-04T10:48:25.495Z DEBUG modem << +CSCON: 0
    2022-07-04T10:49:16.381Z DEBUG modem << +CSCON: 1
    2022-07-04T10:49:16.671Z DEBUG modem << [mqtt_evt_handler:172] default: 9
    2022-07-04T10:49:24.753Z DEBUG modem << +CSCON: 0
    2022-07-04T10:50:17.339Z DEBUG modem << +CSCON: 1
    2022-07-04T10:50:17.621Z DEBUG modem << [mqtt_evt_handler:172] default: 9
    2022-07-04T10:50:23.740Z DEBUG modem << +CSCON: 0
    

Related