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

  • If there is a NUS service in the attribute table, nRFToolbox should keep the connection. Could you find the logging on nRFToolbox ? Could you try to test also with nRFUART app ? 
    When you see an issue, please try to find the root cause, don't use assumption. Why would a reset help here ??

  • I have fixed that particular issue and can connect via the nRF Toolbox application after i disconnect from the Mesh application. But again, disconnecting from the Mesh application does not allow a transfer of more than 20 bytes.

    Here is where you can init your NUS service again.

    I have initialized the NUS inside the proxy_init() function. This is the reason why I can see the extra service added after I provision the device like you mentioned before. Now after Provisioning, I ideally need to disconnect and send the data via the nRF Toolbox application but the major problem now is:

    1) I cannot send more than 20 bytes of data here and have no idea why

    because BLE_NUS_MAX_DATA_LEN has been set to 244 bytes for sure and hence all the characteristics of NUS must reflect the same.

    2) I cannot receive the data from the node because ble_nus_data_send is not working. I have attached the understanding and the points which are not being executed which is resulting the same action.

    // In ble_nus.c inside the function ble_nus_data_send
    if (!p_client->is_notification_enabled)
    {
        return NRF_ERROR_INVALID_STATE; //The error is returning here and hence the data is not being sent over NUS to the mobile application
    }
    
    //Keeping breakpoints we have realised that
    if (ble_srv_is_notification_enabled(p_evt_write->data))
    {
        p_client->is_notification_enabled = true; //This is being executed when we initialize connection via nRFToolbox
        evt.type = BLE_NUS_EVT_COMM_STARTED;
    }
    
    //BUT!!!!! 
    if (p_client->is_notification_enabled)  //Does not enter here
    {
        memset(&evt, 0, sizeof(ble_nus_evt_t));
        evt.type        = BLE_NUS_EVT_TX_RDY;
        evt.p_nus       = p_nus;
        evt.conn_handle = p_ble_evt->evt.gatts_evt.conn_handle;
        evt.p_link_ctx  = p_client;
        p_nus->data_handler(&evt);
    }
    
    //I cannot narrow down as to why this is happening

  • If you don't fully understand how BLE and the NUS service works, it's very hard for us to help you. I strongly suggest you to get to know how NUS works on both the nRF52 side and the Android/iOS side. Try to answer these questions:

    - How does NUS send data from the nRF52 to the phone, using notification or write command ? 

    - How a notification can be enabled for sending (check CCCD)

    - How does the phone send data down to the NRF52,  using notification or write command ? 

    - Try to make your own app to connect to your nRF52, you can refer to the nRF Blinky app. 

Related