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

  • complete history for recreation:

    1) disabled the factory reset command -> works fine

    2) disabled all other AT commands -> works fine

    3) flashed the "old" mqtt_simple sample with the nrf_setdnsaddr as used now -> doesn't work (log stops at LTE connecting / AT+CFUN=1, and device reboots after ~20s)

    4) flashed version from (2) without AT commands -> doesn't work, similar behaviour like (3) but without rebooting, waited 3min+ but with no further response

    5) enabled the both AT Commands %HWVERSION and %SHORTSWVER -> LTE connected after ~58s, getaddrinfo worked fine and mqtt connected

    6) to verify, i flashed the old mqtt_simple sample from (3) and then the new without AT commands from (4), same behaviour, no reaction for like more than 3 minutes

    7) flashed new mqtt_simple sample with the two AT cmds and then nrf_setdnsaddr -> no reaction for >3 min

    8) enabled factory reset -> connection established after 20s, getaddrinfo worked and mqtt connected

    9) disabled factory reset again -> workes, sometimes connection is established in under 10s, sometimes it needs up to a minute (cycles by pressing the reset button)

    So in my opinion: the modem writes something to an internal NVM, this is cleared by a factory reset via the AT command %XFACTORYRESET=0

    And to reproduce from a new mqtt_simple sample at our custom board with MFW 1.3.3:

    1) created a new mqtt_simple sample

    2) created the build configuration with enabled debug options

    3) added in in prj.conf

    #LTE link control
    CONFIG_LTE_NETWORK_MODE_NBIOT=y
    CONFIG_LTE_MODE_PREFERENCE_NBIOT=y
    
    # modem trace debugging
    CONFIG_NRF_MODEM_LIB_TRACE=y

    ### build and program: lte connects, getaddrinfo failes with -2

    mqtt_simple_1.bin / mqtt_simple_1.pcapng


    4) added to modem_configure() after disabling PSM and eDRX:

    #include <nrf_socket.h>
    
    
    int err;
    char response[128];
    static struct nrf_in_addr dns_google;
    dns_google.s_addr = 134744072; // Google DNS, 8.8.8.8
    err = nrf_setdnsaddr(1, &dns_google, sizeof(dns_google));
    LOG_INF("DNS set result %d - %d", err, errno);

    ### build and program: lte connects, getaddrinfo works, mqtt connects

    mqtt_simple_2_setdnsaddr.bin  / mqtt_simple_2_setdnsaddr.pcapng

    conclusio: something must have written something to the modem's NVM to make this strange behaviour plus we dont get a primary DNS from our provider on our hardware (why? I dont know). but with a "clean" board after doing the factory reset AT command it works - even without doing the factory reset everytime. (I dont know what I added to the mqtt_simple sample before trying to add the DNS server via nrf_setdnsaddr at the first try)

    Added this small snippet to our code and flashed it to a "clean" hardware - works fine - also with our sever.

    Looking forward to hear something from a modem expert, we are trying to work with this workaround at the moment. If needed, i can upload our 3 mqtt_simple samples.

    Thank you Achim for your big help!

    BR Thomas

  • > %XFACTORYRESET=0

    The AT commands are all documented, that contains also the info, if the config is stored in the NVM.

    I ment to use that factory-reset only once, I do so, if I have the feeling, that a device doesn' behave proper. That mainly happens, if I use a device for a lot testing, changing the configuration again and again. The sometimes, a factory-reset helps.

    From your latest capture (mqtt_simple_2_setdnsaddr.pcapng):

    The first DNS request shows 10.160.202.185 as source-ip. That "timesout".

    The second shows 10.84.42.235 and that succeeds. The device is then using that address for further requests.

    I'm still worried about the address change. Lets look forward, what Nordic finds in that trace.

  • tomtomtom2401 said:
    I don't find any config option for PCO/ePCO in Kconfig

    You can enabling

    CONFIG_PDN=y
    CONFIG_PDN_LEGACY_PCO=y

  • Thank you for the replay Hakon, in the meantime we got the info from the provider, that ePCO wasn't enabled in their network. After getting enabled by them, everythink works fine. 

    But the question remains, why it works on the devkit without setting any DNS or the PCO config...

  • Maybe you read the ePCO/PCO usage of your DK?

    "AT%XEPCO?"

    In my experience, without a "%XFACTORYRESET=0" once, you do not really know, which configuration may be stored in the NVM.

Reply Children
Related