mqtt_simple sample gets error -2 in getaddrinfo

Hello,

We have developed our own module based on the nrf9160 DK and want to use it to send data to a MQTT broker. A few days ago on the dev-kit everything worked fine, now the new PCBs have arrived and we get this error in the mqtt_simple sample (as well as in our own code, but in a little different format):

 *** Booting Zephyr OS build v3.2.99-ncs1 ***                                      
[00:00:00.504,638] <inf> mqtt_simple: The MQTT simple sample started               
[00:00:00.504,699] <inf> mqtt_simple: Disabling PSM and eDRX                              
[00:00:00.505,401] <inf> mqtt_simple: LTE Link Connecting...                              
[00:00:09.277,618] <inf> mqtt_simple: LTE Link Connected!                                 
[00:00:09.277,862] <err> mqtt_simple: getaddrinfo failed: -2                              
[00:00:09.277,893] <err> mqtt_simple: Failed to initialize broker connection              
[00:00:09.277,893] <err> mqtt_simple: client_init: -10   

We just added the following config lines to use NB-IoT in the sample:

CONFIG_LTE_NETWORK_MODE_NBIOT=y
CONFIG_LTE_MODE_PREFERENCE_NBIOT=y

When using the IP address of the moquitto test server, it works perfectly fine.

*** Booting Zephyr OS build v3.2.99-ncs1 ***                                      
[00:00:00.568,603] <inf> mqtt_simple: The MQTT simple sample started                      
[00:00:00.568,664] <inf> mqtt_simple: Disabling PSM and eDRX                              
[00:00:00.569,366] <inf> mqtt_simple: LTE Link Connecting...                              
[00:00:11.186,523] <inf> mqtt_simple: LTE Link Connected!                                 
[00:00:11.186,950] <inf> mqtt_simple: IPv4 Address found 91.121.93.94                     
[00:00:11.187,438] <dbg> mqtt_simple: client_id_get: client_id = nrf-2EB11F7FD373E99C     
[00:00:11.598,114] <inf> mqtt_simple: MQTT client connected                               
[00:00:11.598,144] <inf> mqtt_simple: Subscribing to: my/subscribe/topic len 22       
[00:00:11.746,185] <inf> mqtt_simple: SUBACK packet id: 1234                              
[00:06:48.615,112] <inf> mqtt_simple: MQTT PUBLISH result=0 len=15                        
[00:06:48.615,203] <inf> mqtt_simple: Received: test with ip address                           
[00:06:48.615,783] <inf> mqtt_simple: Publishing: test with ip address                         
[00:06:48.615,814] <inf> mqtt_simple: to topic: my/publish/topic len: 20              
[00:06:48.761,352] <inf> mqtt_simple: PUBACK packet id: 39802 

Has anybody an idea? 

We are using the NCS v2.2.0 with the toolchain 2.2.0 (but tried the 2.1.0 as well, as we used with the dev-kit), modem firmware is 1.2.3

Edit: I forgot to add: when using the same code on the dev-kit, it works also fine with the IP Address and the URL. Modem firmware is here also 1.2.3 - thats the reason we choose 1.2.3 instead of 1.3.3. We also use the same SIM card to prevent any errors from the provider side (bad DNS, APN, whatever...)

Thank you!

BR Thomas

Parents
  • Hello,

    We are using a m2m SIM from company "drei" from Austria. I've used the very same SIM card in the dev kit and in our module to exclude any errors from this side.
    In the meantime, I tried to set the DNS manually (like in thread), but it only works randomly and only once after flashing the modem firmware. Then it looks like its running into a timeout and a watchdog restarts the module.

    BR Thomas

  • I've tested your approach with multiple requests, but the same result:

    uart:~$ *** Booting Zephyr OS build v3.2.99-ncs1 ***                            
    [00:00:00.495,513] <inf> nrf_modem_lib_trace: Trace thread ready                
    [00:00:00.496,826] <inf> nrf_modem_lib_trace: Trace level override: 2           
    [00:00:00.501,800] <inf> mqtt_simple: The MQTT simple sample started            
    [00:00:00.501,800] <inf> mqtt_simple: Disabling PSM and eDRX                    
    [00:00:00.502,624] <inf> mqtt_simple: LTE Link Connecting...                    
    [00:00:07.834,686] <inf> mqtt_simple: LTE Link Connected!                       
    [00:00:07.834,747] <inf> mqtt_simple: connect to test.mosquitto.org             
    [00:00:08.835,296] <inf> mqtt_simple: getaddrinfo result: -2                    
    [00:00:09.835,662] <inf> mqtt_simple: getaddrinfo result: -2                    
    [00:00:10.836,059] <inf> mqtt_simple: getaddrinfo result: -2                    
    [00:00:10.836,120] <err> mqtt_simple: getaddrinfo failed: -2                    
    [00:00:10.836,120] <err> mqtt_simple: Failed to initialize broker connection    
    [00:00:10.836,120] <err> mqtt_simple: client_init: -10 

    With 1.2.3 and 1.3.3 

  • So your source addresses and port don't change?

    May you have an idea, why the device is running into a timeout when setting the DNS manually? Most times it don't even get to the "LTE connected" state...
    Is there any other preferred method to set the DNS server, other than mentioned in this thread?

  • > So your source addresses and port don't change?

    My trace just contained one DNS request and a couple of CoAP/DTLS requests. On the modem side, the ip-address was stable (the port for the DNS to coap/dtls is changing, but then it's stable). The ip-breakout is then NATing that address/port, but this is not reflected in the modem-trace.

    > Is there any other preferred method to set the DNS server

    Did you modify the samples?

    Would it be possible, that you use the "samples/nrf9160/coap_client" without modification?

    I have no experience with "nrf_setdnsaddr". So far my devices are working without.

    (I'm currently focus on other tasks, if I go back to develop for the nRF9160 I will try to make some captures also with repeated DNS request. We will see, how that works then.)

  • Thank you for your detailled description!

    The traces are from the mqtt_simple sample, but I can do it for the CoAP sample. The only thing i basically changed in both samples is the preferred usage of NB-IoT (instead of CAT-M).

    CONFIG_LTE_NETWORK_MODE_NBIOT=y
    CONFIG_LTE_MODE_PREFERENCE_NBIOT=y
    
    # modem trace debugging
    CONFIG_NRF_MODEM_LIB_TRACE=y

    If I dont set the network mode to NBIOT it will not get any connection established.

    I have traced the (more or less original) CoAP Sample, just with NB-IoT and modem trace enabled:

    (I dont know if there is a difference between the trace collector and the trace collector preview, so I've done both - is just the conversion and live view in wireshark?)

    coap_without_dns.bin (from original trace collector)

    coap_without_dns.bin / coap_without_dns.pcapng

    But I dont see any DNS requests here...

    The DNS request from the older traces are only visible when manually setting the (i think it is the secondary, acc. to nrf_socket.h) DNS server with nrf_setdnsaddr()

Reply Children
  • I'm really wondering. I had never too much trouble with the nRF9160 and DNS. Only on some "fast starts" I need that retry. I use 1.3.1, 1.3.2 and 1.3.3

    Enable the trace and NB-IoT should not change the DNS, at least I didn't made that experience.

    I guess, you will need to "ping" someone from Nordic to have an modem expert having an look at your traces.

    The only left hint would be, to try a "AT%XFACTORYRESET=0" of the config.

Related