HTTP Client + W5500 on nRF5340: Works with IP but fails with domain names (DNS resolution fails)

Hi everyone,

I’m trying to use the HTTP client sample from NCS v3.0.2 with a W5500 Ethernet shield on an nRF5340. DHCP works fine, and I can successfully POST and GET using IP addresses. However, when I try to use domain names, DNS resolution fails.

Here is my prj.conf related to networking and DNS:

# Network driver config
CONFIG_TEST_RANDOM_GENERATOR=y

# Network buffers
CONFIG_NET_MAX_CONN=10
CONFIG_NET_PKT_RX_COUNT=16
CONFIG_NET_PKT_TX_COUNT=16
CONFIG_NET_BUF_RX_COUNT=128
CONFIG_NET_BUF_TX_COUNT=128
CONFIG_NET_CONTEXT_NET_PKT_POOL=y

# Networking core
CONFIG_NETWORKING=y
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=n
CONFIG_NET_UDP=y
CONFIG_NET_TCP=y
CONFIG_NET_SHELL=y

# DHCP
CONFIG_NET_DHCPV4=y
CONFIG_NET_DHCPV4_OPTION_CALLBACKS=y

# Ethernet
CONFIG_ETH_W5500=y

# SPI
CONFIG_SPI=y

# Sockets (MANDATORY)
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=n
CONFIG_ZVFS_POLL_MAX=4
CONFIG_POSIX_API=y

# HTTP client
CONFIG_HTTP_CLIENT=y

# DNS
CONFIG_ZVFS_POLL_MAX=10
CONFIG_DNS_SERVER_IP_ADDRESSES=y
CONFIG_DNS_RESOLVER_MAX_SERVERS=6
CONFIG_DNS_RESOLVER_MAX_QUERY_LEN=255
CONFIG_DNS_RESOLVER_AUTO_INIT=y
CONFIG_DNS_RESOLVER=y
CONFIG_DNS_SERVER1="8.8.8.8"
CONFIG_DNS_SERVER2="1.1.1.1"

# Logging
CONFIG_LOG=y
CONFIG_NET_LOG=y
CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y
CONFIG_NET_HTTP_LOG_LEVEL_DBG=y

# Stack sizes (IMPORTANT for W5500)
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096


What I have tried

  1. Verified DHCP works and prints a valid IP, subnet, and gateway.

  2. Tried adding configs to resolve DNS.
  3. Tried using dns_resolve_init() with 8.8.8.8 and 1.1.1.1 — bus fault occurs if sockets are not managed properly.

  4. Checked CONFIG_NET_SOCKETS_MAXit is not defined in NCS v3.0.2, so I cannot increase max sockets.

  5. Tried limiting HTTP client to one socket at a time, opening DNS first — still fails with net_dns_resolve: Cannot get socket (-106).

  6. Direct IP HTTP requests work perfectly.

Observations

  • Error from DNS resolver is either -106 (ENOBUFS, no free sockets) or -101 (EALREADY).

  • W5500 has only 8 hardware sockets, which seems to limit DNS + HTTP simultaneously.

  • I suspect DNS resolution fails because the DNS UDP socket cannot be allocated when the HTTP sockets are already opened.

Question

  • How can I make DNS resolution work reliably without switching to hardcoded IPs?

Parents
  • Hi,

    Sounds to me that all sockets are taken yes (-106 (ENOBUFS, no free sockets) or -101 (EALREADY)).

    Not sure I have any good suggestion here other than possible look at existing examples that use the W5500 if they have any pointers. You may also need to reach out the the zephyr community or W5500 support for help in case they have any suggestions.

    Kenneth

  • W5500 is at very low level, The libraries from NCS are handling it. So this doesn't seem to be an issue with the W5500.

    I'm using the http_client sample code combined with dhcpv4_client sample. The dhcpv4 client gets an IP assigned from the DHCP server (router in my case). The http_client sample uses that IP address (managed at the backend by ncs/zephyr libraries) to connect to an http server. When I use the IP address of the server, like 142.250.202.14, the socket is opened and http connection is created (verified through logs) and the HTTP GET request is successfully sent, response is received. But when I use domain name like google.com to try to connect the socket, it fails with the error mentioned above -106.

    Although I have set up the DNS resolver in the prj.conf (already shared in the post) of my project, seems like the DNS resolver is unable to resolve the Domain name.

    I'm using the sample code from:

    zephyr/samples/net/dhcpv4_client

    zephyr/samples/net/http_client

Reply
  • W5500 is at very low level, The libraries from NCS are handling it. So this doesn't seem to be an issue with the W5500.

    I'm using the http_client sample code combined with dhcpv4_client sample. The dhcpv4 client gets an IP assigned from the DHCP server (router in my case). The http_client sample uses that IP address (managed at the backend by ncs/zephyr libraries) to connect to an http server. When I use the IP address of the server, like 142.250.202.14, the socket is opened and http connection is created (verified through logs) and the HTTP GET request is successfully sent, response is received. But when I use domain name like google.com to try to connect the socket, it fails with the error mentioned above -106.

    Although I have set up the DNS resolver in the prj.conf (already shared in the post) of my project, seems like the DNS resolver is unable to resolve the Domain name.

    I'm using the sample code from:

    zephyr/samples/net/dhcpv4_client

    zephyr/samples/net/http_client

Children
Related