Skip to content

Commit 5bd0b4d

Browse files
committed
complete get peer name
1 parent 226c99a commit 5bd0b4d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void setup()
2828

2929
// Initialize blinkTimer for 1000 ms and start it
3030
blinkTimer.begin(1000, blink_timer_callback);
31-
//blinkTimer.start();
31+
blinkTimer.start();
3232

3333
// Setup the BLE LED to be enabled on CONNECT
3434
// Note: This is actually the default behaviour, but provided
@@ -102,7 +102,11 @@ void loop()
102102

103103
void connect_callback(void)
104104
{
105-
Serial.println("Connected");
105+
char central_name[32] = { 0 };
106+
Bluefruit.Gap.getPeerDevName(central_name, sizeof(central_name));
107+
108+
Serial.print("Connected to ");
109+
Serial.println(central_name);
106110
}
107111

108112
void disconnect_callback(uint8_t reason)

libraries/Bluefruit52Lib/src/BLEGatt.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,19 @@ uint16_t BLEGatt::readCharByUuid(uint16_t conn_hdl, BLEUuid bleuuid, void* buffe
5252
_adamsg.begin(true);
5353
_adamsg.prepare(buffer, bufsize);
5454

55-
if( NRF_SUCCESS == sd_ble_gattc_char_value_by_uuid_read(conn_hdl, &bleuuid._uuid, &hdl_range) )
55+
err_t err = sd_ble_gattc_char_value_by_uuid_read(conn_hdl, &bleuuid._uuid, &hdl_range);
56+
57+
if( NRF_SUCCESS == err )
58+
{
59+
// Read by uuid could take long if the uuid handle is far from start handle
60+
count = _adamsg.waitUntilComplete(5*BLE_GENERIC_TIMEOUT);
61+
}else
5662
{
57-
count = _adamsg.waitUntilComplete(BLE_GENERIC_TIMEOUT);
63+
VERIFY_MESS(err);
5864
}
59-
6065
_adamsg.stop();
6166

67+
6268
return (count < 0) ? 0 : count;
6369
}
6470

@@ -102,8 +108,6 @@ void BLEGatt::_eventHandler(ble_evt_t* evt)
102108
{
103109
ble_gattc_evt_char_val_by_uuid_read_rsp_t* rd_rsp = &evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp;
104110

105-
PRINT_INT(rd_rsp->count);
106-
PRINT_INT(rd_rsp->value_len);
107111
if (rd_rsp->count)
108112
{
109113
_adamsg.feed(rd_rsp->handle_value[0].p_value, rd_rsp->value_len);

0 commit comments

Comments
 (0)