Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bt_discovery example can't find bluetooth speaker (IDFGH-4742) #6548

Closed
nopnop2002 opened this issue Feb 15, 2021 · 3 comments
Closed

bt_discovery example can't find bluetooth speaker (IDFGH-4742) #6548

nopnop2002 opened this issue Feb 15, 2021 · 3 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@nopnop2002
Copy link

nopnop2002 commented Feb 15, 2021

Environment

freeRTOS version:V10.2.1
NEWLIB version:3.0.0
portTICK_RATE_MS:10 msec/tick
lwIP version:2-1-3-0
ESP-IDF version:v4.3-dev-2586-g526f68239-dirty
chip model is 1, chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash
package is ESP32D0WDQ6

Problem Description

bt_discovery example can't find bluetooth speaker

My trial

I changed some code.

#if 0
    if (!esp_bt_gap_is_valid_cod(cod) ||
            !(esp_bt_gap_get_cod_major_dev(cod) == ESP_BT_COD_MAJOR_DEV_PHONE)) {
        return;
    }
#endif

    /* search for device with MAJOR service class as "rendering" in COD */
    if (!esp_bt_gap_is_valid_cod(cod) ||
            !(esp_bt_gap_get_cod_srvc(cod) & ESP_BT_COD_SRVC_RENDERING)) {
        return;
    }

It can find bluetooth speaker.

I (0) cpu_start: Starting scheduler on APP CPU.
I (564) system_api: Base MAC address is not set
I (564) system_api: read default base MAC address from EFUSE
I (564) BTDM_INIT: BT controller compile version [b62cb38]
I (574) phy_init: phy_version 4660,0162888,Dec 23 2020
I (1234) GAP: Discovery started.
I (1274) GAP: Device found: 83:21:5d:9a:62:bd
I (1274) GAP: --Class of Device: 0x340404
I (1274) GAP: --RSSI: -44
I (1274) GAP: Found a target device, address 83:21:5d:9a:62:bd, name TG-148 -----> *
I (1284) GAP: Cancel device discovery ...
I (1284) GAP: Device found: 83:21:5d:9a:62:bd
I (1294) GAP: --Class of Device: 0x340404
I (1294) GAP: --RSSI: -44
I (1304) GAP: Device discovery stopped.
I (1304) GAP: Discover services ...
I (2764) GAP: Services for device 83:21:5d:9a:62:bd found
I (2764) GAP: --1101
I (2764) GAP: --111e
I (2764) GAP: --110b
I (2764) GAP: --110e
@github-actions github-actions bot changed the title bt_discovery example can't find bluetooth speaker bt_discovery example can't find bluetooth speaker (IDFGH-4742) Feb 15, 2021
@rahult-github
Copy link
Collaborator

Hi nopnop2002
This bt_discovery example shows the usage of the APIs and how they can be used to invoke discovery using ESP SDK. The existing code searches for devices and currently checks for Phone as Major device class.

The check of using rendering service class may work for your case. However, to make it more generic, need to check for correct major class. Have tried to put better check conditions. Can you please try with attached patch and share your observation ?

cod_patch.txt

Thanks,
Rahul

@nopnop2002
Copy link
Author

nopnop2002 commented Feb 16, 2021

@RahulEspressif

Thank you for the replay.
I have tried your code.
But it can't find my speaker.

    ESP_LOGI(GAP_TAG, "esp_bt_gap_is_valid_cod(cod)=%x", esp_bt_gap_is_valid_cod(cod));
    ESP_LOGI(GAP_TAG, "esp_bt_gap_get_cod_major_dev(cod)=%x", esp_bt_gap_get_cod_major_dev(cod));
    if (!esp_bt_gap_is_valid_cod(cod) ||
        !(esp_bt_gap_get_cod_major_dev(cod) == ESP_BT_COD_MAJOR_DEV_PHONE) ||
        !(esp_bt_gap_get_cod_major_dev(cod) == ESP_BT_COD_MAJOR_DEV_AV)) {
        return;
    }
