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

Cycling Speed and Cadence sensor central configuration using nRF52832

i am working on the Cycling Speed and Cadence sensor central configuration using nRF52832 DK in Segger Embedded Studio. I used the RSCS central example of nrf_sdk_v15.0 and have made changes according to my requirement for single sensor and it is working fine i.e i am able to get the correct data. Then i wanted to connect nearly 8 such CSCS beacons so i made small changes in my code accordingly using Multilink central example as reference. I have adjusted the RAM and memory allocation also.  My main doubt is once i run the program it gets connected to a single device and it starts reading the data. How am supposed to make it connect and read the next sensors simultaneously ? I need to store the 8 data in an array after connecting all the beacons. I have attached the RTT log for your reference. What am i supposed to do now ? How can i read all the data parallely ? 

Parents
  • Hello,

    Have you tried to connect to several devices at once? It says that it is scanning for more devices after that you connected with the first one. As long as it enables notification on all of the sensors that it connects to, it should get an event whenever the devices pushes some new data to the device.

     

    What happens if you try to connect another peripheral to your central?

     

    Best regards,

    Edvin

  • Hi Sir,

    Thanks for your reply. 

    Right now i tried for 2 sensors only. I tried to read 2 advertisement reports and have put two cscs handlers for collecting 2 sensor's data. Please check the attached RTT logs of my application. I am getting this output only. I tried connecting with different peripheral names. 

    I dont know why the discovery is part is repeating 8 time when i tried connecting with a single sensor. It not giving any outputs too when i tried. 

    Kindly help me sir,

    Thanks and Regards

    Santosh Krishnan R 

  • Hello,

    Exactly why the discovery part is showing 8 times, I am not quite sure either. I have seen it before in the multilink example, so I think there is a small bug there. However,  I have not seen it causing any problems before. We can look into it eventually. But the "Fatal error" is something that we can't ignore for now.

    Can you please try to define "DEBUG" in your preprocessor defines? 

    A "Fatal error" typically comes from an APP_ERROR_CHECK(err_code); with an err_code != NRF_SUCCESS (=0).

    If you define "DEBUG" in your preprocessor defines, it should print some more info in the log, on where in the code the APP_ERROR_CHECK(err_code); that triggered the fatal error is, and what err_code it received. This way we can see what function that returned err_code != NRF_SUCCESS.

     

    Please let me know if you find out what function call it was, and what the err_code that is returned is.

     

    Best regards,

    Edvin

  • Hi Sir,

    I tried as you said to debug and i am getting the following issues. When i tried to connect my 1st sensor its gets connected and the repetition of discovery occurs and after i wake the second sensor it gives the following error in line 780 which is " APP_ERROR_CHECK(ret) " in the whitelist_load function and hex code: 0x0002E00B and stops. When i restart the debugging its scan for and once name matches it stops again by giving the following error in line 787 which is "APP_ERROR_CHECK(ret)" in the whitelist_load function. I have attached the RTT logs and error code for your reference. I have put the peripheral names in an array and have called in the adv_report. 

    Kindly help. 

    Thanks and Regards,

    Santosh Krishnan R 

Reply
  • Hi Sir,

    I tried as you said to debug and i am getting the following issues. When i tried to connect my 1st sensor its gets connected and the repetition of discovery occurs and after i wake the second sensor it gives the following error in line 780 which is " APP_ERROR_CHECK(ret) " in the whitelist_load function and hex code: 0x0002E00B and stops. When i restart the debugging its scan for and once name matches it stops again by giving the following error in line 787 which is "APP_ERROR_CHECK(ret)" in the whitelist_load function. I have attached the RTT logs and error code for your reference. I have put the peripheral names in an array and have called in the adv_report. 

    Kindly help. 

    Thanks and Regards,

    Santosh Krishnan R 

