Classic Bluetooth: How to detect the start of pairing.

Badziol
Posts: 1
Joined: Mon Nov 15, 2021 12:40 am

Classic Bluetooth: How to detect the start of pairing.

Postby Badziol » Sun Feb 27, 2022 1:20 pm

I am asking for help with a problem that I cannot deal with.
First :
I am using an Arduino-IDE with \ esp32 \ 1.0.6 \ core
I use the library: https://github.com/2dom/PxMatrix
I'm using a board: ESP32 Wrover Dev Kit

I often get an error only when pairing ESP32 with the phone application:

Code: Select all

Guru Meditation Error: Core  1 panic'ed (Cache disabled but cached memory region accessed)
Core 1 register dump:
PC      : 0x400d33b0  PS      : 0x00060034  A0      : 0x800816ec  A1      : 0x3ffbfa60  
A2      : 0x3ffbdd64  A3      : 0x20000000  A4      : 0x00000400  A5      : 0x00000000  
A6      : 0x3ffd6470  A7      : 0xffffffff  A8      : 0x800812eb  A9      : 0x3ffbfa30  
A10     : 0x3ffc4030  A11     : 0x00000028  A12     : 0x00000001  A13     : 0x00000001  
A14     : 0x00060021  A15     : 0x00000000  SAR     : 0x0000001f  EXCCAUSE: 0x00000007  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  
Core 1 was running in ISR context:
EPC1    : 0x40090934  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x400d33b0

ELF file SHA256: 0000000000000000

Backtrace: 0x400d33b0:0x3ffbfa60 0x400816e9:0x3ffbfa80 0x40090209:0x3ffbfaa0 0x40090931:0x3ffba300 0x40084e17:0x3ffba320 0x40095436:0x3ffba340
Visual micro decode to this :

Code: Select all

Exception:Error:
C:\Users\User\Documents\Arduino\LEDP_02/cView.h(660): error 0x400d33b0:xMATRIX
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/spi_flash/cache_utils.c:203:::0x40090934:spi_flash_op_block_func
C:\Users\User\AppData\Local\arduino15\packages\esp32\hardware\esp32\1.0.6\cores\esp32/esp32-hal-timer.c(174): error 0x400816e9:__timerISR
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/xtensa_vectors.S:1154:::0x40090209:_xt_lowint1
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/spi_flash/cache_utils.c:203:::0x40090931:spi_flash_op_block_func
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/ipc.c:62:::0x40084e17:ipc_task
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1):::0x40095436:vPortTaskWrapper
0x40078000: ?? ??:0
0x40080400: ?? ??:0
0x400806b4: ?? ??:0
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/spi_flash/cache_utils.c:203:::0x4009093d:spi_flash_op_block_func
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/spi_flash/cache_utils.c:203:::0x4009093a:spi_flash_op_block_func
The effect of this error is:
The phone has a new Bt device on the list but not the ESP32 module or vice versa.
Then I have to:
esp_bt_gap_remove_bond_device (...) and manually remove bound from the phone.
Start the pairing process and hope for the best.
When the connection is correct, I have no problems sending and receiving data.

I think this part of the code is causing the problem:

Code: Select all

#define INTERRUPT_ATTR IRAM_ATTR
hw_timer_t* timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
uint8_t display_draw_time = 40;
//-------------------------------------------------------------------------
void IRAM_ATTR display_updater() {
    // Increment the counter and set the time of ISR
    portENTER_CRITICAL_ISR(&timerMux);
    display.display(display_draw_time);
    portEXIT_CRITICAL_ISR(&timerMux);
};
//-------------------------------------------------------------------------
void display_update_enable(bool is_enable) {
    if (is_enable)
    {
        timer = timerBegin(1, 80, true); //0->1   /*  0,1,2,3-avible timers  ,  (1 tick take 1/(80MHZ/80) = 1us so we set divider 80) , count up */
        timerAttachInterrupt(timer, &display_updater, true); 
        timerAlarmWrite(timer, 4000, true);//2000->4000 (1000000 = 1s) autoreload = repeat
        timerAlarmEnable(timer);
    }
    else
    {
        timerDetachInterrupt(timer);
        timerAlarmDisable(timer);
    }
};
My first idea is to register in setup:

