bt_mesh_transport: Out of segment buffers

hi all i use vendor model to send data on mesh, i send data from one nrf52840 DK to one else and receive data correctly until a while after that sometimes data isn't send and the Out of segment buffers error occur when i increase BT_MESH_SEG_BUFS just more time later the error occur like buffer overflowing , i program in VScode and nRFconnect extentions. thanks for any helps

int bt_mesh_gap2mesh_message_send(struct bt_mesh_gap2mesh *gap2mesh,
				  const uint8_t *msg)
{

    struct net_buf_simple *buf = gap2mesh->model->pub->msg;
	
    bt_mesh_model_msg_init(buf, BT_MESH_GAP2MESH_OP_MESSAGE);

    size_t msg_len = strnlen(msg, CONFIG_BT_MESH_GAP2MESH_MESSAGE_LENGTH);

    if (msg_len > 0) {

        net_buf_simple_add_mem(buf, msg, msg_len);
		net_buf_simple_add_u8(buf, '\0');

    } else {
        // If the message is empty, return an error or handle it accordingly
        return -EINVAL;
    }
}
#
# Copyright (c) 2021 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
CONFIG_NCS_SAMPLES_DEFAULTS=y

# Deffered logging helps improve LPN power consumption
# when friendship is established.
CONFIG_LOG_MODE_DEFERRED=y
CONFIG_LOG_BUFFER_SIZE=4096

# General configuration
CONFIG_LOG=y
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_HWINFO=y
CONFIG_DK_LIBRARY=y
CONFIG_PM_SINGLE_IMAGE=y
CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x8000

# Bluetooth configuration
CONFIG_BT=y
CONFIG_BT_COMPANY_ID=0x0059
CONFIG_BT_DEVICE_NAME="MESH NET"
CONFIG_BT_L2CAP_TX_MTU=69
CONFIG_BT_L2CAP_TX_BUF_COUNT=20
CONFIG_BT_OBSERVER=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_SETTINGS=y

CONFIG_BT_EXT_ADV=y
CONFIG_BT_EXT_ADV_MAX_ADV_SET=20
CONFIG_BT_MAX_CONN=3

# Disable unused Bluetooth features
CONFIG_BT_CTLR_DUP_FILTER_LEN=0
CONFIG_BT_CTLR_LE_ENC=n
CONFIG_BT_DATA_LEN_UPDATE=n
CONFIG_BT_PHY_UPDATE=n
CONFIG_BT_CTLR_CHAN_SEL_2=n
CONFIG_BT_CTLR_MIN_USED_CHAN=n
CONFIG_BT_CTLR_PRIVACY=n

# Bluetooth mesh configuration
CONFIG_BT_MESH=y
CONFIG_BT_MESH_RELAY=y
CONFIG_BT_MESH_FRIEND=y
CONFIG_BT_MESH_ADV_BUF_COUNT=60
CONFIG_BT_MESH_RX_SEG_MAX=32
CONFIG_BT_MESH_TX_SEG_MAX=32
CONFIG_BT_MESH_PB_GATT=y
CONFIG_BT_MESH_GATT_PROXY=y
CONFIG_BT_MESH_PROXY_USE_DEVICE_NAME=y
CONFIG_BT_MESH_DK_PROV=y

# Bluetooth mesh models
CONFIG_BT_MESH_ONOFF_SRV=y

# Enable the LBS service
#CONFIG_BT_LBS=y
#CONFIG_BT_LBS_POLL_BUTTON=y

# my additional 
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_BT_RX_STACK_SIZE=8192
# CONFIG_BT_MESH_ADV_STACK_SIZE=1024

CONFIG_BT_MESH_TX_SEG_MSG_COUNT=255
CONFIG_BT_MESH_RX_SEG_MSG_COUNT=255
CONFIG_BT_MESH_SEG_BUFS=32
CONFIG_BT_MESH_TX_SEG_RETRANS_COUNT=2

# CONFIG_BT_HOST_CRYPTO=n
CONFIG_BT_MESH_ADV_LEGACY=n
# CONFIG_BT_HCI_HOST=y
# CONFIG_BT_HCI=y 
CONFIG_BT_RPC_STACK=n
CONFIG_GPIO=y
CONFIG_POSIX_API=y

  • and the payload code is 


    #if defined Publish_ON
        {
            k_mutex_lock(&loop, K_FOREVER);
                 for (int i = 0; i < 7; i++)
                 {
                  sprintf(print_string + i * 2, "%02X", repeat_payload[i]);
                 }

                // Print payload to mesh_string
                for (int i = 0; i < 65; i++)
                {
                    sprintf(print_string + i * 2, "%02X", payload[i]);
                }
                public_send_message(&print_string);
                Erase_buffers();
                publish = true;

            k_mutex_unlock(&loop);
        }
    #else
        {
            Erase_buffers();
        }
    #endif
  • Hi Mohamad, 


    Could you give some more information about the data you send. How many bytes do you send each time and how often do you send. 
    Mesh network is not really made for high throughput especially with segmented message. There are a lot of overhead and retransmission if any packet missing. So there could be a chance that you are hitting the limit. 

    If you stop for a while and then continue transmitting do you still receive the "Out of segment buffer" ? 

    Can you post the error log /screenshot ? 

  • Hi Hung Bui Thank you very much for your reply, yes of course, I'm on weekend now, tomorrow I can send a screenshot of the error log, but until then, I'm working on a project that receives data from a number of sensor tags and adds information In the BLE layer and mesh network, the length of the data reaches 145 bytes, each sensor tag sends data once a minute. The problem appears there is that the number of sensor tags increases, so there may be a large number of sensor tag data in one minute. It is not in my control when each sensor tag sends the data from this one minute, and as soon as I receive the data, I process it and publish it in the mesh network.

  • Hi Mohamad, 
    I would suggest to implement a buffer in your device to catch the data from the sensor tag and wait for the mesh buffer to be ready to continue. 
    So if you receive Out of segment buffer, you can pause the transmission for a while and continue later. 

    My assumption is that since the sensor tag only transmit one per minute with small data, there isn't a lot of data to send, even if you have large amount of tags. 

  • Thanks, I'll try this and try to find a way when the mesh buffer is ready.

Related