I (14198) GAP: esp_bt_gap_is_valid_cod(cod)=1
I (14198) GAP: esp_bt_gap_get_cod_major_dev(cod)=4
I (14208) GAP: Device found: 83:21:5d:9a:62:bd -----> This is my bluetooth speaker
I (14208) GAP: --Class of Device: 0x340404
I (14218) GAP: --RSSI: -62
I (14218) GAP: esp_bt_gap_is_valid_cod(cod)=1
I (14228) GAP: esp_bt_gap_get_cod_major_dev(cod)=4
I (14228) GAP: Device found: 83:21:5d:9a:62:bd
I (14238) GAP: --Class of Device: 0x340404
I (14238) GAP: --RSSI: -62
I (14238) GAP: esp_bt_gap_is_valid_cod(cod)=1
I (14248) GAP: esp_bt_gap_get_cod_major_dev(cod)=4
I (14258) GAP: Device discovery stopped.

So I change a little.

    ESP_LOGI(GAP_TAG, "esp_bt_gap_is_valid_cod(cod)=%x", esp_bt_gap_is_valid_cod(cod));
    ESP_LOGI(GAP_TAG, "esp_bt_gap_get_cod_major_dev(cod)=%x", esp_bt_gap_get_cod_major_dev(cod));
    if (!esp_bt_gap_is_valid_cod(cod) ||
        (!(esp_bt_gap_get_cod_major_dev(cod) == ESP_BT_COD_MAJOR_DEV_PHONE) &&
        !(esp_bt_gap_get_cod_major_dev(cod) == ESP_BT_COD_MAJOR_DEV_AV))) {
        return;
    }

It is work fine.

I (1258) GAP: esp_bt_gap_is_valid_cod(cod)=1
I (1258) GAP: esp_bt_gap_get_cod_major_dev(cod)=4
I (1268) GAP: Found a target device, address 83:21:5d:9a:62:bd, name TG-148 ---> This is my bluetooth speaker
I (1278) GAP: Cancel device discovery ...
I (1278) GAP: Device found: 83:21:5d:9a:62:bd
I (1288) GAP: --Class of Device: 0x340404
I (1288) GAP: --RSSI: -42
I (1288) GAP: esp_bt_gap_is_valid_cod(cod)=1
I (1298) GAP: esp_bt_gap_get_cod_major_dev(cod)=4
I (1308) GAP: Device found: 83:21:5d:9a:62:bd
I (1308) GAP: --Class of Device: 0x340404
I (1308) GAP: --RSSI: -43
I (1318) GAP: esp_bt_gap_is_valid_cod(cod)=1
I (1318) GAP: esp_bt_gap_get_cod_major_dev(cod)=4
I (1328) GAP: Device discovery stopped.
I (1328) GAP: Discover services ...
I (2778) GAP: Services for device 83:21:5d:9a:62:bd found
I (2788) GAP: --1101
I (2788) GAP: --111e
I (2788) GAP: --110b
I (2788) GAP: --110e

If it's helpful then i am happy

@rahult-github
Copy link
Collaborator

Thanks. Both cases needed to be checked . Previous patch had incorrect placement of ( bracket. This is what is needed to be changed.

espressif-bot pushed a commit that referenced this issue May 8, 2021
Current code stopped inquiry if major class is not Phone. Modified the
condition to consider for both Phone and Audio to cover majority of real
world devices.

Closes #6548
projectgus pushed a commit that referenced this issue May 21, 2021
Current code stopped inquiry if major class is not Phone. Modified the
condition to consider for both Phone and Audio to cover majority of real
world devices.

Closes #6548
@espressif-bot espressif-bot added Resolution: Done Issue is done internally Status: Done Issue is done internally labels May 24, 2021
projectgus pushed a commit that referenced this issue Jun 8, 2021
Current code stopped inquiry if major class is not Phone. Modified the
condition to consider for both Phone and Audio to cover majority of real
world devices.

Closes #6548
espressif-bot pushed a commit that referenced this issue Jun 11, 2021
Current code stopped inquiry if major class is not Phone. Modified the
condition to consider for both Phone and Audio to cover majority of real
world devices.

Closes #6548
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

3 participants