Code: Select all

    BT.register_callback(myBtcallbackSpp);
	//BT.enableSSP(); //no needed at this point
	BT.setPin("3333");//It doesn't work , but  know at least why 
    BT.begin("LEDS_test");

	esp_err_t ret;
	if ((ret = esp_bt_gap_register_callback(myBtCallbackGap)) != ESP_OK) {
		Serial.println("[************] MY GAP event NOT registered!");
	}
	else {
		Serial.println("[************] MY GAP OK!");
	};
	ShowOrDeletePairedDevices();
	printDeviceAddress();
	//BT.setPin("3333");
    Serial.println("---SPP , GAP CALLBACKS ----");
I have information from ESP_BT_GAP_AUTH_CMPL_EVT when
pairing is successful but how do you know when it starts?

I checked :
/// BT GAP callback events
typedef enum {
ESP_BT_GAP_DISC_RES_EVT = 0, /*!< device discovery result event */
ESP_BT_GAP_DISC_STATE_CHANGED_EVT, /*!< discovery state changed event */
ESP_BT_GAP_RMT_SRVCS_EVT, /*!< get remote services event */
ESP_BT_GAP_RMT_SRVC_REC_EVT, /*!< get remote service record event */
ESP_BT_GAP_AUTH_CMPL_EVT, /*!< AUTH complete event */
ESP_BT_GAP_PIN_REQ_EVT, /*!< Legacy Pairing Pin code request */
ESP_BT_GAP_CFM_REQ_EVT, /*!< Simple Pairing User Confirmation request. */
ESP_BT_GAP_KEY_NOTIF_EVT, /*!< Simple Pairing Passkey Notification */
ESP_BT_GAP_KEY_REQ_EVT, /*!< Simple Pairing Passkey request */
ESP_BT_GAP_READ_RSSI_DELTA_EVT, /*!< read rssi event */
ESP_BT_GAP_REMOVE_BOND_DEV_COMPLETE_EVT, /*!< remove bond device complete event */
ESP_BT_GAP_EVT_MAX,
} esp_bt_gap_cb_event_t;

typedef enum {
ESP_SPP_INIT_EVT = 0, /*!< When SPP is inited, the event comes */
ESP_SPP_UNINIT_EVT = 1, /*!< When SPP is uninited, the event comes */
ESP_SPP_DISCOVERY_COMP_EVT = 8, /*!< When SDP discovery complete, the event comes */
ESP_SPP_OPEN_EVT = 26, /*!< When SPP Client connection open, the event comes */
ESP_SPP_CLOSE_EVT = 27, /*!< When SPP connection closed, the event comes */
ESP_SPP_START_EVT = 28, /*!< When SPP server started, the event comes */
ESP_SPP_CL_INIT_EVT = 29, /*!< When SPP client initiated a connection, the event comes */
ESP_SPP_DATA_IND_EVT = 30, /*!< When SPP connection received data, the event comes, only for ESP_SPP_MODE_CB */
ESP_SPP_CONG_EVT = 31, /*!< When SPP connection congestion status changed, the event comes, only for ESP_SPP_MODE_CB */
ESP_SPP_WRITE_EVT = 33, /*!< When SPP write operation completes, the event comes, only for ESP_SPP_MODE_CB */
ESP_SPP_SRV_OPEN_EVT = 34, /*!< When SPP Server connection open, the event comes */
ESP_SPP_SRV_STOP_EVT = 35, /*!< When SPP server stopped, the event comes */
} esp_spp_cb_event_t;

My idea is to turn it off ( display_update_enable(false); ) at the beginning of pairing process, but how to do it ?
Is there a better solution?

kejuqeju
Posts: 1
Joined: Sun Oct 13, 2024 5:48 am

Re: Classic Bluetooth: How to detect the start of pairing.

Postby kejuqeju » Sun Oct 13, 2024 5:51 am

i have exactly the same problem. and yes, i use interrupt timer for scanning p5 display also. when i stop the timer, the pairing process goes normally. does anyone have solved this problem?

Who is online

Users browsing this forum: No registered users and 45 guests