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

Need the nrf9160 example to transfer large data by TCP.

Hi,

I am a beginner to nrf9160.

I already can do send the large data to server. (Maybe not too large just about 15KB)

In my test, I will send that data in every 25 minutes.

The problem is it is not stable, It will stall after a few times.

I had add the reboot function to restart it.

But it is not a good way, I should prevent it happen.

Maybe something I miss or setting the wrong value.

So can you suggest some example code for me to reference?

Best regards,

Luther

  • Hi Luther, 
    Please make sure you have the latest modem firmware .

    And please add this fix into your environment: https://github.com/NordicPlayground/nrfxlib/pull/77

    Also please share any log output or even a modem trace would be beneficial.

  • Hi Martin,

    Thanks for your reply.
    I  already using the modem firmware v1.0.0.
    After I update the NCS, and update the two libbsd_nrf9160_xxaa.a files.
    It seems better now, it already running 10 hours and success to send the data to the server without error.
    I will continue testing.

    Thanks a lot.

    By the way, can you suggest a smart way to send the large data?
    Here is my send data function.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #define MAX_SOCKET_SEND_SIZE 512
    int sendLargeData(int sock, uint8_t *pSrc, int size)
    {
    int sendCount = 0;
    int sendIx = 0;
    int err = 0;
    int remainSize = size;
    while (remainSize > 0)
    {
    if (remainSize > MAX_SOCKET_SEND_SIZE)
    {
    sendCount = MAX_SOCKET_SEND_SIZE;
    }
    else
    {
    sendCount = remainSize;
    }
    err = blocking_send(sock, (pSrc + sendIx), sendCount, 0);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    I slice the total data to small pieces, and add a delay k_sleep(200) after send each piece.
    It seems after call the send() function, the data just keep in the buffer. Not finished the sending data.
    I don't know how to check the buffer is clear or not. So I just add a waiting time.

  • Please take a look at this TCP sample and use that as reference.

    (similar thread)

  • Hi Martin,

    I had look into tcp example, but it seem not what I want.
    That example is for receiving data. But it has a "blocking_send" function.
    So I had modify that tcp example to do the following test for sending large tcp data.
    The send buffer size is about 20KB
    Test 1: Just using "blocking_send" to send the data.
    Result:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    ***** Booting Zephyr OS v1.14.99-ncs2 *****
    LTE Link Connecting ...
    LTE Link Connected!
    TCP example getaddrinfo err: 0
    client_fd: 3
    connect err: 0
    Send total data size: 20479
    Test 1: blocking_send -1
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Actually it will fail to send data. The return code is -1.

    Test 2: I write a new function slice the buffer, every time just send 512 bytes. but without delay.
    Result:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    ***** Booting Zephyr OS v1.14.99-ncs2 *****
    LTE Link Connecting ...
    LTE Link Connected!
    TCP example getaddrinfo err: 0
    client_fd: 3
    connect err: 0
    Send total data size: 20479
    Send piece NoDelay: 512
    Send piece NoDelay: 512
    Send piece NoDelay: 512
    Send piece NoDelay: 512
    Send piece NoDelay: 512
    Send piece NoDelay: 512
    Send piece NoDelay: 512
    Error: send large data, c:-1, ix:3584
    Test 2: sendLargeData 3584
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    As you can see, the data send about 7 piece then got the error code -1.

    Test 3: Slice the buffer, every time send 512 bytes and add delay 200ms.
    Result:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    ***** Booting Zephyr OS v1.14.99-ncs2 *****
    LTE Link Connecting ...
    LTE Link Connected!
    TCP example getaddrinfo err: 0
    client_fd: 3
    connect err: 0
    Send total data size: 20479
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    Send piece delay 200ms: 512
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Yes, this time. The data had successful be send. But I wish I could do the optimum about the delay time.

    BTW, I am testing the NBIoT.


    Here is my prj.conf and main.c

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    prj.conf
    CONFIG_BSD_LIBRARY=y
    CONFIG_GPIO=n
    CONFIG_SERIAL=y
    CONFIG_STDOUT_CONSOLE=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_TEST_RANDOM_GENERATOR=y
    CONFIG_NETWORKING=y
    CONFIG_NET_BUF_USER_DATA_SIZE=1
    CONFIG_NET_SOCKETS_OFFLOAD=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_POSIX_NAMES=y
    CONFIG_NET_RAW_MODE=y
    CONFIG_TRUSTED_EXECUTION_NONSECURE=y
    CONFIG_LOG=n
    CONFIG_LOG_DEFAULT_LEVEL=4
    CONFIG_HEAP_MEM_POOL_SIZE=1024
    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Remember to modify the #define TCP_HOST and TCP_PORT to your test server.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    /*
    * Copyright (c) 2018 Nordic Semiconductor ASA
    *
    * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
    */
    #include <zephyr.h>
    #include <net/socket.h>
    #include <stdio.h>
    #include <uart.h>
    #include <string.h>
    #include <lte_lc.h>
    #define TEST_SEND_WITH_DELAY
    //#define DO_TEST_1
    #define TCP_HOST "test.com"
    #define TCP_PORT "8080"
    #define RECV_BUF_SIZE ((80 * 24) + 1)
    #define MAX_SOCKET_SEND_SIZE 512
    #define SEND_BUF_SIZE (20 * 1024)
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX