36
36
#include " esp_spp_api.h"
37
37
#include < esp_log.h>
38
38
39
- #ifdef ARDUINO_ARCH_ESP32
40
39
#include " esp32-hal-log.h"
41
- #endif
42
40
43
41
const char * _spp_server_name = " ESP32SPP" ;
44
42
@@ -52,6 +50,7 @@ static TaskHandle_t _spp_task_handle = NULL;
52
50
static EventGroupHandle_t _spp_event_group = NULL ;
53
51
static boolean secondConnectionAttempt;
54
52
static esp_spp_cb_t * custom_spp_callback = NULL ;
53
+ static BluetoothSerialDataCb custom_data_callback = NULL ;
55
54
56
55
#define INQ_LEN 0x10
57
56
#define INQ_NUM_RSPS 20
@@ -218,7 +217,6 @@ static void _spp_tx_task(void * arg){
218
217
_spp_task_handle = NULL ;
219
218
}
220
219
221
-
222
220
static void esp_spp_cb (esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
223
221
{
224
222
switch (event)
@@ -278,7 +276,9 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
278
276
// esp_log_buffer_hex("",param->data_ind.data,param->data_ind.len); //for low level debug
279
277
// ets_printf("r:%u\n", param->data_ind.len);
280
278
281
- if (_spp_rx_queue != NULL ){
279
+ if (custom_data_callback){
280
+ custom_data_callback (param->data_ind .data , param->data_ind .len );
281
+ } else if (_spp_rx_queue != NULL ){
282
282
for (int i = 0 ; i < param->data_ind .len ; i++){
283
283
if (xQueueSend (_spp_rx_queue, param->data_ind .data + i, (TickType_t)0 ) != pdTRUE){
284
284
log_e (" RX Full! Discarding %u bytes" , param->data_ind .len - i);
@@ -322,6 +322,10 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
322
322
if (custom_spp_callback)(*custom_spp_callback)(event, param);
323
323
}
324
324
325
+ void BluetoothSerial::onData (BluetoothSerialDataCb cb){
326
+ custom_data_callback = cb;
327
+ }
328
+
325
329
static void esp_bt_gap_cb (esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
326
330
{
327
331
switch (event){
@@ -469,7 +473,7 @@ static bool _init_bt(const char *deviceName)
469
473
}
470
474
471
475
if (!_spp_task_handle){
472
- xTaskCreate (_spp_tx_task, " spp_tx" , 4096 , NULL , 2 , &_spp_task_handle);
476
+ xTaskCreatePinnedToCore (_spp_tx_task, " spp_tx" , 4096 , NULL , 2 , &_spp_task_handle, 0 );
473
477
if (!_spp_task_handle){
474
478
log_e (" Network Event Task Start Failed!" );
475
479
return false ;
@@ -511,6 +515,10 @@ static bool _init_bt(const char *deviceName)
511
515
return false ;
512
516
}
513
517
518
+ if (esp_bt_sleep_disable () != ESP_OK){
519
+ log_e (" esp_bt_sleep_disable failed" );
520
+ }
521
+
514
522
log_i (" device name set" );
515
523
esp_bt_dev_set_device_name (deviceName);
516
524
0 commit comments