How to send connection request?

jki131
Posts: 5
Joined: Thu Feb 18, 2021 10:55 pm

How to send connection request?

Postby jki131 » Thu Feb 18, 2021 11:02 pm

Hello, Im testing bluetooth in esp32 and i want to send connection request but it doesn't seem to work. I tried something like this:

Code: Select all

void send_con_rq() {
    unsigned char p[17] = {0x01, 0x05, 0x04, 0x0d, 0xAB, 0xCD, 0xEF, 0x7D, 0x1A, 0x00, 0x18, 0xcc, 0x02 ,0x00, 0x00, 0x00, 0x00};
    esp_vhci_host_send_packet(p, 17);
}
But connection is not quiet working. Its dropping after few packets. I think its because i enabled bluedroid but when i don't enable it i get following error:

Code: Select all

ASSERT_ERR(lm_env.local_name), in lm.c at line 79
Guru Meditation Error: Core  0 panic'ed (Interrupt wdt timeout on CPU0). 

Core  0 register dump:
PC      : 0x400830b0  PS      : 0x00060234  A0      : 0x80109085  A1      : 0x3ffc8550  
0x400830b0: r_assert_err at ??:?

A2      : 0x00000001  A3      : 0x00000000  A4      : 0x60008048  A5      : 0x3ffbdbe4  
A6      : 0x3ffbdbe4  A7      : 0x00000000  A8      : 0x800830b0  A9      : 0x3ffc8530  
A10     : 0x00000032  A11     : 0x00000032  A12     : 0x00000010  A13     : 0xffffffff  
A14     : 0x00000000  A15     : 0xfffffffd  SAR     : 0x00000004  EXCCAUSE: 0x00000005  
EXCVADDR: 0x00000000  LBEG    : 0x40083058  LEND    : 0x4008305f  LCOUNT  : 0x00000000  
0x40083058: r_assert_err at ??:?

0x4008305f: r_assert_err at ??:?


Backtrace:0x400830ad:0x3ffc8550 0x40109082:0x3ffc8570 0x4002509e:0x3ffc8590 0x400ff522:0x3ffc85d0 0x4008403e:0x3ffc85f0 0x40019d11:0x3ffc8620 0x40055b4d:0x3ffc8640 0x400faf8f:0x3ffc8660 0x400fb581:0x3ffc8680 0x40092b7d:0x3ffc86b0
0x400830ad: r_assert_err at ??:?

0x40109082: r_LM_GetLocalNameSeg at ??:?

0x400ff522: lc_lmp_rx_handler at ??:?

0x4008403e: ke_task_schedule at ke_task.c:?

0x400faf8f: r_rw_schedule at ??:?

0x400fb581: btdm_controller_task at ??:?

0x40092b7d: vPortTaskWrapper at /home/user/esp/esp-idf/components/freertos/port/xtensa/port.c:168

Core  1 register dump:
PC      : 0x4012e40e  PS      : 0x00060834  A0      : 0x800d7216  A1      : 0x3ffbd8b0  
0x4012e40e: esp_pm_impl_waiti at /home/user/esp/esp-idf/components/esp_pm/pm_impl.c:780

A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000001  A5      : 0x80000001  
A6      : 0x00000003  A7      : 0x00060023  A8      : 0x80110f1a  A9      : 0x3ffbd880  
A10     : 0x00000000  A11     : 0x00060823  A12     : 0x00060820  A13     : 0x00060823  
A14     : 0x00000001  A15     : 0x00000001  SAR     : 0x0000000d  EXCCAUSE: 0x00000005  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  

Backtrace:0x4012e40b:0x3ffbd8b0 0x400d7213:0x3ffbd8d0 0x40091011:0x3ffbd8f0 0x40092b7d:0x3ffbd910
0x4012e40b: cpu_ll_waiti at /home/user/esp/esp-idf/components/hal/esp32/include/hal/cpu_ll.h:183
 (inlined by) esp_pm_impl_waiti at /home/user/esp/esp-idf/components/esp_pm/pm_impl.c:778

0x400d7213: esp_vApplicationIdleHook at /home/user/esp/esp-idf/components/esp_common/src/freertos_hooks.c:63

