getaddrinfo error when porting "FOTA over Wi-Fi" exercise to nrf52840 + modem

I am trying to adapt lesson 9 (FOTA over Wi-Fi) exercise 7 of the DevAcademy nRF Connect SDK Intermediate course. I am trying to adapt it to work with nrf52840 connected to a simcom modem via UART. I managed to get it to boot but it fails at trying to resolve the DNS address.

See my changes here: https://github.com/olalonde/ncs-l9-e7/pull/1/files

It seems like the network connectivity goes up but when it is time of doing the dns request (getaddrinfo), the packet never makes it to the modem. If it did, we would see a CMUX log with some data after getaddrinfo is called, but it doesn't happen.

Full log: github.com/.../LOGS.txt

Relevant part:

[00:00:26.858,245] <inf> aws_iot_sample: Network connectivity established
...
...
[00:00:31.858,337] <inf> aws_iot_sample: Connecting to AWS IoT
[00:00:31.858,581] <dbg> mqtt_helper: broker_init: Resolving IP address for XXXX-ats.iot.us-east-2.amazonaws.com
[00:00:31.859,191] <dbg> net_l2_ppp: net_pkt_hexdump: send L2
[00:00:31.859,252] <dbg> net_l2_ppp: net_pkt_hexdump: 0x200314dc
                                     45 00 00 52 00 00 00 00  40 11 b9 69 64 7c 15 46 |E..R.... @..id|.F
                                     c8 58 7f 17 f3 b1 00 35  00 3e d5 aa 46 d9 01 00 |.X.....5 .>..F...
                                     00 01 00 00 00 00 00 00  08 78 78 78 78 2d 61 74 |........ .xxxx-at
                                     73 03 69 6f 74 09 75 73  2d 65 61 73 74 2d 32 09 |s.iot.us -east-2.
                                     61 6d 61 7a 6f 6e 61 77  73 03 63 6f 6d 00 00 01 |amazonaw s.com...
                                     00 01                                            |..               
[00:00:36.959,472] <err> mqtt_helper: getaddrinfo() failed, error -11
[00:00:36.959,533] <dbg> mqtt_helper: mqtt_state_set: Skipping transition to the same state (MQTT_STATE_DISCONNECTED)
[00:00:36.959,564] <err> aws_iot: mqtt_helper_connect, error: 11
[00:00:36.959,564] <err> aws_iot_sample: aws_iot_connect, error: 11

I assume there is something wrong with my configuration?

I am new to Zephyr/embedded development but it's as if getaddrinfo was not communicating with the modem PPP driver at all? 

I am able to successfully run the secure MQTT sample and cellular modem samples from Zephyr so I don't think it's an issue with the modem driver. I also tried increasing the DNS timeout but that doesn't help.

github.com/.../modem-port

