Hello, im newbie here. I using multilink NUS from example and i want somehow get peripheral (peer) address in ble_nus_c_evt_handler TX event. How can i receive that?
Hello, im newbie here. I using multilink NUS from example and i want somehow get peripheral (peer) address in ble_nus_c_evt_handler TX event. How can i receive that?
See the scan_evt_handler()
static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
.......
case NRF_BLE_SCAN_EVT_CONNECTED:
{
ble_gap_evt_connected_t const * p_connected =
p_scan_evt->params.connected.p_connected;
// Scan is automatically stopped by the connection.
NRF_LOG_INFO("Connecting to target %02x%02x%02x%02x%02x%02x",
p_connected->peer_addr.addr[0],
p_connected->peer_addr.addr[1],
p_connected->peer_addr.addr[2],
p_connected->peer_addr.addr[3],
p_connected->peer_addr.addr[4],
p_connected->peer_addr.addr[5]
);
} break;
........
}
Here is your wanted.
Thank you, but there a way i can get this information in NUS handler from "ble_nus_c_evt_handler"?
Hi
Each connection is identified by a unique 16-bit connection handle, and it is this handle that is passed around in the various events.
If you want to know the address of a specific connection you need to store the address somewhere in memory when the NRF_BLE_SCAN_EVT_CONNECTED event occurs, and then you can refer to it later if needed.
The connection handle starts at 0 and increments from there, so if you need to support multiple connections you can simply create an array of addresses, and use the connection handle as an index into the array.
If you don't want to store the address in the application it is also possible to modify the ble_nus_c_s client structure to store the address when you connect. A pointer to this struct is provided in the ble_nus_c_evt_handler, making it easy to access.
Best regards
Torbjørn
Hi
Each connection is identified by a unique 16-bit connection handle, and it is this handle that is passed around in the various events.
If you want to know the address of a specific connection you need to store the address somewhere in memory when the NRF_BLE_SCAN_EVT_CONNECTED event occurs, and then you can refer to it later if needed.
The connection handle starts at 0 and increments from there, so if you need to support multiple connections you can simply create an array of addresses, and use the connection handle as an index into the array.
If you don't want to store the address in the application it is also possible to modify the ble_nus_c_s client structure to store the address when you connect. A pointer to this struct is provided in the ble_nus_c_evt_handler, making it easy to access.
Best regards
Torbjørn