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

Proxy and NUS in one application

Hi,

We are encountering a problem when we try to avail Nordic UART service (NUS) and Mesh service in one application. The problem statement is that after Provisioning, when we disconnect through the nRF Mesh application and go to nRF Connect application to use NUS, we can send only 20 Bytes of data.

But when we dump just the NUS code we availed the service of sending 244 Bytes of data. According to my knowledge there are two main functions in the main.c file of NUS, where the ATT packet size is set after the changes in sdk_config.h.

The first function is the

nrf_ble_gatt_init(&m_gatt, gatt_evt_handler);

2nd function

nrf_ble_gatt_att_mtu_periph_set(&m_gatt, NRF_SDH_BLE_GATT_MAX_MTU_SIZE);

 

When I added these functions to the main.c file, I could send 244 Bytes of data, but the nRF Mesh application does not even initialize the connection with the DK and throws an app_error_weak.c.

 

Hence we are not in a position to provision the node and after disconnecting we cannot push 240 Bytes of data via the nRF Connect application.

We are using nRF52840 DK, on SES platform.

Mesh 2.2V along with 15.0.0.

Kind Regards,

Shrinidhi Bhat

  • Hi Hung,

    We have gotten a partial solution after some tests, hence sorry for the late reply. I will update you with what has been done and the steps afresh:

    1) After dumping the code, in the nRF Connect app we can see NUS and Mesh Proxy service. (4 service)

    2) We Provision the node, bind app keys and give all the addresses. (All in debug mode)

    3) When we open the nRF Connect app again, we cannot see NUS anymore (Probably because we availed the Mesh proxy service ) hence there are only 3 services [Generic access, Generic attribute and Mesh Proxy service]

    4) We shut the debug mode and rerun it again (F5) and we can see NUS now in nRF Connect app now. We can now send 240 bytes of data too!!!!

    Hence there are 4 services again.

    BUT

    When we dump the code we cannot avail both the services. My understanding is that the Mesh proxy service is overriding the NUS and hence re-flashing again after creating a proxy mesh network will allow us to send 240 bytes of data. I believe we have 2 Primary services apart from the other generic ones which is causing the problem.

    Now the Question is:

    Q) How do I make the NUS to fall inside the Mesh proxy service. I should be able to use NUS after Provisioning and disconnecting from Mesh network. I don't want one service to override the other.

    Kind Regards,

    Shrinidhi Bhat

  • Hi Shrinidhi

    I think I can explain this. The provisioning process is combined of 2 phases, provisioning and configuration. They are performed on different GATT profile. A PB-GATT profile and the Proxy GATT profile respectively. 

    PB-GATT is replaced by Proxy GATT after the device provisioned. In our current softdevice we don't support removing services (only adding) so what we do is to disable softdevice and enable it again and add the Proxy Gatt service in. 

    Because of this your NUS service is removed after the device is provisioned. And when you reset the device, it will be added as normal. 

    The code that does the re-initialization of the Proxy GATT is inside mesh_provisionee.c. You can find at NRF_MESH_PROV_EVT_LINK_CLOSED event if the device is provisioned, gatt_database_reset() will be called. This function will disable mesh and then disable softdevice in mesh_evt_handler(). After the softdevice re-enabled (by NRF_SDH_EVT_STATE_DISABLED event) , inside NRF_SDH_EVT_STATE_ENABLED event you can find we initialize proxy_init(). 

    Here is where you can init your NUS service again. 

  • Hi Hung,

    Thank you so much for the valuable input. Now I understand why it disconnects and reconnects again during provisioning. Coming back to the problem we are facing.

    My uart_service is initialized in the main.c file. I just externed it and called it right after proxy_init [A very beginner approach]. It is throwing a app_weak_error (Mesh error). 

    Now my next approach would be to initialize the same inside ble_nus.c instead of main.c and calling the header file, but I'm not sure that is will give me the right result.

    What would your approach be? I also don't know how to interpret the app_weak_error.c.

    Best Regards,

    Shrinidhi Bhat

  • Please post your log. 

    You can use addr2line to debug which line throwing the error. Have a look here

  • So, I did both the steps as mentioned in my previous reply, but both threw the same error. To make it simple I added Log files after before and after uart_service_init (NUS). The mesh_provisionee.c chunk of code is given below along with the Log file.

    //************This is the chunk of code from mesh_provisionee.c 
    #if GATT_PROXY
                mesh_key_index_t key_index;
                uint32_t count = 1;
                nrf_mesh_key_refresh_phase_t kr_phase;
    
                APP_ERROR_CHECK(dsm_subnet_get_all(&key_index, &count));
                APP_ERROR_CHECK(dsm_subnet_kr_phase_get(dsm_net_key_index_to_subnet_handle(key_index),
                                                        &kr_phase));
    
                proxy_init();
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "AFTER :proxy_init\n"); //These lines were added
                uart_services_init();
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "AFTER :uart_services_init\n"); //These lines were added
    
                /* NOTE: Even though the device supports the GATT proxy feature, enabling the proxy
                 * state is _not_ required. The Node Identity will be advertised for 60s, if the proxy
                 * is enabled, the device will start advertising the Network ID afterwards. The default
                 * state for the proxy feature is set with `PROXY_ENABLED_DEFAULT`.
                 */
                NRF_MESH_ERROR_CHECK(proxy_node_id_enable(NULL, kr_phase));
    //End of code sample
    //***************************Start of Log file 
    //1st Log is right after dumping the code (Initializations)
    <t:        588>, main.c,  856, Initializing and adding models
    <t:        592>, ble_nus.c,  506, NUS_DATA_HANDLER being assigned to nus_init in ble_nus.c
    <t:        596>, ble_nus.c,  388, Inside ble_nus_init in ble_nus.c
    <t:       5457>, mesh_gatt.c,  553, Effective MTU Packet size of Mesh_GATT: 244
    <t:       5475>, main.c, 1111, Device UUID : 005955AA000000004BB1BF73B8371451
    
    //2nd Log is after connecting to the node
    <t:     281713>, main.c,  784, Successfully updated connection parameters
    <t:     281717>, mesh_gatt.c,  714, Log inside the mesh_gatt file after BLE_GAP_EVT_CONNECTED
    <t:     315256>, mesh_gatt.c,  807, Entered here: BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST
    <t:     315266>, mesh_gatt.c,  535, exchange_mtu_req_handle packet size: 244
    <t:     315511>, main.c,  784, Successfully updated connection parameters
    
    //3rd Log is after Identifying and TRYING to Provision the node
    //This is where it fails
    <t:         12>, mesh_gatt.c,  553, Effective MTU Packet size of Mesh_GATT: 244
    <t:         20>, mesh_provisionee.c,  112, AFTER :proxy_init
    <t:         22>, app_error_weak.c,  105, Mesh error 8 at 0x00000000 (:0)

    I will use addr2line and see the exact line which is throwing the error.

    Thank you for your patience and answers.

    Kind Regards,

    Shrinidhi Bhat

Related