This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

BLE_GATTS_EVT_HVN_TX_COMPLETE event does not works on NUS for multi-role device

Hi,

In a multi-role central-peripheral code for a nRF52840-DK based device, I have to send a buffer acting as a peripheral. I use the ble_nus_data_send function sent as a trigger in the BLE_GAP_EVT_CONNECTED (into the ble_evt_handler function). So, I send the first data packet once the connection as peripheral has been established.

The rest of the buffer was expected to be sent using the BLE_GATTS_EVT_HVN_TX_COMPLETE event into the ble_evt_handler function. However, the event does not never occurs.

In fact, when I execute ble_nus_data_send the first time, it returns a NRF_ERROR_INVALID_STATE because it detects a condition ike !p_client->is_notification_enabled.

I have tried to clone the NUS configuration (as a peripheral) from the ble_app_uart example, working using the nRF5_SDK_17.1.0_ddde560. And including the sdk_config.h file configuration.

What should I setup to enable the BLE_GATTS_EVT_HVN_TX_COMPLETE event? Should I use another event?

Thank you very much in advance.

Best Regards,

Joel

Parents
  • Hi Joel,

    I cannot think of any situation where you would not get a BLE_GATTS_EVT_HVN_TX_COMPLETE notification as long as the notification/indication is successfully sent. If it is, it should always arrive, though you might not get the same number of BLE_GATTS_EVT_HVN_TX_COMPLETE events as you send notifications, as the same event can cover more than one notification (in that case, the count field informs you how many notifications has been sent).

    Could it be that you are for instance filtering on the wrong connection handle, and therefor do not see the events? This is just a guess, though.

    If you don't make progress, perhaps you can share your event handling code here so that I can see if I spot anything?

  • Hi Einar,

    The definition is:

    BLE_NUS_DEF(m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT);

    The initialization is:

        ble_nus_init_t   nus_init;

        memset(&nus_init, 0, sizeof(nus_init));
        nus_init.data_handler = nus_data_handler;
        err_code = ble_nus_init(&m_nus, &nus_init);

    In the ble_evt_handler. In the BLE_GAP_EVT_CONNECTED event it discriminates if it works a central device or like a peripheral. In this second case it executes the next:

                    m_per_con_handle = p_gap_evt->conn_handle;
                    NRF_LOG_INFO("Peripheral connection 0x%x established.", m_per_con_handle);    
                    
                    app_timer_start(m_post_message_delay_timer_id, APP_TIMER_TICKS(2000), 0);
                    
                    app_timer_stop(m_adv_led_blink_timer_id);
                    
                    bsp_board_led_on(PERIPHERAL_ADV_CON_LED);
                    punter_buffer_accelerometre= 0;
                    num_rebuts_buffer_accelerometre= 128003;
                    send_data_ble_accel();

    Into the function send_data_ble_accel function the code executes

                   err_code = ble_nus_data_send(&m_nus, data_buf, &length, m_per_con_handle);

    If I debug this function in this stage I can see that the notification is not enabled.

    As a peer I'm using a second nRF52840-DK board running the ble_central_and_peripheral\experimental\ble_app_att_mtu_throughput example. Here I select the buttin 4. This board establish the connection as a central device and recognizes the other board.

    Regards,

    Joel

  • Hi,

    I'm trying to use Nordic examples as a entral device. AndI thought that in the ATT_MTU example working as central the client notification were enabled. Are they not? What should I do to enable them?

    Or do you think should I use the ble_app_uart_c example? How should I enable the notifications there?

    Thank you in advance.

    Regards,

    Joel

  • Hi Joel,

    I am not exactly sure which changes you have done and how, but the way this works is that the Bluetooth connection is established, the GATT client (which is typically the central here) does service discovery, and after that it can enable notifications on characteristics that support it and it want notifications on. That seems to not be done here. If you refer to the NUS central example, you will see that it does enable notifications, and you must do the same (search for "ble_nus_c_tx_notif_enable" in examples/ble_central/ble_app_uart_c/main.c). 

  • Hi Einar,

    I will make a double check. I will come back tomorrow.

    By the way, I will have to connect it to an iPhone app in the end. This app will work as the central that has to enable then the notifications. Do you see anything special should I do from the device side?

    Regards,

    Joel

  • Hi Einar,

    I attach the multi-role+multi-link code I'm using. It comes from the multi-link-multi-role example in github, adding the NUS service (I have modified it over SES environment).

    ble_aggregator_NUS_6.zip

    I have a problem. Acting as a peripheral I can see it the Aggregator device on the mobile app nRF Connect. However, it does not establish connection with a second nRF52840-DK board that has the ble_app_uart_c code running on it as a central. So, it's not clear that as an Aggregator multi-role could acting ok as a NUS peripheral. Please, may you suggest me something to get that this multi-role Aggregator can be linked also to a NUS Central?

    Thank you in advance.

    Regards,

    Joel

  • Hi Joel,

    jinvers said:
    It comes from the multi-link-multi-role example in github

    Which example is that? Can you link to it?

    jinvers said:
    However, it does not establish connection with a second nRF52840-DK board that has the ble_app_uart_c code running on it as a central.

    In this case, the phone is also acting as a central I assume? And you want to connect with a second central (phone running ble_app_uart_c)? If so, that will not work. The project you have uploaded supports multiple central links but only a single peripheral link.

    Is the intention to also support several peripheral links (links where the nRF acts as a peripheral role)? If so, the first thing you must do is adjust NRF_SDH_BLE_PERIPHERAL_LINK_COUNT and set it to the number of central links you want. This is among other things used when initializing the SoftDevice, so having this set to 1 more than 1 link will never work. You also need to do a bit of changes to the application code to support this (I see you have done some but I have not gone through your implementation in detail).

