I am working on a ble nus pheripheral application on nrf52810 with sdk 15.2 and s112. currently I can connect to nrf52 with 4 mobile phone at same time and send&receive string. but how can I know which phone sends the characters?
I am working on a ble nus pheripheral application on nrf52810 with sdk 15.2 and s112. currently I can connect to nrf52 with 4 mobile phone at same time and send&receive string. but how can I know which phone sends the characters?
You have to check the conn_handle of the event that the string comes in. Please note that there may be a bug in the ble_nuc.c library, as the BLE_NUS_EVT_RX_DATA event doesn'f forward the conn_handle (it is designed for only one connection).
So in on_write() in ble_nus.c, look for the place it says:
evt.type = BLE_NUS_EVT_RX_DATA;
Then add the conn_handle to this event before it is forwarded to the p_nus->data_handler(&evt);
Add the event by adding this line before this call:
evt.conn_handle = p_ble_evt->evt.gatts_evt.conn_handle;
Then you can check the conn_handle in the nus_data_handler:
static void nus_data_handler(ble_nus_evt_t * p_evt) { if (p_evt->type == BLE_NUS_EVT_RX_DATA) { uint32_t err_code; uint16_t my_conn_handle = p_ble_evt->conn_handle; NRF_LOG_INFO("received data from conn_handle %x", my_conn_handle); NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART."); NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length); ...
You need to keep track of what phone that belongs to what conn_handle. It should be the same as the conn_handle that you find in the BLE_GAP_EVT_CONNECTED event in ble_evt_handler() in main.c.
Best regards,
Edvin
is it
uint16_t my_conn_handle = p_ble_evt->conn_handle;
or
uint16_t my_conn_handle = p_evt->conn_handle;
in nus_data_handler(ble_nus_evt_t * p_evt)
is it
uint16_t my_conn_handle = p_ble_evt->conn_handle;
or
uint16_t my_conn_handle = p_evt->conn_handle;
in nus_data_handler(ble_nus_evt_t * p_evt)
Sorry.
p_evt->conn_handle.
It should always be the same as the event that is passed into the function.
Best regards,
Edvin
Ok, thanks. seems it's gonna work. I will verify your answer after the test.