@@ -235,26 +235,34 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
235
235
break ;
236
236
237
237
case ESP_SPP_SRV_OPEN_EVT:// Server connection open
238
- log_i (" ESP_SPP_SRV_OPEN_EVT" );
239
- if (!_spp_client){
240
- _spp_client = param->open .handle ;
238
+ if (param->srv_open .status == ESP_SPP_SUCCESS) {
239
+ log_i (" ESP_SPP_SRV_OPEN_EVT" );
240
+ if (!_spp_client){
241
+ _spp_client = param->srv_open .handle ;
242
+ } else {
243
+ secondConnectionAttempt = true ;
244
+ esp_spp_disconnect (param->srv_open .handle );
245
+ }
246
+ xEventGroupClearBits (_spp_event_group, SPP_DISCONNECTED);
247
+ xEventGroupSetBits (_spp_event_group, SPP_CONNECTED);
241
248
} else {
242
- secondConnectionAttempt = true ;
243
- esp_spp_disconnect (param->open .handle );
249
+ log_e (" ESP_SPP_SRV_OPEN_EVT Failed!, status:%d" , param->srv_open .status );
244
250
}
245
- xEventGroupClearBits (_spp_event_group, SPP_DISCONNECTED);
246
- xEventGroupSetBits (_spp_event_group, SPP_CONNECTED);
247
251
break ;
248
252
249
253
case ESP_SPP_CLOSE_EVT:// Client connection closed
250
- log_i (" ESP_SPP_CLOSE_EVT" );
251
- if (secondConnectionAttempt) {
252
- secondConnectionAttempt = false ;
254
+ if ((param->close .async == false && param->close .status == ESP_SPP_SUCCESS) || param->close .async ) {
255
+ log_i (" ESP_SPP_CLOSE_EVT" );
256
+ if (secondConnectionAttempt) {
257
+ secondConnectionAttempt = false ;
258
+ } else {
259
+ _spp_client = 0 ;
260
+ xEventGroupSetBits (_spp_event_group, SPP_DISCONNECTED);
261
+ }
262
+ xEventGroupClearBits (_spp_event_group, SPP_CONNECTED);
253
263
} else {
254
- _spp_client = 0 ;
255
- xEventGroupSetBits (_spp_event_group, SPP_DISCONNECTED);
256
- }
257
- xEventGroupClearBits (_spp_event_group, SPP_CONNECTED);
264
+ log_e (" ESP_SPP_CLOSE_EVT failed!, status:%d" , param->close .status );
265
+ }
258
266
break ;
259
267
260
268
case ESP_SPP_CONG_EVT:// connection congestion status changed
@@ -267,11 +275,15 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
267
275
break ;
268
276
269
277
case ESP_SPP_WRITE_EVT:// write operation completed
270
- if (param->write .cong ){
271
- xEventGroupClearBits (_spp_event_group, SPP_CONGESTED);
278
+ if (param->write .status == ESP_SPP_SUCCESS) {
279
+ if (param->write .cong ){
280
+ xEventGroupClearBits (_spp_event_group, SPP_CONGESTED);
281
+ }
282
+ xSemaphoreGive (_spp_tx_done);// we can try to send another packet
283
+ log_v (" ESP_SPP_WRITE_EVT: %u %s" , param->write .len , param->write .cong ?" CONGESTED" :" " );
284
+ } else {
285
+ log_e (" ESP_SPP_WRITE_EVT failed!, status:%d" , param->write .status );
272
286
}
273
- xSemaphoreGive (_spp_tx_done);// we can try to send another packet
274
- log_v (" ESP_SPP_WRITE_EVT: %u %s" , param->write .len , param->write .cong ?" CONGESTED" :" FREE" );
275
287
break ;
276
288
277
289
case ESP_SPP_DATA_IND_EVT:// connection received data
@@ -296,6 +308,8 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
296
308
if (param->disc_comp .status == ESP_SPP_SUCCESS) {
297
309
log_i (" ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote" );
298
310
esp_spp_connect (ESP_SPP_SEC_AUTHENTICATE, ESP_SPP_ROLE_MASTER, param->disc_comp .scn [0 ], _peer_bd_addr);
311
+ } else {
312
+ log_e (" ESP_SPP_DISCOVERY_COMP_EVT failed!, status:%d" , param->disc_comp .status );
299
313
}
300
314
break ;
301
315
@@ -532,9 +546,9 @@ static bool _init_bt(const char *deviceName)
532
546
return false ;
533
547
}
534
548
535
- if (esp_bt_sleep_disable () != ESP_OK){
536
- log_e (" esp_bt_sleep_disable failed" );
537
- }
549
+ // if (esp_bt_sleep_disable() != ESP_OK){
550
+ // log_e("esp_bt_sleep_disable failed");
551
+ // }
538
552
539
553
log_i (" device name set" );
540
554
esp_bt_dev_set_device_name (deviceName);
0 commit comments