nRF9160 Ethernet and LTE both available but cannot open sockets under Ethernet

I've got an nRF 9160-dk board I have been able to connect over the LTE using TLS to my own data repository site and to google.com and example.com

What I've not been able to do is get a connection over the Ethernet to anything.

So far I've tried:

  • using CONFIG_NET_SOCKETS_OFFLOAD=n which results in me getting EPROTOTYPE (-107) when trying to open the socket
  • enabling CONFIG_MBEDTLS=y and CONFIG_MBEDTLS_TLS_LIBRARY=y this did not change anything
  • Setting CONFIG_DNS_RESOLVER=y and CONFIG_DNS_SERVER1="1.1.1.1"
  • I've also tried connection without TLS

Additional notes;

I have verified that I can run the DHCPv4 client code and get an address and the gateway route. I'm also able to use getaddrinfo to get the DNS address of my site with CONFIG_NET_SOCKETS_OFFLOAD=n set.

Development Setup

OS: Ubuntu 22.04 LTS

SW:

  • Visual Studio Code
    • Version: 1.75.1
    • Commit: 441438abd1ac652551dbe4d408dfcec8a499b8bf
    • Date: 2023-02-08T21:35:30.018Z
    • Electron: 19.1.9
    • Chromium: 102.0.5005.194
    • Node.js: 16.14.2
    • V8: 10.2.154.23-electron.0
    • OS: Linux x64 6.1.10-x64v1-xanmod1
    • Sandboxed: No
  • JLink (V758b X86_64 Linux)

HW:

Parents
  • Hi,

    Did you make any progress on this? I am also trying to get LTE and Ethernet going in the same firmware, with the exception that I am using the link_board_eth.

  • Hi,

    I’m having the same issue. Can’t get the http_get sample nor the aws-sample to work on my nRF9160DK using the Ethernet controller ENC424J600. DHCPv4 works fine, I can ping fine make DNS lookups through the net shell, but everytime a `getaddrinfo()` is called, I get a -11 error and cannot go any further.

    Also `CONFIG_NET_SOCKETS_OFFLOAD` can’t really be disabled as it is required by `CONFIG_LTE_CONNECTIVITY`.

    Any idea on how to proceed? I’ve been at it for days at this point. Should the offloading be disabled? Why isn’t my DNS server somehow not used by `getaddrinfo()`?

    Thanks!

  • Hi,

    Note that the below is a terrible hack and is not the "correct" way to do this.

    I finally got this working, but not without forking both sdk-zephyr and sdk-nrf. There are at least two issues related to how Zephyr handles multiple network interfaces:

    1. Zephyr does support multiple network interfaces. Choosing which one to use is primarily based on static priority and address family match. It is possible to change to priorities such that either Ethernet or LTE comes first, but whether or not a route towards the destination exists from the chosen interface is not taken into account. This means that if you pull the Ethernet cable or LTE disconnects, packets will not magically start flowing through the other interface.
    2. Enabling NRF_MODEM_LIB also enables CONFIG_NET_SOCKETS_OFFLOAD and this also offloads DNS to the modem. This means that getaddrinfo() will fail if LTE is not connected.

    There is an additional gotcha: the net shell DNS lookup does not call getaddrinfo() like your application does. This had me confused for a while.

    It is possible to choose which interface to bind a new socket to, but I was using aws_lib and the call to create a socket is buried deep within `mqtt` so that did not solve my problem.

    I could not find any official way to solve 1. and 2. What I did in the end was:

    • Add a flag in zephyr/subsys/net/lib/sockets/socket_dispatcher.c to tell the dispatcher whether or not to allow using the modem.
    • Add the same flag in zephyr/subsys/net/lib/sockets/getaddrinfo.c to make sure the getaddrinfo() calls use the modem or Ethernet accordingly.
    • Export the function static int nrf91_socket_create(int family, int type, int proto) from nrf/lib/nrf_modem_lib/nrf91_sockets.c so that when zephyr/subsys/net/lib/sockets/socket_dispatcher.c iterates over the interfaces, it can check if it is looking at the modem.

    The flag was then used to switch between LTE and Ethernet. A connectivity manager was made to detect if either interface had internet connectivity and switch accordingly.

  • Thanks a lot for your reply! That really looks like a pain to get everything working together…

    In my case, I’m only enabling one of the interface at a time depending on different factors (SIM inserted? Ethernet link available?). The rest of the time the device sleeps and everything is turned off, so I don’t really need the second interface to take over in case packets can’t flow through the first one, but of course I still need my sockets opening to use the right (up) one.

    I’m also using the AWS IoT library and also found the socket opening stuff was buried deep, though the issue about managing these two interfaces should probably be handled elsewhere anywhere. I’ll try to experiment a bit more and see if I can sort things out… I really thought all that network interfaces and connectivity manager stuff would help making this easier, but it seems to be aimed only at Wi-Fi and LTE somehow.

  • Hi  ,

    We do not have sample that would directly assist you in your implementation effort. I hope that you can find some useful suggestions/ideas in the  post.

    Best regards,
    Dejan

Reply Children
No Data
Related