@@ -53,18 +53,11 @@ static EventGroupHandle_t _spp_event_group = NULL;
53
53
static boolean secondConnectionAttempt;
54
54
static esp_spp_cb_t * custom_spp_callback = NULL ;
55
55
56
- #define SPP_TAG " BluetoothSerial"
57
- static const esp_spp_sec_t sec_mask = ESP_SPP_SEC_AUTHENTICATE;
58
- static const esp_spp_role_t role_master = ESP_SPP_ROLE_MASTER;
56
+ #define INQ_LEN 30 ;
57
+ #define INQ_NUM_RSPS 0 ;
59
58
static esp_bd_addr_t _peer_bd_addr;
60
- static uint8_t peer_bdname_len;
61
- static char peer_bdname[ESP_BT_GAP_MAX_BDNAME_LEN + 1 ];
62
- static const esp_bt_inq_mode_t inq_mode = ESP_BT_INQ_MODE_GENERAL_INQUIRY;
63
- static const uint8_t inq_len = 30 ;
64
- static const uint8_t inq_num_rsps = 0 ;
65
59
static char _remote_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1 ];
66
60
static bool _isRemoteAddressSet;
67
- static esp_bd_addr_t _remote_address;
68
61
static bool _isMaster;
69
62
static esp_bt_pin_code_t _pin_code;
70
63
static int _pin_len;
@@ -295,7 +288,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
295
288
log_i (" ESP_SPP_DISCOVERY_COMP_EVT" );
296
289
if (param->disc_comp .status == ESP_SPP_SUCCESS) {
297
290
log_i (" ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote" );
298
- esp_spp_connect (sec_mask, role_master , param->disc_comp .scn [0 ], _peer_bd_addr);
291
+ esp_spp_connect (ESP_SPP_SEC_AUTHENTICATE, ESP_SPP_ROLE_MASTER , param->disc_comp .scn [0 ], _peer_bd_addr);
299
292
}
300
293
break ;
301
294
case ESP_SPP_OPEN_EVT:// Client connection open
@@ -325,8 +318,9 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
325
318
switch (event){
326
319
case ESP_BT_GAP_DISC_RES_EVT:
327
320
log_i (" ESP_BT_GAP_DISC_RES_EVT" );
328
- esp_log_buffer_hex (SPP_TAG, param->disc_res .bda , ESP_BD_ADDR_LEN);
329
321
for (int i = 0 ; i < param->disc_res .num_prop ; i++){
322
+ uint8_t peer_bdname_len;
323
+ peer_bdname[ESP_BT_GAP_MAX_BDNAME_LEN + 1 ];
330
324
if (param->disc_res .prop [i].type == ESP_BT_GAP_DEV_PROP_EIR
331
325
&& get_name_from_eir ((uint8_t *)param->disc_res .prop [i].val , peer_bdname, &peer_bdname_len)){
332
326
log_v (" ESP_BT_GAP_DISC_RES_EVT : EIR : %s" , peer_bdname);
@@ -366,7 +360,6 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
366
360
case ESP_BT_GAP_AUTH_CMPL_EVT:{
367
361
if (param->auth_cmpl .stat == ESP_BT_STATUS_SUCCESS) {
368
362
log_v (" authentication success: %s" , param->auth_cmpl .device_name );
369
- esp_log_buffer_hex (SPP_TAG, param->auth_cmpl .bda , ESP_BD_ADDR_LEN);
370
363
} else {
371
364
log_e (" authentication failed, status:%d" , param->auth_cmpl .stat );
372
365
}
@@ -675,7 +668,7 @@ bool BluetoothSerial::connect(String remoteName)
675
668
_remote_name[ESP_BT_GAP_MAX_BDNAME_LEN] = 0 ;
676
669
log_i (" master : remoteName" );
677
670
// will first resolve name to address
678
- return (esp_bt_gap_start_discovery (inq_mode, inq_len, inq_num_rsps ) == ESP_OK);
671
+ return (esp_bt_gap_start_discovery (ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS ) == ESP_OK);
679
672
}
680
673
681
674
bool BluetoothSerial::connect (uint8_t remoteAddress[])
@@ -702,7 +695,7 @@ bool BluetoothSerial::connect()
702
695
} else if (_remote_name[0 ]) {
703
696
log_i (" master : remoteName" );
704
697
// will resolve name to address first - it may take a while
705
- return (esp_bt_gap_start_discovery (inq_mode, inq_len, inq_num_rsps ) == ESP_OK);
698
+ return (esp_bt_gap_start_discovery (ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS ) == ESP_OK);
706
699
} else {
707
700
log_e (" Neither Remote name nor address was provided" );
708
701
}
@@ -725,15 +718,15 @@ bool BluetoothSerial::connected() {
725
718
bool BluetoothSerial::isReady (bool checkMaster)
726
719
{
727
720
if (checkMaster && !_isMaster) {
728
- log_e (" Master mode is not active. Call begin(localName, true) to enanbe Master mode" );
721
+ log_e (" Master mode is not active. Call begin(localName, true) to enable Master mode" );
729
722
return false ;
730
723
}
731
724
// btStarted() is not sufficient to indicate ESP_SPP_INIT_EVT is complete
732
725
if (_isInitializing) {
733
726
int retry = 10 ;
734
727
do {
735
728
delay (500 );
736
- log_i (" waiting for intialization to complete..." );
729
+ log_i (" waiting for initialization to complete..." );
737
730
} while (!_isInitialized && retry-- > 0 );
738
731
}
739
732
if (!_isInitialized) {
0 commit comments