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

How to send data from the central to multiple peripherals?

Hello everybody !

My code is based on the code of the "ble_app_multilink_central" on which, I added some of the code "ble_app_uart_c" for the initialization and the event manager on the uart. I have a nrf52832 development board as a central and 2 rf52832 developpemtn boards as a peripheral. Each peripheral consists of 4 characteristics.

I am currently using the following code to be able to manage by my PC the connection between the central and the peripherals :

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void uart_event_handle(app_uart_evt_t * p_event)
{
static uint8_t data_array[30];
static uint16_t index = 0;
uint32_t ret_val;
static char const start[] = "1";
static char const acquisition[] = "2";
static char const disconnect[] = "3";
UNUSED_VARIABLE(app_uart_get(&data_array[index]));
if (memcmp(start, data_array, sizeof(start)) == 0){
//printf("start");
scan_start();
}
if (memcmp(acquisition, data_array, sizeof(acquisition)) == 0){
//function to acquire values "characteristic"
printf("LEDdebug");
bsp_board_led_invert(LEDTEST);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

In my uart event handle, I created several commands that I manage from my PC.
For example by pressing "1", I start scanning, and "3" i disconnect the link between central and peripherals.

My goal is to add a function by pressing, for example "2", writing the message "0x01"  on a feature of each peripheral, which could for example be interpreted by my 2 devices by "change status of one of their LED.

What does my peripheral do when you write about one of its values :

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
static void on_write(ble_cus_t * p_cus, ble_evt_t const * p_ble_evt)
{
ble_gatts_evt_write_t const * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
// Custom Value Characteristic Written to.
if (p_evt_write->handle == p_cus->custom_value_handles.value_handle)
{
if(*p_evt_write->data == 0x01)
{
nrf_gpio_pin_toggle(LED_4);
}
else
{
//Do nothing
}
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Thank you in advance for your assistance !