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

BLE NUS data not sending > 20bytes

Hi,

I have tested the ble_nus code in NCS v1.4.2

where i can't send 250 bytes

I want to send 250 bytes to ble nus data send for 100 ms once

How to enable data send of 250 bytes 100ms once

  • Hi 

    If you add the CONFIG_BT_NUS_UART_BUFFER_SIZE parameter to your prj.cnf file you should be able to change the UART data size from the default 20 bytes to something larger. 

    Best regards
    Torbjørn

  • CONFIG_BT_NUS_UART_BUFFER_SIZE = 500

    is it possible

    does it need to set phy = 2M and ATT-MTU ?

    and here i attach my prj.conf

    
    
    #CONFIG_NCS_SAMPLES_DEFAULTS=y
    
    #BT config
    CONFIG_BT=y
    CONFIG_BT_DEBUG_LOG=y
    CONFIG_BT_MAX_CONN=2
    CONFIG_BT_MAX_PAIRED=1
    CONFIG_BT_SMP=y
    CONFIG_BT_L2CAP_TX_BUF_COUNT=5
    CONFIG_BT_PERIPHERAL=y
    
    #Devie Name config
    CONFIG_BT_DEVICE_NAME="Headset"
    CONFIG_BT_DEVICE_APPEARANCE=961
    
    #Device Info service config
    CONFIG_BT_DIS=y
    CONFIG_BT_DIS_PNP=y
    CONFIG_BT_DIS_MANUF="NordicSemiconductor"
    CONFIG_BT_DIS_PNP_VID_SRC=2
    CONFIG_BT_DIS_PNP_VID=0x1915
    CONFIG_BT_DIS_PNP_PID=0xEEEF
    CONFIG_BT_DIS_PNP_VER=0x0100
    
    #Battery Service Config
    CONFIG_BT_BAS=y
    
    #HID config
    CONFIG_BT_HIDS=y
    CONFIG_BT_HIDS_MAX_CLIENT_COUNT=1
    CONFIG_BT_HIDS_DEFAULT_PERM_RW_ENCRYPT=y
    CONFIG_BT_GATT_UUID16_POOL_SIZE=40
    CONFIG_BT_GATT_CHRC_POOL_SIZE=20
    
    CONFIG_BT_LL_SOFTDEVICE_DEFAULT=y
    CONFIG_BT_CONN_CTX=y
    
    # Enable the NUS service
    CONFIG_BT_NUS=y
    
    # Enable bonding
    CONFIG_BT_SETTINGS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_SETTINGS=y
    CONFIG_BT_SETTINGS_CCC_STORE_ON_WRITE=y
    
    # Enable DK LED and Buttons library
    CONFIG_DK_LIBRARY=y
    
    # This example requires more workqueue stack
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    
    # Enable the UART driver
    CONFIG_UART_ASYNC_API=y
    CONFIG_NRFX_UARTE1=y
    CONFIG_SERIAL=y		
    
    CONFIG_GPIO=y
    
    # Make sure printk is not printing to the UART console
    CONFIG_CONSOLE=y
    CONFIG_RTT_CONSOLE=n
    CONFIG_UART_CONSOLE=y
    CONFIG_PRINTK=y
    
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    
    # Config logger
    CONFIG_LOG=y
    CONFIG_LOG_BUFFER_SIZE=2048
    CONFIG_LOG_PRINTK=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=n
    
    CONFIG_ASSERT=y
    
    # Clock configuration
    CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH=y
    
    # I2C Enable
    CONFIG_I2C=y
    CONFIG_SENSOR=y
    
    #MLX90393 Enable
    CONFIG_MLX90393=y
    CONFIG_MLX90393_TRIGGER_GLOBAL_THREAD=y
    
    # NFC configuration
    CONFIG_NFC_OOB_PAIRING=n
    
    # Optimize for debug
    CONFIG_DEBUG_OPTIMIZATIONS=y
    
    # Added
    CONFIG_BT_GATT_CLIENT=y
    
    CONFIG_BT_USER_DATA_LEN_UPDATE=y
    CONFIG_BT_RX_BUF_LEN=260
    CONFIG_BT_ATT_TX_MAX=10
    CONFIG_BT_ATT_PREPARE_COUNT=2
    CONFIG_BT_CONN_TX_MAX=10
    CONFIG_BT_L2CAP_TX_BUF_COUNT=10
    CONFIG_BT_L2CAP_TX_MTU=252
    CONFIG_BT_L2CAP_RX_MTU=252
    CONFIG_BT_CTLR_TX_BUFFER_SIZE=251
    CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
    

    i am reading 13 sensors through TWI and send the calculated value at every 100ms

    data sample be

    x,-3018,5826,-1944,-4055,6151,1699,-5840,-2676,7394,-6113
    y,-5767,5830,-7638,5952,-6185,5262,-5650,5682,-6004,7257
    z,-10541,10810,-16294,10959,11348,12433,-13132,10381,-11102,-11281

    character will be 150 - 250 it varies

    after connected to iphone and uart notify enabled

    after 4 to 7 mins the device get restart and during debug found

  • Hi 

    First off, I wouldn't recommend sending sensor data in ASCII format like this. It is much more efficient to send the raw data directly, and do the ASCII conversion on the phone side. 

    Then you get less data to send over BLE, and you get a consistent data length for each update. 

    Using 2M PHY and longer ATT MTU should speed up the throughput definitely. Have you had a look at the throughput example in the SDK for an idea of how to increase throughput?

    Sunil vignesh said:

    CONFIG_BT_NUS_UART_BUFFER_SIZE = 500

    is it possible

    This should be possible, yes. In general characteristics can be up to 512 bytes in length, but using long characteristics like this is not always the most efficient since the packet might have to be split up into several smaller packets over the air (depending on the max data length setting). 

    Have you added any error handling to the function you use to send data, in order to check if it ever returns an error?

    Best regards
    Torbjørn

  • HI ,

    following code line shows my data sending through NUS

     length = sprintf(data, "\nx,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\ny,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\nz,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", (int16_t)mlx90393_config[0].reading[MLX90393_x],
          (int16_t)mlx90393_config[1].reading[MLX90393_x],
          (int16_t)mlx90393_config[2].reading[MLX90393_x],
          (int16_t)mlx90393_config[3].reading[MLX90393_x],
          (int16_t)mlx90393_config[4].reading[MLX90393_x],
          (int16_t)mlx90393_config[5].reading[MLX90393_x],
          (int16_t)mlx90393_config[6].reading[MLX90393_x],
          (int16_t)mlx90393_config[7].reading[MLX90393_x],
          (int16_t)mlx90393_config[8].reading[MLX90393_x],
          (int16_t)mlx90393_config[9].reading[MLX90393_x],
          (int16_t)mlx90393_config[0].reading[MLX90393_y],
          (int16_t)mlx90393_config[1].reading[MLX90393_y],
          (int16_t)mlx90393_config[2].reading[MLX90393_y],
          (int16_t)mlx90393_config[3].reading[MLX90393_y],
          (int16_t)mlx90393_config[4].reading[MLX90393_y],
          (int16_t)mlx90393_config[5].reading[MLX90393_y],
          (int16_t)mlx90393_config[6].reading[MLX90393_y],
          (int16_t)mlx90393_config[7].reading[MLX90393_y],
          (int16_t)mlx90393_config[8].reading[MLX90393_y],
          (int16_t)mlx90393_config[9].reading[MLX90393_y],
          (int16_t)mlx90393_config[0].reading[MLX90393_z],
          (int16_t)mlx90393_config[1].reading[MLX90393_z],
          (int16_t)mlx90393_config[2].reading[MLX90393_z],
          (int16_t)mlx90393_config[3].reading[MLX90393_z],
          (int16_t)mlx90393_config[4].reading[MLX90393_z],
          (int16_t)mlx90393_config[5].reading[MLX90393_z],
          (int16_t)mlx90393_config[6].reading[MLX90393_z],
          (int16_t)mlx90393_config[7].reading[MLX90393_z],
          (int16_t)mlx90393_config[8].reading[MLX90393_z],
          (int16_t)mlx90393_config[9].reading[MLX90393_z]);
    
      if (bt_nus_send(NULL, data, length)) {
        LOG_WRN("Failed to send data over BLE connection");
      }
    

    How to send the raw data in NUS

Related