Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How LED ON at same time in Central connected to 3 ble peripheral.

Hello,

I have developing one project in that i am using nRF52832 and SD 15.0. Here is the current application developing:

  1. There are 3 ble app_blinky(ble peripheral) example operated on battery and it connected to multilink central.
  2. Lets say ble peripheral name A, B, C and central device is master.
  3. Each ble peripheral- A interface simply 2 push switch and whenever it press digital signal goes to connected central and then ON particular GPIO LED.
  4. Same point two for other B and C ble peripheral. Therefore total LEDs on central side has 6 for each switch.
  5. Now i am able to connect 3 ble peripheral to central but not able to ON particular LED controlled by ble peripheral slave.

Problems:

  1. When switch press of device A , B or C then how i know in central whether it coming from A or B or C. I know connection handle link for each connection but i can do it will you please provide me program snippet for understanding.
  2. Once all switches (Total 6) press at same time then it will wake up all 3 peripherals A, B and C connect to central device. Want to ON all 6 LEDs in central at same time frame. How i can do it.

Thanks......

  • The one in the example gives you a simulated battery level. You need to get the battery level as mentioned in the thread here. Even though the thread is for nRF51, the technique remains the same. There are lot of information in this forum for this. Please check the other threads on how to do this.

  • Hi Aryan,

    I have added battery level characteristics in my both programs. In ble peripheral i have used BAS_ENABLED and in Central i have used BAS_C_ENABLED. When i push button at peripheral side i called battery_level_update() function. 

    But problem is not getting battery read event at central side. After that for checking purpose i have connect my phone with nRF Connect app to ble peripheral and checked battery services and it shows and also read battery level in android app. But not getting in central device will please help me where should exactly problem, how i can identify this. 
    I have added all required services in Central for read battery level. 
    Thanks...!! 
  • Sorry for late reply.

    You need to check if a notification is sent to the central. You can sniff the air packets to see if anything is sent on a button press.

  • It's Ok Aryan,

    Now i have solved this issue by defining bas event in init function my mistake i forgot to initialize Now our battery update code is well working.

    But now problem is we have 3 BLE peripherals so for that we want to use only one program all of these three devices. And at central side want to glow particular led with slave only.

    For that slave 1 i use this function:

    static void button_event_handler(uint8_t pin_no, uint8_t button_action)
    {
        ret_code_t err_code;
    
        switch (pin_no)
        {
            case LEDBUTTON_BUTTON1:
                NRF_LOG_INFO("Send first button state change.");
     //           err_code = ble_lbs_on_button_change(m_conn_handle, &m_lbs, button_action);
          err_code = button_action ? ble_lbs_on_button_change(m_conn_handle, &m_lbs, 1) : ble_lbs_on_button_change(m_conn_handle, &m_lbs, 0);
                if (err_code != NRF_SUCCESS &&
                    err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
                    err_code != NRF_ERROR_INVALID_STATE &&
                    err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
                {
                    APP_ERROR_CHECK(err_code);
                }
                break;
            case LEDBUTTON_BUTTON2:
                NRF_LOG_INFO("Send second button state change.");
     //           err_code = ble_lbs_on_button_change(m_conn_handle, &m_lbs, button_action);
         err_code = button_action ? ble_lbs_on_button_change(m_conn_handle, &m_lbs, 3) : ble_lbs_on_button_change(m_conn_handle, &m_lbs, 2);
                if (err_code != NRF_SUCCESS &&
                    err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
                    err_code != NRF_ERROR_INVALID_STATE &&
                    err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
                {
                    APP_ERROR_CHECK(err_code);
                }
                break;
    
            default:
                APP_ERROR_HANDLER(pin_no);
                break;
        }
    }

    And in slave 2 only change button state value and read this value in central side and ON particular LED with respective slave signal.

    Please help me how i can logic to convert this 3 slave code into one program code and will work  if flashed into 3 devices. Whenever use press switch ON slave 1 device only LED 1 will ON at central side. If slave 1 device turn OFF and then user press switch ON slave 3 then only LED 3 will ON at central side. Meaning whenever any slave turn ON/OFF switch press at that time respective LEDs only ON as defined in program not depend on connection handle. 

    Because connection handle changed due to slave power ON and OFF not in order. But in central code LED will fixed for respective signal coming from slaves.

    Will please provide me program snippet how i can do this logic??

    We are stuff here and also not much more time for this project.

    If you need my both central and slaves complete projects files just let me know i can share with you but before that please do this case as private.

    Thanks in advanced..!!!

  • Hi Parag, Sorry for the late reply

    For every connection with your slave you will get different conn_handle value.

    So when the connection is established you need to save them into m_conn_handle1, m_conn_handle2 and m_conn_handle3

    In your button event, you compare the conn_handle with one of these to know which device is sending this button events and light the appropriate LED

Related