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

How to correctly receive a value sent by notification, on my nRF51 DK

Hi all, i am experiencing a problem, that i exposed maybe not so clearly on other topics; i have a a smart beacon kit that is sending temperature values by notification (as done in the tutorial devzone.nordicsemi.com/.../ and it works, i see the values connecting to my android phone with MCP on it), and i want them to be received by my nrf51 DK and then be sent to the PC. My problem now is that the DK doesn't seem to receive the values! What i have done on the DK is simply discover the wanted name of the device (my beacon's name) and then connect to it (and this happens, i see it with a LED turning on); then just by connecting the two devices i should find the values on my DK in:

p_ble_evt->evt.gattc_evt.params.hvx.data;

Is this correct? Or, more specifically, there is something precise i have to write (an instruction or something) that need to be added in order to receive the values on the DK or it is enough to connect the two devices? Please do not link any tutorial or examples because i have widely read all of them trying to figure out by myself the problem ^^'

projects.rar

  • Sorry probably i can't explain well what i have done until now. As i said in the post, i have already used those example you are suggesting (ble app uart central in particular), i will load the full code that i used on the DK (as said, it's pretty much the app uart central, on the beacon i have the service of the tutorial that sends temperature data) in the post so you can watch what i implemented.

    @Jorge, yes indeed, i have a similar code but not specifically for HRS since i don't use it, i just tried to adapt the procedure for my own service.

  • Please do not copy paste your complete code. If you want us to test your application, zip both your peripheral and central project and let us know what SoftDevice version and SDK version you are using.

  • Ok thanks, i uploaded the zip:

    For the central project (ble_app_uart_c), which is loaded on the DK, i used SDK 11 with softdevice s130 For the peripheral project (ble_app_beacon), which is loaded on the smart beacon kit (rev 1.0), i used SDK 7.1 (the latest compatible) with softdevice s110.

    Thanks in advance!

  • There are several ways of doing this, but I will use ble_app_uart_c as a reference.

    As I mentioned above you need to discover your service, you can use the Database Discovery Module to this. See the SDK documentation and my answer here may also be helpful. ble_app_uart_c discovers the UART service, you need to discover your service. You can see that ble_db_discovery_evt_register() is called inside ble_nus_c_init().

    In on_ble_evt() you can see that when you get the BLE_GAP_EVT_CONNECTED event service discovery is started with ble_db_discovery_start(). When a service is discovered db_disc_handler() will be called, which calls ble_nus_c_on_db_disc_evt(). This checks if the correct service was discovered and stores the attribute handles of the characteristic values and the CCCD. It then sends the BLE_NUS_C_EVT_DISCOVERY_COMPLETE event to ble_nus_c_evt_handler() in main.c. This event triggers ble_nus_c_rx_notif_enable() which writes 0x0001 to the CCCD of the characteristic that shall send notifications. Before the CCCD is set to 0x0001 the peripheral will not be able to send notifications.

    If you get a notification from the peripheral you will get the BLE_GATTC_EVT_HVX event, in this you can find your data.

  • First of all thanks really for your time. So if i am understanding correctly, i should modify the ble_app_uart_c on the DK to tell it to discover my personal service on the beacon, which is NOT the nus service, but my custom one (formerly "our service" of the tutorial)?

Related