nrf53: getaddrinfo() failed

Hi,

I am adapting the Azure IoT example for use with the nRF5340DK and nRF7002EK.

The configuration is:

- sdk: nvs 2.6.0

- example Azure IoT hub

Initially, the getaddrinfo() function returns a failure code of -101 when called in the broker_init.

After that, I implemented the DNS resolver, dns_resolve_init(), which changed the return error to -11.

Could you please assist me in resolving this issue?

prj.conf

CONFIG_NET_IPV6=n
CONFIG_NET_IPV4=y
CONFIG_NET_DHCPV4=n


# Enable Sockets support
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y

# Enable the DNS resolver
CONFIG_DNS_RESOLVER=y
# Enable additional buffers
CONFIG_DNS_RESOLVER_ADDITIONAL_BUF_CTR=5
# Enable additional queries
CONFIG_DNS_RESOLVER_ADDITIONAL_QUERIES=2
# Enable mDNS support
CONFIG_MDNS_RESOLVER=y
# Enable LLMNR support
CONFIG_LLMNR_RESOLVER=n

CONFIG_DNS_RESOLVER_MAX_SERVERS=1
CONFIG_DNS_SERVER_IP_ADDRESSES=y
CONFIG_DNS_NUM_CONCUR_QUERIES=5
CONFIG_DNS_RESOLVER_LOG_LEVEL_DBG=y

# Google DNS IPv4 and IPv6 servers
CONFIG_DNS_SERVER1="8.8.8.8"
# CONFIG_DNS_SERVER2="2001:4860:4860::8888"

CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV6=n
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"

Terminal

*** Booting nRF Connect SDK v3.5.99-ncs1 ***


[00:00:00.014,862] <inf> wifi_nrf_bus: SPIM spi@a000: freq = 8 MHz
[00:00:00.014,923] <inf> wifi_nrf_bus: SPIM spi@a000: latency = 0
*** Booting nRF Connect SDK v3.5.99-ncs1 ***
[00:00:30.272,857] <inf> main: Azure IoT Hub sample started
[00:00:30.272,857] <inf> main: Bringing network interface up and connecting to the network
[00:00:31.832,885] <inf> wifi_mgmt_ext: Connection requested
[00:00:36.031,585] <inf> main: Network connectivity established and IP address assigned
[00:00:36.032,226] <inf> main: Connected to network
[00:00:36.032,257] <inf> main: Device ID: device-02
[00:00:36.032,287] <inf> main: Starting DPS
[00:00:36.032,623] <inf> main: DPS registration status: AZURE_IOT_HUB_DPS_REG_STATUS_NOT_STARTED
[00:00:36.032,836] <err> mqtt_helper: getaddrinfo() failed, error -11
[00:00:36.032,867] <err> azure_iot_hub_dps: mqtt_helper_connect failed, error: 11
[00:00:36.032,867] <err> main: DPS failed to start, error: 11
[00:00:36.032,867] <err> main: Failed to run DPS, error: 11, terminating connection attempt

Parents Reply Children
  • Do you set up and configure an Azure IoT Hub instance? See Setup and configuration for information on creating an Azure IoT Hub instance and Additional configuration for additional information on the configuration options that are available. 

  • Yes, I have already set up my IoT hub and tested it using a Python script, provision_x509.py

    prj.conf

    # Azure IoT Hub library
    CONFIG_AZURE_IOT_HUB=y
    CONFIG_AZURE_IOT_HUB_DEVICE_ID="myDevice"
    CONFIG_AZURE_IOT_HUB_DPS=y
    CONFIG_AZURE_IOT_HUB_DPS_ID_SCOPE="0ne00xxxxxx"
    CONFIG_AZURE_IOT_HUB_LOG_LEVEL_DEFAULT=y
    # Host name must be configured if DPS is not used
    CONFIG_AZURE_IOT_HUB_HOSTNAME=""
    # Change the security tag to the tag where Azure IoT Hub certificates
    # are provisioned
    CONFIG_MQTT_HELPER_SEC_TAG=10
    CONFIG_MQTT_HELPER_SECONDARY_SEC_TAG=11
    CONFIG_MQTT_HELPER_STACK_SIZE=8192

    Certificate configuration

    ca-cert.pem --> G2

    client-cert.pem --> myDevice-full-chain.cert.pem

    private-key.pem --> myDevice.key.pem

  • Hi, 

    In your log, "<err> mqtt_helper: getaddrinfo() failed, error -11"

    The getaddrinfo() function is used to resolve domain names into IP addresses. If it fails with error -11, it typically means that the Domain Name System (DNS) lookup failed. This can happen if the device is not connected to the internet, or if the DNS server is not reachable or not working correctly.

    -Amanda H.

  • Hi,

    "<inf> main: Connected to network". This log shows that my device can connect to the internet, doesn't it?

    the DNS server is not reachable or not working correctly.

    Can you help clarify the important configurations that I should check?

    Additional findings from my investigation:

    - The error code -11 occurs when CONFIG_NET_DHCPV4=y.
    - When CONFIG_NET_DHCPV4=n, the error code is -101.

  • Hi!

    Amanda is out of office, so I'm replying instead.

    We don't see any DNS-related logs, despite you setting CONFIG_DNS_RESOLVER_LOG_LEVEL_DBG, probably missed CONFIG_NET_LOG

    Make sure you enable:

    CONFIG_NET_LOG=y
    CONFIG_DNS_RESOLVER_LOG_LEVEL_DBG=y
    CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y # (for gettaddrinfo logs)

    Now as for the failures:

    1. w/o DHCPv4 your configuration won't work (unless you ommited some essential configs in the snippet you provided) as you configure DNS server to an external server (8.8.8.8), but doesn't set the GW address ( DCONFIG_NET_CONFIG_MY_IPV4_GW) - the server won't be reachable. Although I wouldn't personally recommend static address configuration
    2. w/ DHCPv4 - would be good to see the log output with the configs I've mentioned above. Personally, I'd also enable CONFIG_NET_SHELL=y and see what DNS server address gets configured with DHCPv4 ( net dns command), whether it's a valid one and whether you can execute simple queries ( net dns google.com ) for instance.


    BR,

    Sigurd

Related