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

  • So can you please indicate me the correct way, maybe with an example of instruction? By the way, this is what another member said me to do in another topic, it's not an idea of mine, and that assignation is taken from another example (heart rate service).

  • On the DK you need to Discover the device, connect to it, allow it to send notifications and then you should receive the data from the beacon. If you can connect, I don't understand what could be the problem for not getting the data.

  • Guys i think that you are not reading the main post. I got them connecting as i clearly stated (discovery on the DK and all the stuff), and this is confirmed by the setting of a LED, the notification are also enabled but i don't receive anything, this is the problem. I am just asking at level of code, what i should write to enable the receiving of the value on the DK to see if i did all correctly.

  • I suspect you think this is much less complex than it is. It is not one line of code you can put in to get this to work. You need to do service discovery, you need to enable notifications on the peripheral by writing to the CCCD of the characteristic. That is why I recommended you to have a look at the BLE central tutorial. I would also recommend you to start of with a peripheral and central example that actually works, play with them, and modify them to learn how thing works. For example ble_app_uart and ble_app_uart_c. Or ble_app_hrs and ble_app_hrs_c.

  • If you are using the ble_app_hrs_c example there is this part:

    /**@brief Heart Rate Collector Handler.
     */
    static void hrs_c_evt_handler(ble_hrs_c_t * p_hrs_c, ble_hrs_c_evt_t * p_hrs_c_evt)
    {
        uint32_t err_code;
    
        switch (p_hrs_c_evt->evt_type)
        {
            case BLE_HRS_C_EVT_DISCOVERY_COMPLETE:
    
                // Heart rate service discovered. Enable notification of Heart Rate Measurement.
                err_code = ble_hrs_c_hrm_notif_enable(p_hrs_c);
                APP_ERROR_CHECK(err_code);
    
                APPL_LOG_DEBUG("Heart rate service discovered \r\n");
                break;
    
            case BLE_HRS_C_EVT_HRM_NOTIFICATION:
            {
                APPL_LOG_DEBUG("[APPL]: HR Measurement received %d \r\n", p_hrs_c_evt->params.hrm.hr_value);
    
                APPL_LOG("Heart Rate = %d\r\n", p_hrs_c_evt->params.hrm.hr_value);
                break;
            }
    
            default:
                break;
        }
    }
    

    this enables the notification and receives the data is on p_hrs_c_evt->params.hrm.hr_value.

    this example is from SDK11. To be sure you are accessing all the steps you waant you can put some printf's on your code to see if it goes where you want!

Related