HFP AG connection.

allex1978
Posts: 3
Joined: Sat Apr 13, 2019 12:37 am

HFP AG connection.

Postby allex1978 » Mon Apr 15, 2019 9:58 pm

Hi, i`m trying to rebuild a2dp_sink example to HFP and can`t open AG. I enabled Voice Over HCI via menuconfig. Then added

Code: Select all

        
esp_hf_client_init();
esp_hf_client_register_callback(esp_hf_client_cb);
esp_hf_client_register_data_callback(esp_hf_client_incoming_data_cb,esp_hf_client_outgoing_data_cb);
esp_bd_addr_t remote_bda = {0x24,0xda,0x9b,0x76,0xf4,0x5a};
esp_hf_client_connect(remote_bda);
to main.c
added callbacks to bt_app_av.c

Code: Select all

void esp_hf_client_cb(esp_hf_client_cb_event_t event, esp_hf_client_cb_param_t *param)
{
    esp_hf_client_cb_param_t *hpf = NULL;
    switch (event) {
    case ESP_HF_CLIENT_CONNECTION_STATE_EVT:
        hpf = (esp_hf_client_cb_param_t *)(param);
        uint8_t *bda = hpf->conn_stat.remote_bda;
        ESP_LOGI(BT_AV_TAG,"HPF connection state: %s, [%02x:%02x:%02x:%02x:%02x:%02x]",
             s_hpf_conn_state_str[hpf->conn_stat.state], bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
        if(hpf->conn_stat.state==ESP_HF_CLIENT_CONNECTION_STATE_SLC_CONNECTED){
			esp_err_t ret = esp_hf_client_connect_audio(hpf->conn_stat.remote_bda);
			if (ret != ESP_OK) {
					ESP_LOGE(BT_AV_TAG, "Audio connect failed: %s", esp_err_to_name(ret));
				}
		}
		break;
        
    case ESP_HF_CLIENT_AUDIO_STATE_EVT: 
        hpf = (esp_hf_client_cb_param_t *)(param);
        ESP_LOGI(BT_AV_TAG,"HPF Audio connection state: %s",s_hfp_audio_conn_state_str[hpf->audio_stat.state]);  
		break;
	
	case ESP_HF_CLIENT_BVRA_EVT:                          /*!< voice recognition state change event */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_BVRA_EVT");
		break;
    case ESP_HF_CLIENT_CIND_CALL_EVT:                     /*!< call indication */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_CIND_CALL_EVT");
		break;
    case ESP_HF_CLIENT_CIND_CALL_SETUP_EVT:               /*!< call setup indication */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_CIND_CALL_SETUP_EVT");
		break;    
	case ESP_HF_CLIENT_CIND_CALL_HELD_EVT:                /*!< call held indication */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_CIND_CALL_HELD_EVT");
		break;
    case ESP_HF_CLIENT_CIND_SERVICE_AVAILABILITY_EVT:     /*!< network service availability indication */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_CIND_SERVICE_AVAILABILITY_EVT");
		break;
    case ESP_HF_CLIENT_CIND_SIGNAL_STRENGTH_EVT:          /*!< signal strength indication */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_CIND_SIGNAL_STRENGTH_EVT");
		break;    
	case ESP_HF_CLIENT_CIND_ROAMING_STATUS_EVT:           /*!< roaming status indication */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_CIND_ROAMING_STATUS_EVT");
		break;
    case ESP_HF_CLIENT_CIND_BATTERY_LEVEL_EVT:            /*!< battery level indication */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_CIND_BATTERY_LEVEL_EVT");
		break;
    case ESP_HF_CLIENT_COPS_CURRENT_OPERATOR_EVT:         /*!< current operator information */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_COPS_CURRENT_OPERATOR_EVT");
		break;
    case ESP_HF_CLIENT_BTRH_EVT:                          /*!< call response and hold event */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_BTRH_EVT");
		break;
    case ESP_HF_CLIENT_CLIP_EVT:                          /*!< Calling Line Identification notification */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_CLIP_EVT");
		break;
    case ESP_HF_CLIENT_CCWA_EVT:                          /*!< call waiting notification */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_CCWA_EVT");
		break;
    case ESP_HF_CLIENT_CLCC_EVT:                          /*!< list of current calls notification */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_CLCC_EVT");
		break;
    case ESP_HF_CLIENT_VOLUME_CONTROL_EVT:                /*!< audio volume control command from AG, provided by +VGM or +VGS message */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_VOLUME_CONTROL_EVT");
		break;
    case ESP_HF_CLIENT_AT_RESPONSE_EVT:                   /*!< AT command response event */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_AT_RESPONSE_EVT");
		break;
    case ESP_HF_CLIENT_CNUM_EVT:                          /*!< subscriber information response from AG */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_CNUM_EVT");
		break;
    case ESP_HF_CLIENT_BSIR_EVT:                          /*!< setting of in-band ring tone */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_BSIR_EVT");
		break;
    case ESP_HF_CLIENT_BINP_EVT:                          /*!< requested number of last voice tag from AG */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_BINP_EVT");
		break;
    case ESP_HF_CLIENT_RING_IND_EVT:                      /*!< ring indication event */
		ESP_LOGI(BT_AV_TAG,"HPF event ESP_HF_CLIENT_RING_IND_EVT");
		break;
    default:
        ESP_LOGE(BT_AV_TAG,"Invalid HPF event: %d", event);
        break;
    }
}

void esp_hf_client_incoming_data_cb(const uint8_t *buf, uint32_t len){
  ESP_LOGI(BT_AV_TAG,"data= %d",(uint8_t)buf);
}

uint32_t esp_hf_client_outgoing_data_cb(uint8_t *buf, uint32_t len){
  ESP_LOGI(BT_AV_TAG,"data1= %d",(uint8_t)buf);
  return 0;
}

i`m trying to use esp_hf_client_connect_audio after Service Layer is connected. esp_hf_client_connect_audio function sends AT+BCC then AT+BCS=1 then got OK responce and stops. HPF Audio connection state changed to "Connecting" but never get the "Connected" state. ESP32 disconnects from phone when i`m trying to make a call. hf_client_data callbacks are never fire.

i added some ESP_LOGI("hf_mydebug",....) to bt functions to trace the events and got this:

Code: Select all

ets Jun  8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:6724
load:0x40078000,len:11984
load:0x40080400,len:7372
entry 0x40080780
[0;32mI (28) boot: ESP-IDF v4.0-dev-266-ge7f85f198-dirty 2nd stage bootloader[0m
[0;32mI (29) boot: compile time 00:07:26[0m
[0;32mI (30) boot: Enabling RNG early entropy source...[0m
[0;32mI (35) qio_mode: Enabling default flash chip QIO[0m
[0;32mI (40) boot: SPI Speed      : 80MHz[0m
[0;32mI (44) boot: SPI Mode       : QIO[0m
[0;32mI (48) boot: SPI Flash Size : 4MB[0m
[0;32mI (53) boot: Partition Table:[0m
[0;32mI (56) boot: ## Label            Usage          Type ST Offset   Length[0m
[0;32mI (63) boot:  0 nvs              WiFi data        01 02 00009000 00004000[0m
[0;32mI (71) boot:  1 otadata          OTA data         01 00 0000d000 00002000[0m
[0;32mI (78) boot:  2 phy_init         RF data          01 01 0000f000 00001000[0m
[0;32mI (86) boot:  3 factory          factory app      00 00 00010000 00100000[0m
[0;32mI (93) boot:  4 ota_0            OTA app          00 10 00110000 00100000[0m
[0;32mI (101) boot:  5 ota_1            OTA app          00 11 00210000 00100000[0m
[0;32mI (108) boot: End of partition table[0m
[0;32mI (113) boot: Defaulting to factory image[0m
[0;32mI (117) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x2ca5c (182876) map[0m
[0;32mI (175) esp_image: segment 1: paddr=0x0003ca84 vaddr=0x3ffbdb60 size=0x02aac ( 10924) load[0m
[0;32mI (178) esp_image: segment 2: paddr=0x0003f538 vaddr=0x40080000 size=0x00400 (  1024) load[0m
[0;32mI (182) esp_image: segment 3: paddr=0x0003f940 vaddr=0x40080400 size=0x006d0 (  1744) load[0m
[0;32mI (191) esp_image: segment 4: paddr=0x00040018 vaddr=0x400d0018 size=0x8f584 (587140) map[0m
[0;32mI (354) esp_image: segment 5: paddr=0x000cf5a4 vaddr=0x40080ad0 size=0x11174 ( 70004) load[0m
[0;32mI (388) boot: Loaded app from partition at offset 0x10000[0m
[0;32mI (388) boot: Disabling RNG early entropy source...[0m
[0;32mI (389) cpu_start: Pro cpu up.[0m
[0;32mI (392) cpu_start: Application information:[0m
[0;32mI (397) cpu_start: Project name:     a2dp_sink[0m
[0;32mI (402) cpu_start: App version:      1[0m
[0;32mI (406) cpu_start: Compile time:     Apr 16 2019 00:06:47[0m
[0;32mI (413) cpu_start: ELF file SHA256:  b0943e2b0cceffd6...[0m
[0;32mI (419) cpu_start: ESP-IDF:          v4.0-dev-266-ge7f85f198-dirty[0m
[0;32mI (425) cpu_start: Starting app cpu, entry point is 0x4008105c[0m
[0;32mI (0) cpu_start: App cpu up.[0m
[0;32mI (436) heap_init: Initializing. RAM available for dynamic allocation:[0m
[0;32mI (443) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM[0m
[0;32mI (449) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM[0m
[0;32mI (455) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM[0m
[0;32mI (461) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM[0m
[0;32mI (467) heap_init: At 3FFD0360 len 0000FCA0 (63 KiB): DRAM[0m
[0;32mI (473) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM[0m
[0;32mI (480) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[0m
[0;32mI (486) heap_init: At 40091C44 len 0000E3BC (56 KiB): IRAM[0m
[0;32mI (492) cpu_start: Pro cpu start user code[0m
[0;32mI (174) cpu_start: Starting scheduler on PRO CPU.[0m
[0;32mI (0) cpu_start: Starting scheduler on APP CPU.[0m
[0;32mI (216) I2S: DMA Malloc info, datalen=blocksize=480, dma_buf_count=6[0m
[0;32mI (216) I2S: APLL: Req RATE: 44100, real rate: 43945.238, BITS: 32, CLKM: 1, BCK_M: 4, MCLK: 11249981.000, SCLK: 1406247.625000, diva: 1, divb: 0[0m
[0;32mI (226) BTDM_INIT: BT controller compile version [b638fbb][0m
[0;32mI (226) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE[0m
[0;32mI (326) phy: phy_version: 4100, 6fa5e27, Jan 25 2019, 17:02:06, 0, 0[0m
[0;31mE (876) BT_BTM: btm_sco_process_num_bufs, 4[0m
[0;32mI (906) hf_mydebug: BTA_HfClientRegister[0m
[0;32mI (906) hf_mydebug: BTA_HfClientOpen[0m
[0;32mI (916) hf_mydebug: BTA HF Client State Change: [BTA_HF_CLIENT_INIT_ST] -> [BTA_HF_CLIENT_OPENING_ST] after Event [BTA_HF_CLIENT_API_OPEN_EVT][0m
[0;33mW (1716) BT_APPL: new conn_srvc id:27, app_id:1[0m
[0;32mI (1716) hf_mydebug: bta_hf_client_send_at AT+BRSF=255[0m
[0;32mI (1716) hf_mydebug: BTA HF Client State Change: [BTA_HF_CLIENT_OPENING_ST] -> [BTA_HF_CLIENT_OPEN_ST] after Event [BTA_HF_CLIENT_RFC_OPEN_EVT][0m
[0;32mI (1736) BT_AV: HPF connection state: Connected, [24:da:9b:76:f4:5a][0m
[0;32mI (1796) hf_mydebug: bta_hf_client_send_at AT+BAC=1[0m
[0;32mI (1806) hf_mydebug: bta_hf_client_send_at AT+CIND=?[0m
[0;32mI (1816) hf_mydebug: bta_hf_client_send_at AT+CIND?[0m
[0;32mI (2936) BT_AV: HPF event ESP_HF_CLIENT_CIND_CALL_EVT[0m
[0;32mI (2936) BT_AV: HPF event ESP_HF_CLIENT_CIND_CALL_SETUP_EVT[0m
[0;32mI (2936) BT_AV: HPF event ESP_HF_CLIENT_CIND_SERVICE_AVAILABILITY_EVT[0m
[0;32mI (2936) hf_mydebug: bta_hf_client_send_at AT+CMER=3,0,0,1[0m
[0;32mI (2946) BT_AV: HPF event ESP_HF_CLIENT_CIND_SIGNAL_STRENGTH_EVT[0m
[0;32mI (2956) BT_AV: HPF event ESP_HF_CLIENT_CIND_ROAMING_STATUS_EVT[0m
[0;32mI (2956) BT_AV: HPF event ESP_HF_CLIENT_CIND_BATTERY_LEVEL_EVT[0m
[0;32mI (2966) BT_AV: HPF event ESP_HF_CLIENT_CIND_CALL_HELD_EVT[0m
[0;32mI (3006) hf_mydebug: bta_hf_client_send_at AT+CHLD=?[0m
[0;32mI (3016) hf_mydebug: bta_hf_client_send_at AT+BIA=1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0[0m
[0;32mI (3016) BT_AV: HPF connection state: SLC_Connected, [24:da:9b:76:f4:5a][0m
[0;32mI (3026) hf_mydebug: BTA_HfClientSendAT[0m
[0;32mI (3026) hf_mydebug: BTA_HF_CLIENT_AT_BIA_OK[0m
[0;32mI (3036) hf_mydebug: bta_hf_client_send_at AT+CCWA=1[0m
[0;32mI (3036) BT_AV: HPF Audio connection state: Connecting[0m
[0;32mI (3086) hf_mydebug: bta_hf_client_send_at AT+CMEE=1[0m
[0;32mI (3166) hf_mydebug: bta_hf_client_send_at AT+COPS=3,0[0m
[0;32mI (3176) hf_mydebug: bta_hf_client_send_at AT+BTRH?[0m
[0;32mI (3236) hf_mydebug: bta_hf_client_send_at AT+CLIP=1[0m
[0;32mI (3316) hf_mydebug: bta_hf_client_send_at AT+BCC[0m
[0;32mI (3396) hf_mydebug: BTA_HF_CLIENT_AT_BCC_OK[0m
[0;32mI (3406) hf_mydebug: MSBC+CVSD codec[0m
[0;32mI (3406) hf_mydebug: bta_hf_client_send_at AT+BCS=1[0m
[0;32mI (3456) hf_mydebug: BTA_HF_CLIENT_AT_BCS_OK[0m
[0;31mE (11326) BT_APPL: bta_dm_pm_btm_status hci_status=12[0m
what am i doing wrong? please help.

andrij09
Posts: 1
Joined: Fri May 24, 2019 3:49 pm

Re: HFP AG connection.

Postby andrij09 » Fri May 24, 2019 6:04 pm

Hi, as I can see, there is no answers for more then a month.
I have a semi working application (why semi, because the audio transfer works only in one direction).
As I understand, the audio connection should be established only when there is something to be sent or receive, for example an active call on the phone and not when establishing the BT connection itself.
You should receive a corresponding event stating, for example, "call in progress" and before that another ones about "dialing" and "alerting", so after that you can handle the audio connection.
In your outgoing data callback function the buf contains nothing, so nothing relevant to send with ESP_LOGI.

Code: Select all

uint32_t esp_hf_client_outgoing_data_cb(uint8_t *buf, uint32_t len){
  ESP_LOGI(BT_AV_TAG,"data1= %d",(uint8_t)buf);
  return 0;
You should fill this buffer with your data to be sent.
When you are ready to send something, you should call the:

Code: Select all

esp_hf_client_outgoing_data_ready();
to inform the lower layer functions to call the "esp_hf_client_outgoing_data_cb" itself

Tnarain5
Posts: 7
Joined: Fri Nov 29, 2019 11:22 am

Re: HFP AG connection.

Postby Tnarain5 » Thu Dec 12, 2019 12:01 pm

Hi,
I tried your code but im having the following error :

bta_hf_client_sco_co_out_data invaild air mode 255



After calling the function esp_hf_client_outgoing_data_ready(); when call is in progress.

PLEASE HELP!

Who is online

Users browsing this forum: No registered users and 55 guests