Reply
  • Hi Joel,

    jinvers said:
    It comes from the multi-link-multi-role example in github

    Which example is that? Can you link to it?

    jinvers said:
    However, it does not establish connection with a second nRF52840-DK board that has the ble_app_uart_c code running on it as a central.

    In this case, the phone is also acting as a central I assume? And you want to connect with a second central (phone running ble_app_uart_c)? If so, that will not work. The project you have uploaded supports multiple central links but only a single peripheral link.

    Is the intention to also support several peripheral links (links where the nRF acts as a peripheral role)? If so, the first thing you must do is adjust NRF_SDH_BLE_PERIPHERAL_LINK_COUNT and set it to the number of central links you want. This is among other things used when initializing the SoftDevice, so having this set to 1 more than 1 link will never work. You also need to do a bit of changes to the application code to support this (I see you have done some but I have not gone through your implementation in detail).

Children
  • Hi,

    I have included the zip file with the example modified. The original link is

    github.com/.../nrf52-ble-multi-link-multi-role

    The example is a central and a peripheral device simultaneously. I have adjusted the parameters you have told me.

    Regards,

    Joel

  • HI Joel,

    Ah, I was not aware of that repo.

    I saw your project from your previous post. As mentioned, it clearly cannot support more than one connection in the peripheral role, particularly because you configure the SoftDevice handler library (and in turn the SoftDevice) to only support 1. So adjusting that needs to be the first thing you need to do (among several) for the problem you mentioned in your last post, which is that you cannot be connected to two centrals at the same time.

  • Excuse me Einar, but I think èrhaps there is a misunderstanding. This device is a multi-role device. According to the aggregator multi-role and multi-link example it was possible to work simultaneously as a central and as a peripjheral.

    When it works as a peripheral, it is only connected to one central and the configuration and the tests have all been done using one only central ever. I have never tried to connect it to two centrals.

    However, this device is also a central for other peripherals.

    Regards,

    Joel

  • Hi joel,

    jinvers said:

    Excuse me Einar, but I think èrhaps there is a misunderstanding. This device is a multi-role device. According to the aggregator multi-role and multi-link example it was possible to work simultaneously as a central and as a peripjheral.

    When it works as a peripheral, it is only connected to one central and the configuration and the tests have all been done using one only central ever. I have never tried to connect it to two centrals.

    Aha, yes there could be a misunderstanding. I was reading this:

    jinvers said:
    I have a problem. Acting as a peripheral I can see it the Aggregator device on the mobile app nRF Connect. However, it does not establish connection with a second nRF52840-DK board that has the ble_app_uart_c code running on it as a central.

    and interpreted it that you now tried to use both a phone and a second DK with ble_app_uart_c) at the same time, which would e two centrals, and that will not work with your application (which allows several links in the central role, but only one link in the peripheral role).  Perhaps we can back-track a bit, and you can explain in more detail how you test, describing all devices in use at the same time and which roles they have etc?

    Assuming this is all from the misunderstanding, I guess the original issue remains, which seems to be that you (in the central role / as GATT client have not enabled notifications on the NUS characteristic, and therefor the NUS peripheral (GATT server) is not able to notify on it. This you just need to do as is doen in the NUS example (taking account that you have multiple connections).

  • Hi Einar,

    I try to update the question.

    First, I try to clarify again the scenario: The multi-link-multi-role device (using the modified aggregator example I attached) when connects as a PERIPHERAL (so as GATT Server) to a mobile phone app OR (not simultaneously) to a second nRF52840-DK acting as central. To be more clear, consider only a mobile phone app.

    I have to transmit a long buffer (around 125KBytes) from this device acting as a PERIPHERAL (so GATT Server) to the mobile phone app (acting as a Central). But in 2 or 3 seconds, so I need to do it using NOTIFICATIONS at a high rate (phy of 1M, MTU of 247, Data Length of 244, Interval between 50ms and 100ms).

    I have continued investigating about the aggregator example. I would say that it uses the ble_agg_cfg_service_string_send funtion to do this (into this function it's called the sd_ble_gatts_hvx function). So, I try again using the ble_agg_cfg_service_string_send function. Is this OK?

    So, using the ble_agg_cfg_service_string_send function I may confirm that the BLE_GATTS_EVT_HVN_TX_COMPLETE is activated into the ble_evt_handler. However, the transmitting rate is slow. So, I think that the notifications are really not enabled and that I'm not using the right tools for testing. To send notifications, I have understood that they should be enabled in the mobile app side. Is this right?

    If all my former assumptions are correct, I have really two questions now:

    1.- Before developing a new mobile app, I need to use some other tool (acting as a central) to simulate all this behaviour. What would you suggest to use?

    2.- Could I use the nRFConnect mobile phone app as a terminal to test this? How?

    Regards,

    Joel

Related