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

Parents
  • Hi, 

    I tried to change MESH_GATT_MTU_SIZE_MAX and NRF_SDH_BLE_GATT_MAX_MTU_SIZE from 69 to 240 in the proxy light switch example in our SDK and has no problem. 

    Please be aware that mesh already has a gatt library (mesh_gatt.c) that handles sd_ble_gatts_exchange_mtu_reply(), you don't need to have nrf_ble_gatt.c library. There should be only one reply to the MTU exchange request. 

    When you see an error, please go into the root cause. 

  • Hi Hung,

    I had done that prior to asking you this question. I had initially set them at 244 and 247 bytes respectively. I even have a log result inside the exchange_mtu_req_handle function which shows the server_rx_mtu size as 247 bytes after the following line of code: 

    uint16_t server_rx_mtu = MAX(MIN(MIN(client_rx_mtu, NRF_SDH_BLE_GATT_MAX_MTU_SIZE), MESH_GATT_MTU_SIZE_MAX), BLE_GATT_ATT_MTU_EDITED); // BLE_GATT_ATT_MTU_EDITED = 247 bytes.

    The problem is when I try to avail the NUS. When I open the nRF Connect application and connect with the DK, it again enters inside the proxy.c and hence mesh_gatt.c as shown by the Log details. Now when I click on NUS and try to send 20 bytes of data, it works perfectly. But when I increase that to 21 bytes, it does not even hit the DK and after some time throws a GATT timeout error (0x85/133).

    I will attach the log file in the sequence of operation as given below:

    1) Connect to the DK via nRF Mesh application (Node is already provisioned before)

    2) Disconnect the node from the nRF Mesh application.

    3) Connect the node via nRF Connect application.

    4) Send 20 Bytes of data using nRF connect app.

    5) Send more than 20 bytes of data.

    NOTE:- I will separate each activity by 3 spaces on the Log file for ease of understanding.

    //This is the Log file and not the code
    //**********1st Activity
    <t:        570>, main.c,  847, Initializing and adding models
    <t:        606>, mesh_gatt.c,  573, Effective MTU Packet size of Mesh_GATT: 244
    <t:        614>, mesh_gatt.c,  556, nus_gatt_peripheral_set: 247
    <t:        631>, main.c, 1075, Device UUID : 005955AA000000004BB1BF73B8371451
    <t:     959866>, main.c,  775, Successfully updated connection parameters
    <t:     959869>, proxy.c,  579, Connected
    <t:     959872>, mesh_gatt.c,  517, Inside connect_evt_handle: 247
    <t:     959874>, mesh_gatt.c,  731, Log inside the mesh_gatt file after BLE_GAP_EVT_CONNECTED
    <t:     996995>, main.c,  775, Successfully updated connection parameters
    <t:     999691>, mesh_gatt.c,  527, Checking this out client: 517
    <t:     999697>, mesh_gatt.c,  531, Checking this out server: 247
    <t:     999701>, mesh_gatt.c,  534, Another Log check: 244
    <t:    1009277>, proxy.c,  605, TX ready
    <t:    1009287>, mesh_gatt.c,  768, Entered here: BLE_GATTS_EVT_WRITE
    <t:    1022062>, mesh_gatt.c,  773, Entered here: BLE_GATTS_EVT_HVN_TX_COMPLETE
    <t:    1022069>, proxy.c,  610, Enters the RX via Mesh gatt Handler
    <t:    1022072>, proxy.c,  553, RX GATT PDU type 0x2, len 19
    <t:    1022083>, mesh_gatt.c,  768, Entered here: BLE_GATTS_EVT_WRITE
    <t:    1028442>, mesh_gatt.c,  773, Entered here: BLE_GATTS_EVT_HVN_TX_COMPLETE
    
    
    
    //**********2nd Activity
    <t:    3498036>, proxy.c,  594, Disconnected
    <t:    3498392>, mesh_gatt.c,  741, Log inside the mesh_gatt file after BLE_GAP_EVT_DISCONNECTED
    
    
    //**********3rd Activity Connect via nRF Connect application
    <t:    4619492>, main.c,  775, Successfully updated connection parameters
    <t:    4619495>, proxy.c,  579, Connected
    <t:    4619497>, mesh_gatt.c,  517, Inside connect_evt_handle: 244
    <t:    4619500>, mesh_gatt.c,  731, Log inside the mesh_gatt file after BLE_GAP_EVT_CONNECTED
    <t:    4658977>, main.c,  775, Successfully updated connection parameters
    
    
    
    //**********4th Activity Send 20 bytes of data via NUS of nRF Connect application
    <t:    8517069>, main.c,  932, The Length of Data received from nRF Connect is 20
    <t:    8517076>, mesh_gatt.c,  768, Entered here: BLE_GATTS_EVT_WRITE
    
    
    //**********5th Activity Send more than 20 bytes of data via NUS of nRF Connect application
    No Log file as nothing is received by the DK. 
    Seeing the Log file of nRF Connect app, there are few takeaways. 
    1--> Writing request to characteristics works fine
    2--> gatt.writeCharacteristic also visible
    3--> Data written to xxxx is NOT visible for anything over 20 bytes
    And after some time GATT timeout error is detected
    
    

    To help debug, I have tried to get as many Logs as possible. Its still not hitting the nus_data_handler function when sending upwards of 20 bytes.

    Awaiting your reply,

    Kind Regards,

    Shrinidhi Bhat

  • It would be much easier to find the issue by having a sniffer trace to check if the MTU has been updated and to see what happens between the device and the phone.  

    You can also printout a log if you receive event BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST on the nRF52. 

    Could you double check if you can send more than 20 bytes when you modify the ble_app_uart example to support 240 bytes ? There could be a chance that the phone doesn't support that. 

Reply Children
  • Hi,

    Could you double check if you can send more than 20 bytes

    I'm pretty sure the phone supports more than 240 bytes of data. This can be seen in the Log file as:

    <info> app: Debug logging for UART over RTT started.
    <info> app: Connected inside the ble_evt_handler
    <info> app: Data len is set to 0xF4(244)
    <info> app: The length of the Data received from nRF Connect is: 33 // I have added a Log to check the length

    I will check the sniffer trace like you suggested.

    But I believe any data upwards of 20 bytes is not hitting mesh_gatt.c. But the Log file shows the the size to be set at 240 bytes.

    Have tested this case before? Of sending more than 240 bytes of data via mesh_gatt? Is there a rule set from the app that no more than 20 bytes of data can be sent to any Mesh gatt feature?

    Kind Regards,

    Shrinidhi Bhat

  • No Mesh gatt is just normal BLE. 

    Please capture sniffer traces (working and non working situations). 

  • 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

Related