0x40091011: prvIdleTask at /home/user/esp/esp-idf/components/freertos/tasks.c:3835 (discriminator 1)

0x40092b7d: vPortTaskWrapper at /home/user/esp/esp-idf/components/freertos/port/xtensa/port.c:168
Is there any better way to send connection request?

User avatar
WardMas
Posts: 75
Joined: Fri Jun 19, 2020 9:09 am

Re: How to send connection request?

Postby WardMas » Fri Feb 19, 2021 4:47 am

Hi,
As far as I know without enabling Bluedroid, you can't do any Bluetooth related operation. If you are using BT classic, then you need to activate on of the ESP32 supported classes (HFP, A2DP or SPP) to be able to establish a connection since initializing one of the mentioned classes will enable service discovery protocol, which is responsible for BT classic communication. Personally, I initialized BT GAP with HFP and could do connection request using

Code: Select all

 esp_hf_client_connect(esp_bd_addr_t remote_bda);
which takes bluetooth device address pointer as a parameter and if the required device is nearby, the connection will occur right away. I could get the the device address by pairing with it, which will store the address in the NOR flash. you can obtain all the paired devices address using

Code: Select all

esp_bt_gap_get_bond_device_list(int *dev_num, esp_bd_addr_t *dev_list);
If you are working o BLE then you need to initialize your device as GATT client. once you have done that correctly, then you can call

Code: Select all

esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct);
to open a connection. Have a look at the ESP-IDF examples to see how init operations are done correctly.
Last edited by WardMas on Fri Feb 19, 2021 9:51 am, edited 2 times in total.
You can always visit my YouTube channel for embedded systems related tutorials
https://youtube.com/user/wardzx1

jki131
Posts: 5
Joined: Thu Feb 18, 2021 10:55 pm

Re: How to send connection request?

Postby jki131 » Fri Feb 19, 2021 7:23 am

Hi, thanks for response.
Is it possible to connect to device without using HFP, A2DP or SPP classes?
I want to connect to device and read rssi, and link quality. I can do the same thing on linux using hcitool commands:
hcitool cc AB:CD:EF:00:00:00
hcitool rssi AB:CD:EF:00:00:00
hcitool lq AB:CD:EF:00:00:00

Can i use esp32 for the same thing and connect to device that doesn't use HFP, A2DP or SPP classes?

User avatar
WardMas
Posts: 75
Joined: Fri Jun 19, 2020 9:09 am

Re: How to send connection request?

Postby WardMas » Fri Feb 19, 2021 9:48 am

I ran into the same issue before and could not establish a connection until I initialized HFP. this issue in ESP32 Bluetooth architecture document:
2.1.2.SDP The Service Discovery Protocol (SDP) provides a means for applications to discover services offered by a peer Bluetooth device, as well as to determine the characteristics of the available services. The SDP involves communication between an SDP server and an SDP client. A server maintains a list of service records that describe the characteristics of services associated with the server. A client can retrieve this information by issuing an SDP request. Both SDP client and server are implemented in the Host stack, and this module is only used by profiles, such as A2DP and AVRCP, and does not provide APIs for user applications at the moment.
You can always visit my YouTube channel for embedded systems related tutorials
https://youtube.com/user/wardzx1

jki131
Posts: 5
Joined: Thu Feb 18, 2021 10:55 pm

Re: How to send connection request?

Postby jki131 » Sat Feb 20, 2021 10:33 pm

Hello, i done more testing of this and it looks like the connection that i established using function send_con_rq() code that i sent here before is always dropping after 10 seconds. I tried establish connection with hf initiated and using funtion esp_hf_client_connect but i doesn't work. if i establish connection using esp_hf_client_connect its get dropped when it doesn't found hf profile. I also tried disabling modem sleep and it also doesn't help.

Is there any function that allows me to change connection timeout from 10 seconds to something more?

jki131
Posts: 5
Joined: Thu Feb 18, 2021 10:55 pm

Re: How to send connection request?

Postby jki131 » Sun Feb 21, 2021 12:47 pm

How i can include btm_api.h to my code, so i can use BTM_CreateSco function?

Who is online

Users browsing this forum: No registered users and 118 guests