This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf9160 getaddrinfo() return error -11

Hello,

it's been a couple of days that i have a problem with NRF9160DK.

The problem is related to function getaddrinfo() that is now permanently returning -11, whatever i do. The code i'm using as a base (and, i repeat, that worked without any changes up to about 1 week ago) is the http example. This code snippet is where the problem happens:

void http_motherRegister(u32_t mbAddress, u8_t batt_status)
{
    struct sockaddr_in local_addr;
    struct addrinfo *res;
    int send_data_len;
    int num_bytes;
    int mtu_size = MAX_MTU_SIZE;
    char message_buf[MAX_MESS_SIZE];
    char send_buf[SEND_BUF_SIZE];
    
    local_addr.sin_family = AF_INET;
    local_addr.sin_port = htons(0);
    local_addr.sin_addr.s_addr = 0;

    printk("\n\r\n\rHTTP motherRegister routine started\n");

    int err = getaddrinfo(HTTP_HOST, NULL, NULL, &res);

    printk("getaddrinfo err: %d\n", err);
    //THE BOARD CRASHES HERE
    ((struct sockaddr_in *)res->ai_addr)->sin_port = htons(HTTP_PORT);

This is what my serial print is:

*** Booting Zephyr OS build v2.1.99-ncs1-4-gc025ef3dd566  ***
+CEREG: 2,"FFFE","FFFFFFFF",7,0,0,"11100000","11100000"
+CEREG: 2,"80F3","04987148",9,0,0,"11100000","11100000"
+CEREG: 4,"80F3","04987148",9,0,15,"11100000","11100000"
+CEREG: 4,"FFFE","FFFFFFFF",9,0,15,"11100000","11100000"
+CEREG: 2,"90EA","010F0971",9,0,15,"11100000","11100000"
+CEREG: 2,"90EA","010F0971",9,0,13,"11100000","11100000"
+CEREG: 2,"FFFE","FFFFFFFF",9,0,13,"11100000","11100000"
+CEREG: 2,"7B88","04DCDD88",9,0,13,"11100000","11100000"
+CEREG: 5,"7B88","04DCDD88",9,,,"11100000","11100000"
LAP Motherboard State machine initializing...

SM State: INIT

SM State: SERVER_REG

HTTP motherRegister routine started
getaddrinfo err: -11

*** Booting Zephyr OS build v2.1.99-ncs1-4-gc025ef3dd566  ***
Flash regionDomainPermissions
00 0x00000 0x08000 Securerwxl

I really don't know what could be the cause. From what i understand from the serial print the board connects (+CEREG: 5) and the software boots normally (execute a state machine i coded), but when getaddrinfo() is called for DNS resolution it returns error and reboots the board.

Some info on my hardware:

- NRF9160DK (last firmware)

- nrf9160 modem firmware 1.1.1 (and now 1.2.0, same behaviour)

- SIM IBasis (still 90% of data plan available)

Things i tried:

- Changed the HTTP_HOST define from my host to "ptsv2.com" to make a test --> still not working

- Updated the modem firmware to version 1.2.0 (from 1.1.1) --> still not working

Parents Reply
  • Hi,

     

    frax84 said:
    Could it be a temporary network provider issue?

    It could be, but what has changed since the last time it was working?

    Now you are on NB1, were you always on NB1, or has it recently done the switch from LTE M1 to NB1?

     

    Is there anything out-of-the-ordinary (or different from a previous working situation) if you run at_client? Is it still connecting to the same provider?

     

    Kind regards,

    Håkon

Children
  • It could be, but what has changed since the last time it was working?

    Absolutely nothing, at least from the development code point of view. I even used a working code backup from my github to be sure to have not messed up my code, but nothing changed. From the network side, unfortunately i didn't saved the details about the network, so i'm not sure if i'm connecting on the same network as the previous 2 (working) months. Of course this could be a good point. If i'm connected on a different network this one could not provide DNS service. I'll take note of the full CEREG string from now on.

    Now you are on NB1, were you always on NB1, or has it recently done the switch from LTE M1 to NB1?

    I'm in Rome, Italy. As far as i know in Italy we have no national LTE-M network deployed. The biggest providers (Vodafone and TIM [Telecom Italia Mobile]) deployed national NB-IoT coverage, so yes, i have always been on NB1 (9 on CEREG).

    This is very common error to see if your local carrier does not provide DNS servers. You could try setting it manually, as shown here, and see if that works?

    I'm happy to say that, with manual DNS setup, it works!

    For people who could occur in the same problem i did, this is the function i used:

    static void modem_configure(void)
    {
      if (IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT)) {
        /* Do nothing, modem is already turned on
        * and connected.
        */
      } else {
        //Set manually DNS server
        struct nrf_in_addr dns;
        dns.s_addr = 134744072; // Google DNS, 8.8.8.8 in u32 rapresentation
        int err = nrf_setdnsaddr(2, &dns);
        if (err ==0) {
          printk("DNS correctly set\n");
        } else {
          printk("Error %d, DNS not set\n", err);
        }
        
        //Init network connection
        printk("LTE Link Connecting ...\n");
        err = lte_lc_init_and_connect();
        __ASSERT(err == 0, "LTE link could not be established.");
        printk("LTE Link Connected!\n");
        }
    }

    Please remember to set properly .config file

    Thanks for the nice and fast support!

    Frax

  • Please remember to set properly .config file

    Can you please explain what you mean @frax84? I have used this code but I am still getting a "error -11" on getaddrinfo

  • Hi JDoc,

    sorry for the delay in answer but i was still on vacation. Before anything else, i want to share with you this post:

    https://devzone.nordicsemi.com/f/nordic-q-a/61822/nrf9160-fails-to-connect-to-nb-iot

    This is the continuation of the post we're writing on right now. In that post you will receive further indications about how to solve your issue with error -11. Actually the post linked represents the method that really solved my problems so i suggest you to read it.

    By the way, returning to what you asked me, as you probably well know, many configuration parameters need to be set on the configuration file of  the project depending on the features needed to work on the project  itself (es. NB-IoT? LTE-M? DNS? IP?). The file i'm speaking about is "prj.conf".

    I don't know which features you need in your project and i would like to avoid to confuse you, so i prefer to not share my prf.conf file settings. By the way, if you still don't find any solution after this post, i can share it.

    Regards,

    Frax 

Related