nRF9160 fails to connect to server with IP and port number. Gives 116 (timeout error)?

Hello,

I have nRF9160, modem FW = 1.3.6 and nrf sdk version 2.7.0.

I am trying to create an outgoing socket with connects to specific port num and ip address but I am getting timeout error with value 116. I am attaching the code snippet below for your reference. 

int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (sock < 0)
    {
        printk("Failed to create socket: %d\n", errno);
        return AtJsonTypes::CONNECT_FAILED;
    }
    struct sockaddr_in server;
    server.sin_family = AF_INET;
    server.sin_port = htons(SERVER_PORT);
    if (inet_pton(AF_INET, SERVER_IP, &server.sin_addr) <= 0)
    {
        printk("Invalid address/ Address not supported\n");
        close(sock);
        return AtJsonTypes::CONNECT_FAILED;
    }

    if (CellConnection::IsCellConnected() == CellConnection::CONNECTED)
    {
        printk("Modem is conneted to network\n");
    }
    else
    {
        printk("No modem connection\n");
        return AtJsonTypes::CONNECT_FAILED;
    }

    int retries = 3;
    while (retries > 0)
    {
        printk("Device IP is %s and Port num is %d\n", SERVER_IP, SERVER_PORT);
        int ret = connect(sock, (struct sockaddr *)&server, sizeof(server));
        if (ret == 0)
        {
            // Connection successful
            printk("Connected to %s at port num %d\n", SERVER_IP, SERVER_PORT);
            break;
        }
        else if (errno == ETIMEDOUT)
        {
            // Handle timeout
            printk("Failed to connect socket timeout: %d\n", errno);
            retries--;
            sleep(1); // Wait before retrying
        }
        else
        {
            // Handle other errors
            printk("Failed to connect socket: %d\n", errno);
            break;
        }
    }
Could you please help?
Parents Reply Children
  • ent  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -Wl,-no-pie  9160/nrfxlib/crypto/nrf_cc310_platform/lib/cortex-m33/soft-float/no-interrupts/libnrf_cc310_platform_0.9.19.a && cd 9160/nrf9160/build/mcuboot/zephyr && /usr/bin/cmake -E true
    zephyr-sdk-0.16.5-1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: zephyr/zephyr_pre0.elf section `noinit' will not fit in region `RAM'
    zephyr-sdk-0.16.5-1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: region `RAM' overflowed by 3784 bytes
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    [4/311] Generating include/generated/offsets.h

  • I tried to enable 

    CONFIG_NRF_MODEM_LIB_TRACE config and getting the above attached which is RAM overflow. I tried reducing the buffers but impact on RAM consumption is not see. Can you please suggest a solution. Also, can you tell, how much memory it takes when modem trace is enabled?
Related