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

nrf52840 gsm modem sim800 tcp client socket send error

Hi,

I created an example using gsm_modem application, after network connected, I create tcp client socket then send data to the server. After several sendings, I got the packet allocation failed.

char buff[10] = "abcdef\n";
int len = sizeof(buff);

// ... after network connected in main function

int sockfd, connfd;
struct sockaddr_in servaddr, cli;
  
// socket create and varification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
    printk("socket creation failed...\n");
    return;
}

printk("Socket successfully created..\n");

int  IP = 104*256*256*256 + 168*256*256 + 98*256 + 15;   // 104.168.98.15

// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(IP);
servaddr.sin_port = htons(2120);

// connect the client socket to server socket
if (connect(sockfd, (struct sockaddr_in*) & servaddr, sizeof(servaddr)) != 0)
{
    printk("connection with the server failed...\n");
    return;
}

printk("connected to the server..\n");

while (1) 
{
    send(sockfd, buff, 10, 0);
    k_sleep(K_SECONDS(2));
}


Error log:
[00:00:29.692,749] [1;31m<err> net_tcp: conn: 0x200133c0 packet allocation failed, len=10[0m
[00:00:29.892,944] [1;31m<err> net_tcp: conn: 0x200133c0 packet allocation failed, len=10[0m
[00:00:30.093,139] [1;31m<err> net_tcp: conn: 0x200133c0 packet allocation failed, len=10[0m
[00:00:30.293,334] [1;31m<err> net_tcp: conn: 0x200133c0 packet allocation failed, len=10[0m
[00:00:30.493,530] [1;31m<err> net_tcp: conn: 0x200133c0 packet allocation failed, len=10[0m
[00:00:30.693,725] [1;31m<err> net_tcp: conn: 0x200133c0 packet allocation failed, len=10[0m
[00:00:30.893,920] [1;31m<err> net_tcp: conn: 0x200133c0 packet allocation failed, len=10[0m
[00:00:31.094,116] [1;31m<err> net_tcp: conn: 0x200133c0 packet allocation failed, len=10[0m
[00:00:31.294,311] [1;31m<err> net_tcp: conn: 0x200133c0 packet allocation failed, len=10[0m
[00:00:31.494,506] [1;31m<err> net_tcp: conn: 0x200133c0 packet allocation failed, len=10[0m
[00:00:31.694,702] [1;31m<err> net_tcp: conn: 0x200133c0 packet allocation failed, len=10[0m

Do you know how to fix this issue?
Thanks.

Parents Reply
  • Hi Didrik,

    Is the modem connected to the network?

    Yes, it connected to the internet.

    Do you receive the packets in the other end?

    Yes, I received some packages in the other end.

    Does the modem provide you with any logs that could help you figure out what is wrong?
    No, the modem in ppp mode, there is no error log.

    Do you know how to increase internal buffer size of gsm modem driver?

Children
  • Buffer sizes in NCS and Zephyr are generally configured by Kconfig.

    So the best way to find what buffers you can change, and what options to set is to look through the Kconfig files of the relevant module (driver, library, subsystem, etc.).

    Note that the best practice is to set your desired values in the prj.conf file, not changing the defaults in the Kconfig files.

    Also, when setting an option in prj.conf, it must be prefixed with CONFIG_.

    After looking through some of the Kconfig files in the IP stack and GSM modem driver, these options seems most relevant:

    NET_TX_STACK_SIZE

    NET_BUF_DATA_SIZE or NET_BUF_DATA_POOL_SIZE

    HEAP_MEM_POOL_SIZE

  • I run debug mode on Segger Ide causing this issue. When I let the board running without debugging, it works well.

    Thanks for your support.

Related