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......

  • Hi Parag,

    You answered your own question.

    1) You can identify the peer device either by peer device device address or the connection handle. Adding an if else statement to turnon LEDs based on the connection ID from where the request came from is not that difficult. I am assuming that you are sending the switch state from peripherals to central using notifications. Then this logic should go into the notification handler for the service central discovered.

    2)  For the peripheral to wakeup on the button(switch)  press, you need to configure the gpio to wake the peripheral on the state change. You can see how it is done here.

     

  • Thanks for your response,

    For my first ques, I am trying with connection handle but not getting. Will you please provide me small program snippet for how i can set address and ON LED with particular connection link.

    And my second question i know wake up with GPIO sense signal it not problem, My other problem is as per above description device A B and C connected each device 2 switches press all same time then want to ON all LED on central with same time frame.  

    Thanks..

  • 1) on the central side, in the ble_evt_handler

     

    void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    
    You have uint16_t conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
    
    

    This connection is unique per connection and you can use it to identify the peripheral logically.

    2) Even though you press all the switches at the same time, the central will have to process them separately as each peripheral will send this notification to central separately. 

    For example, 

    if(the notification is for the LED service)
    {
        if(conn_handle == 0x0 ) 
        {
            if(value == 1)    LED_X_ON;
            else LED_X_OFF;
        }
        
        else if(conn_handle == 0x1 ) 
        {
            if(value == 1)    LED_Y_ON;
            else LED_Y_OFF;
        }
        
        else if(conn_handle == 0x2 ) 
        {
            if(value == 1)    LED_Z_ON;
            else LED_Z_OFF;
        }
    }

    I am just giving you a pseudo code to give you an idea. 

     

  • Hi, 

    Thanks for your suggestion..

    As per connection handle is working with one button and one LED but in my application in each connection handle having two switch and two LEDs.

    I am able to add two switch in blinky example. like this:

    static app_button_cfg_t buttons[] =
    {
    {LEDBUTTON_BUTTON1, false, BUTTON_PULL, button_event_handler},
    {LEDBUTTON_BUTTON2, false, BUTTON_PULL, button_event_handler}
    }; 

    When i press button 1 and 2 is working fine in blinky.

    But in multi-link central How i can identify which button state change to ON particular button LED in same connection handle 0.

    I have checked in lbs_c_evt_handler(...)

     case BLE_LBS_C_EVT_BUTTON_NOTIFICATION:
            {
                NRF_LOG_INFO("Link 0x%x, Button state changed on peer to 0x%x",
                             p_lbs_c_evt->conn_handle,
                             p_lbs_c_evt->params.button.button_state);
    
                if (p_lbs_c_evt->params.button.button_state)
                {
                    bsp_board_led_on(LEDBUTTON_LED);
                }
                else
                {
                    bsp_board_led_off(LEDBUTTON_LED);
                }
            } break; // BLE_LBS_C_EVT_BUTTON_NOTIFICATION
    

    When i press button 1 and 2 the event is coming for two button ON same LED because having same same connection link. I want ON particular LED with when particular button press.  

    How i can switch in central if second button press with same link. will please provide me small program snippet.

    Thanks......

  • sorry for the late reply, we had some summer holidays here in Norway, hence the delays.

    You should be able to use p_lbs_c_evt->conn_handle (in addition to the button_state you already are checking) to decide which connection it is and switch the appropriate LED on/off. 

Related