Parents
  • I don't know if this helps but I tried setting the hostname to 8.8.8.8 to test and skip the DNS resolution and this is what it does:

    [00:00:28.145,690] <dbg> modem_cellular: modem_cellular_log_event: event registered
    [00:00:28.145,721] <dbg> modem_cellular: modem_cellular_log_event: event script success
    [00:00:29.259,094] <inf> aws_iot_sample: Connecting to AWS IoT
    [00:00:29.259,338] <dbg> mqtt_helper: broker_init: Resolving IP address for 8.8.8.8
    [00:00:29.259,490] <dbg> mqtt_helper: broker_init: IPv4 Address found 8.8.8.8 (AF_INET)
    [00:00:29.259,582] <dbg> mqtt_helper: mqtt_state_set: State transition: MQTT_STATE_DISCONNECTED --> MQTT_STATE_TRANSPORT_CONNECTING
    [00:00:29.260,253] <dbg> net_mqtt_sock_tls: mqtt_client_tls_connect: (sysworkq): Created socket 2
    [00:00:29.261,138] <dbg> net_l2_ppp: net_pkt_hexdump: send L2
    [00:00:29.261,199] <dbg> net_l2_ppp: net_pkt_hexdump: 0x2003155c
                                         45 00 00 2c 00 00 00 00  40 06 94 19 0a 4c cc 57 |E..,.... @....L.W
                                         08 08 08 08 91 23 22 b3  03 42 91 6f 00 00 00 00 |.....#". .B.o....
                                         60 02 02 aa 66 41 00 00  02 04 05 b4             |`...fA.. ....    
    [00:00:29.524,475] <dbg> net_l2_ppp: net_pkt_hexdump: send L2
    [00:00:29.524,536] <dbg> net_l2_ppp: net_pkt_hexdump: 0x2003159c
                                         45 00 00 2c 00 00 00 00  40 06 94 19 0a 4c cc 57 |E..,.... @....L.W
                                         08 08 08 08 91 23 22 b3  03 42 91 6f 00 00 00 00 |.....#". .B.o....
                                         60 02 02 aa 66 41 00 00  02 04 05 b4             |`...fA.. ....    
    [00:00:29.887,725] <wrn> net_tcp: net_pkt alloc failure
    [00:00:30.250,946] <wrn> net_tcp: net_pkt alloc failure
    [00:00:30.614,166] <wrn> net_tcp: net_pkt alloc failure
    [00:00:30.977,355] <wrn> net_tcp: net_pkt alloc failure
    [00:00:31.340,545] <wrn> net_tcp: net_pkt alloc failure
    [00:00:31.703,735] <wrn> net_tcp: net_pkt alloc failure
    [00:00:32.066,925] <wrn> net_tcp: net_pkt alloc failure
    [00:00:32.261,627] <err> mqtt_helper: mqtt_connect, error: -116
    [00:00:32.261,688] <dbg> mqtt_helper: mqtt_state_set: State transition: MQTT_STATE_TRANSPORT_CONNECTING --> MQTT_STATE_DISCONNECTED
    [00:00:32.261,688] <err> aws_iot: mqtt_helper_connect, error: -116
    [00:00:32.261,688] <err> aws_iot_sample: aws_iot_connect, error: -116
    [00:00:32.261,718] <err> aws_iot_sample: Fatal error! Rebooting the device.


    Also, I noticed in the build there are some warnings related to the MQTT helper library.

    https://github.com/olalonde/ncs-l9-e7/blob/modem-port/BUILD_LOGS.txt

    [378/459] Building C object modules/nrf/subsys/net/lib/mqtt_helper/CMakeFiles/..__nrf__subsys__net__lib__mqtt_helper.dir/mqtt_helper.c.obj
    In file included from /Users/redacted/code/alpha21/myproject/workspace/zephyr/include/zephyr/toolchain.h:50,
                     from /Users/redacted/code/alpha21/myproject/workspace/zephyr/include/zephyr/kernel_includes.h:23,
                     from /Users/redacted/code/alpha21/myproject/workspace/zephyr/include/zephyr/kernel.h:17,
                     from /Users/redacted/code/alpha21/myproject/workspace/zephyr/include/zephyr/net/socket.h:27,
                     from /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:8:
    In function 'broker_init',
        inlined from 'client_connect' at /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:457:8,
        inlined from 'mqtt_helper_connect' at /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:598:8:
    /Users/redacted/code/alpha21/myproject/workspace/zephyr/include/zephyr/toolchain/gcc.h:157:18: warning: array subscript 'struct <anonymous>[0]' is partly outside array bounds of 'struct sockaddr_storage[1]' [-Warray-bounds]
      157 |         __p->__v = (v);                                                 \
          |         ~~~~~~~~~^~~~~
    /Users/redacted/code/alpha21/myproject/workspace/zephyr/include/zephyr/net/net_ip.h:889:9: note: in expansion of macro 'UNALIGNED_PUT'
      889 |         UNALIGNED_PUT(UNALIGNED_GET(src), dest)
          |         ^~~~~~~~~~~~~
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:408:25: note: in expansion of macro 'net_ipaddr_copy'
      408 |                         net_ipaddr_copy(&broker6->sin6_addr,
          |                         ^~~~~~~~~~~~~~~
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c: In function 'mqtt_helper_connect':
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:32:32: note: at offset 4 into object 'broker' of size 8
       32 | static struct sockaddr_storage broker;
          |                                ^~~~~~
    In function 'broker_init',
        inlined from 'client_connect' at /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:457:8,
        inlined from 'mqtt_helper_connect' at /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:598:8:
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:410:46: warning: array subscript 'struct sockaddr_in6[0]' is partly outside array bounds of 'struct sockaddr_storage[1]' [-Warray-bounds]
      410 |                         broker6->sin6_family = addr->ai_family;
          |                         ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c: In function 'mqtt_helper_connect':
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:32:32: note: object 'broker' of size 8
       32 | static struct sockaddr_storage broker;
          |                                ^~~~~~
    In function 'broker_init',
        inlined from 'client_connect' at /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:457:8,
        inlined from 'mqtt_helper_connect' at /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:598:8:
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:411:44: warning: array subscript 'struct sockaddr_in6[0]' is partly outside array bounds of 'struct sockaddr_storage[1]' [-Warray-bounds]
      411 |                         broker6->sin6_port = htons(CONFIG_MQTT_HELPER_PORT);
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c: In function 'mqtt_helper_connect':
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:32:32: note: object 'broker' of size 8
       32 | static struct sockaddr_storage broker;
          |                                ^~~~~~

Reply
  • I don't know if this helps but I tried setting the hostname to 8.8.8.8 to test and skip the DNS resolution and this is what it does:

    [00:00:28.145,690] <dbg> modem_cellular: modem_cellular_log_event: event registered
    [00:00:28.145,721] <dbg> modem_cellular: modem_cellular_log_event: event script success
    [00:00:29.259,094] <inf> aws_iot_sample: Connecting to AWS IoT
    [00:00:29.259,338] <dbg> mqtt_helper: broker_init: Resolving IP address for 8.8.8.8
    [00:00:29.259,490] <dbg> mqtt_helper: broker_init: IPv4 Address found 8.8.8.8 (AF_INET)
    [00:00:29.259,582] <dbg> mqtt_helper: mqtt_state_set: State transition: MQTT_STATE_DISCONNECTED --> MQTT_STATE_TRANSPORT_CONNECTING
    [00:00:29.260,253] <dbg> net_mqtt_sock_tls: mqtt_client_tls_connect: (sysworkq): Created socket 2
    [00:00:29.261,138] <dbg> net_l2_ppp: net_pkt_hexdump: send L2
    [00:00:29.261,199] <dbg> net_l2_ppp: net_pkt_hexdump: 0x2003155c
                                         45 00 00 2c 00 00 00 00  40 06 94 19 0a 4c cc 57 |E..,.... @....L.W
                                         08 08 08 08 91 23 22 b3  03 42 91 6f 00 00 00 00 |.....#". .B.o....
                                         60 02 02 aa 66 41 00 00  02 04 05 b4             |`...fA.. ....    
    [00:00:29.524,475] <dbg> net_l2_ppp: net_pkt_hexdump: send L2
    [00:00:29.524,536] <dbg> net_l2_ppp: net_pkt_hexdump: 0x2003159c
                                         45 00 00 2c 00 00 00 00  40 06 94 19 0a 4c cc 57 |E..,.... @....L.W
                                         08 08 08 08 91 23 22 b3  03 42 91 6f 00 00 00 00 |.....#". .B.o....
                                         60 02 02 aa 66 41 00 00  02 04 05 b4             |`...fA.. ....    
    [00:00:29.887,725] <wrn> net_tcp: net_pkt alloc failure
    [00:00:30.250,946] <wrn> net_tcp: net_pkt alloc failure
    [00:00:30.614,166] <wrn> net_tcp: net_pkt alloc failure
    [00:00:30.977,355] <wrn> net_tcp: net_pkt alloc failure
    [00:00:31.340,545] <wrn> net_tcp: net_pkt alloc failure
    [00:00:31.703,735] <wrn> net_tcp: net_pkt alloc failure
    [00:00:32.066,925] <wrn> net_tcp: net_pkt alloc failure
    [00:00:32.261,627] <err> mqtt_helper: mqtt_connect, error: -116
    [00:00:32.261,688] <dbg> mqtt_helper: mqtt_state_set: State transition: MQTT_STATE_TRANSPORT_CONNECTING --> MQTT_STATE_DISCONNECTED
    [00:00:32.261,688] <err> aws_iot: mqtt_helper_connect, error: -116
    [00:00:32.261,688] <err> aws_iot_sample: aws_iot_connect, error: -116
    [00:00:32.261,718] <err> aws_iot_sample: Fatal error! Rebooting the device.


    Also, I noticed in the build there are some warnings related to the MQTT helper library.

    https://github.com/olalonde/ncs-l9-e7/blob/modem-port/BUILD_LOGS.txt

    [378/459] Building C object modules/nrf/subsys/net/lib/mqtt_helper/CMakeFiles/..__nrf__subsys__net__lib__mqtt_helper.dir/mqtt_helper.c.obj
    In file included from /Users/redacted/code/alpha21/myproject/workspace/zephyr/include/zephyr/toolchain.h:50,
                     from /Users/redacted/code/alpha21/myproject/workspace/zephyr/include/zephyr/kernel_includes.h:23,
                     from /Users/redacted/code/alpha21/myproject/workspace/zephyr/include/zephyr/kernel.h:17,
                     from /Users/redacted/code/alpha21/myproject/workspace/zephyr/include/zephyr/net/socket.h:27,
                     from /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:8:
    In function 'broker_init',
        inlined from 'client_connect' at /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:457:8,
        inlined from 'mqtt_helper_connect' at /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:598:8:
    /Users/redacted/code/alpha21/myproject/workspace/zephyr/include/zephyr/toolchain/gcc.h:157:18: warning: array subscript 'struct <anonymous>[0]' is partly outside array bounds of 'struct sockaddr_storage[1]' [-Warray-bounds]
      157 |         __p->__v = (v);                                                 \
          |         ~~~~~~~~~^~~~~
    /Users/redacted/code/alpha21/myproject/workspace/zephyr/include/zephyr/net/net_ip.h:889:9: note: in expansion of macro 'UNALIGNED_PUT'
      889 |         UNALIGNED_PUT(UNALIGNED_GET(src), dest)
          |         ^~~~~~~~~~~~~
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:408:25: note: in expansion of macro 'net_ipaddr_copy'
      408 |                         net_ipaddr_copy(&broker6->sin6_addr,
          |                         ^~~~~~~~~~~~~~~
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c: In function 'mqtt_helper_connect':
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:32:32: note: at offset 4 into object 'broker' of size 8
       32 | static struct sockaddr_storage broker;
          |                                ^~~~~~
    In function 'broker_init',
        inlined from 'client_connect' at /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:457:8,
        inlined from 'mqtt_helper_connect' at /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:598:8:
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:410:46: warning: array subscript 'struct sockaddr_in6[0]' is partly outside array bounds of 'struct sockaddr_storage[1]' [-Warray-bounds]
      410 |                         broker6->sin6_family = addr->ai_family;
          |                         ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c: In function 'mqtt_helper_connect':
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:32:32: note: object 'broker' of size 8
       32 | static struct sockaddr_storage broker;
          |                                ^~~~~~
    In function 'broker_init',
        inlined from 'client_connect' at /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:457:8,
        inlined from 'mqtt_helper_connect' at /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:598:8:
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:411:44: warning: array subscript 'struct sockaddr_in6[0]' is partly outside array bounds of 'struct sockaddr_storage[1]' [-Warray-bounds]
      411 |                         broker6->sin6_port = htons(CONFIG_MQTT_HELPER_PORT);
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c: In function 'mqtt_helper_connect':
    /Users/redacted/code/alpha21/myproject/workspace/nrf/subsys/net/lib/mqtt_helper/mqtt_helper.c:32:32: note: object 'broker' of size 8
       32 | static struct sockaddr_storage broker;
          |                                ^~~~~~

Children
No Data
Related