Children
  • Hello,

    if pm_whitelist_set() returns 5, it means NRF_ERROR_NOT_FOUND. Please see pm_whitelist_set() on infocenter.

     

    Can you please try to step through the function. If you set a breakpoint on line 619 after that the first peripheral has connected, and before the second connects. Is this the function that returns != 0?

    If so, can you step into this function to see where it returns?

    Is it after peer_data_find() or fds_record_open()? If you find out which one it is, try to step further in, and figure out which softdevice call, sd_...() that returns != NRF_SUCCESS.

     

    Best regards,

    Edvin

  • Hi Edvin, 

    Thanks for your reply. I will try to debug the issue and will let you know if i find any difficulty or doubt.

    With Regards,

    Santosh Krishnan 

  • Hi Edvin,

    Now i am able to connect with multiple cscs and heart rate sensors. But i am connecting it using their peripheral name. But i want to connect it with their mac address to differentiate and collect the values in an array and finally hard code the macs which something like whitelisting. How can i read multiple advertisement mac addresses and connect to those devices ? Kindly help me.  

  • Hello,

    Whenever you have scanning enabled, you will get some events called BLE_GAP_EVT_ADV_REPORT, which usually calls on_adv_report() in our examples from the SDK.

    Depending on what example the on_adv_report() is copied from, it will either filter on advertising name, or advertising UUID, but you can change this to bluetooth address if you like.

     

    In the ble_app_rscs_c example, this function looks like this:

    /**@brief Function for handling the advertising report BLE event.
     *
     * @param[in] p_adv_report  Advertising report from the SoftDevice.
     */
    static void on_adv_report(ble_gap_evt_adv_report_t const * p_adv_report)
    {
        ret_code_t err_code;
        ble_uuid_t target_uuid = {.uuid = TARGET_UUID, .type = BLE_UUID_TYPE_BLE};
    
        if (ble_advdata_uuid_find(p_adv_report->data.p_data, p_adv_report->data.len, &target_uuid))
        {
            // Stop scanning.
            (void) sd_ble_gap_scan_stop();
    
            err_code = bsp_indication_set(BSP_INDICATE_IDLE);
            APP_ERROR_CHECK(err_code);
    
            // Initiate connection.
            m_scan_param.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
    
            err_code = sd_ble_gap_connect(&p_adv_report->peer_addr,
                                          &m_scan_param,
                                          &m_connection_param,
                                          APP_BLE_CONN_CFG_TAG);
    
            m_whitelist_disabled = false;
    
            if (err_code != NRF_SUCCESS)
            {
                NRF_LOG_DEBUG("Connection Request Failed, reason 0x%x", err_code);
            }
        }
        else
        {
            err_code = sd_ble_gap_scan_start(NULL, &m_scan_buffer);
            APP_ERROR_CHECK(err_code);
        }
    }

     

    The line:

    if (ble_advdata_uuid_find(p_adv_report->data.p_data, p_adv_report->data.len, &target_uuid) is the function that decides whether to connect to the device or not.

    The address of the advertising device is found in:

    p_adv_report->peer_addr.addr[BLE_GAP_ADDR_LEN].

    so if you know the address of the device, you can filter by this:

    if (p_adv_report->peer_addr.addr[0] = 0x12 &&
        p_adv_report->peer_addr.addr[1] = 0x34 &&
        p_adv_report->peer_addr.addr[2] = 0x56 &&
        p_adv_report->peer_addr.addr[3] = 0x78 &&
        p_adv_report->peer_addr.addr[4] = 0x9a &&
        p_adv_report->peer_addr.addr[5] = 0xbc)
    {
        // the same connection stuff from the function on_adv_report()
    }

     

    Try that, and let me know if it doesn't work.

     

    BR,

    Edvin

  • Hi Edvin,

    Thanks for your reply. Now we are able to connect the devices. But i mainly want to mac the mac IDs to the specific users. I am able to get the connection instances after starting the services. But how to bring the mac ids inside the service event handlers. After getting connected and when the services starts at any instances i want the mac addresses too along with the connection instances. i mean i need the mac address to differentiate between the values of the instances since we may not know which device has been connected. So i want the mac address too with the connection instance. Kindly help. 

    Thanks and Regards,

    Santosh Krishnan R 

Related