Battery query client CC2564 ARM FreeRtos

30 views
Skip to first unread message

Sergey Grjazev

unread,
Feb 16, 2024, 7:06:37 AMFeb 16
to btstack-dev
Hi friends!

I have ARM controller with CC2564 chip, connected by UART.
I'm trying to realize "battery query clinet". I want to receive information about the charge level from the headphones. As example I use file "gatt_battery_query.c" (stack v 1.5.3).
But my exchage is stopped after received message "SM_EVENT_IDENTITY_RESOLVING_STARTED".  Could you help me?

Sound transmission (hfp profile) works good.

Thanks.

My init code for battery query:

btstack_memory_init();
// it require to call first!!!
btstack_run_loop_init(btstack_run_loop_freertos_get_instance());

// init HCI btstack_uart_block_t
const btstack_uart_block_t *uart_driver =
btstack_uart_block_freertos_instance();
const hci_transport_t *transport = hci_transport_h4_instance(uart_driver);
hci_init(transport, (void *)&config);
hci_set_chipset(btstack_chipset_cc256x_instance());
hci_set_link_key_db(btstack_link_key_db_memory_instance());

// inform about BTstack state
hci_event_callback_registration.callback = &packet_handler_btTask;
hci_add_event_handler(&hci_event_callback_registration);

l2cap_init();
// Battery
att_server_init(profile_data, NULL, NULL);
// GATT Client setup
gatt_client_init();
//  Device Information Service Client setup
battery_service_client_init();

sm_init();
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);

gap_set_local_name(bt_local_name);
gap_discoverable_control(1);
gap_set_class_of_device(0x200408);
gap_set_scan_parameters(0, 0x0030, 0x0030);

hci_power_control(HCI_POWER_ON);

LOGOUT("btstack executing run loop...");
btstack_run_loop_execute();



My logs

BT_TASK: Texas Instruments - CC256x compatible chipset.
BT_TASK: eHCILL disabled.
BT Info: local name:
BT_TASK: Local name:
BT Info: Init script done
BT Info: Command 0x00 supported 2/5
BT Info: Command 0x01 supported 10/4
BT Info: Command 0x02 supported 14/7
BT Info: Command 0x03 supported 18/3
BT Info: Command 0x04 supported 20/4
BT Info: Command 0x06 supported 24/6
BT Info: Local supported commands summary 0000005f
BT Info: controller supports ECDH operation: 0
BT Info: Local Address, Status: 0x00: Addr: A0:E6:F8:61:63:F4
BT Info: hci_read_buffer_size: ACL size module 1021 -> used 1021, count 4 / SCO size 180, count 4
BT Info: ACL Packet types ff1e
BT Info: SCO Packet types 03ff - eSCO 1
BT Info: BR/EDR support 1, LE support 1
BT Info: hci_le_read_buffer_size: acl size 27, acl count 15
BT Info: hci_le_read_white_list_size: size 25
BT Info: hci_init_done -> HCI_STATE_WORKING
BT Info: BTSTACK_EVENT_STATE 2
BT_TASK: BTstack up and running at A0:E6:F8:61:63:F4
BT Info: HCI Working!
BT Err: Persistent IR not set with sm_set_ir. Use of private addresses will cause pairing issues
BT Err: Persistent ER not set with sm_set_er. Legacy Pairing LTK is not secure
BT Err: Please configure btstack_tlv to let BTstack setup ER and IR keys
BT Info: hci_le_set_own_address_type: old 0, new 0
BT Info: DKG_CALC_IRK started
BT Info: irk    C7CF41E75979A53FA2FC7B3160EEEAE6
BT Info: DKG_CALC_DHK started
BT Info: dhk    B54FC6732A320AA2AA8FB959921729C7
BT_TASK: Start scanning!
BT_TASK: GAP_EVENT_ADVERTISING_REPORT
BT_TASK: adv. event: evt-type 0, addr-type 0, addr 38:5C:76:3E:43:2A, rssi 176, length adv 3, data:
BT Info: gap_connect: no connection exists yet, creating context
BT Info: create_connection_for_addr 38:5C:76:3E:43:2A, type 0
BT Info: gap_connect: send create connection next
BT Info: sending hci_le_create_connection
BT Info: LE Connection_complete (status=0) type 0, 38:5C:76:3E:43:2A
BT Info: New connection: handle 1025, 38:5C:76:3E:43:2A
BT Info: BTSTACK_EVENT_NR_CONNECTIONS_CHANGED 1
BT_TASK: HCI_EVENT_META_GAP
BT Info: battery_service_run_for_client, state 1
BT Info: GATT client timeout start, handle 0x401
BT_TASK: Battery service connected. Status 0
BT Info: SM_EVENT_IDENTITY_RESOLVING_STARTED


My config:

#define HAVE_EMBEDDED_TIME_MS
#define HAVE_FREERTOS_TASK_NOTIFICATIONS

// BTstack features that can be enabled
#define ENABLE_BLE
#define ENABLE_CLASSIC
#define ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
#define ENABLE_LE_CENTRAL
#define ENABLE_LE_PERIPHERAL
#define ENABLE_LE_SIGNED_WRITE
#define ENABLE_SDP_EXTRA_QUERIES

#define ENABLE_SDP_DES_DUMP
#define ENABLE_SDP_EXTRA_QUERIES
#define ENABLE_SOFTWARE_AES128

#define ENABLE_HFP_AT_MESSAGES
// BTstack configuration. buffers, sizes, ...
#define HCI_ACL_PAYLOAD_SIZE (1024 + 4) //Max official att size + l2cap header size
#define HCI_INCOMING_PRE_BUFFER_SIZE 16
#define MAX_NR_LE_DEVICE_DB_ENTRIES 4

#define MAX_NR_GATT_CLIENTS 3
#define MAX_NR_HCI_CONNECTIONS 4    // for two channels in HFP profile: servise channel and SCO audio channel
#define MAX_NR_L2CAP_SERVICES  4
#define MAX_NR_L2CAP_CHANNELS  4
#define MAX_NR_HFP_CONNECTIONS 2
#define MAX_NR_RFCOMM_MULTIPLEXERS 2
#define MAX_NR_RFCOMM_SERVICES 2
#define MAX_NR_RFCOMM_CHANNELS 2
#define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 10
#define MAX_NR_BNEP_SERVICES 2
#define MAX_NR_BNEP_CHANNELS 2
#define MAX_NR_WHITELIST_ENTRIES 2
#define MAX_NR_SM_LOOKUP_ENTRIES 3
#define MAX_NR_SERVICE_RECORD_ITEMS 2   // for SDP records SPP and HFP
#define MAX_NR_BATTERY_SERVICE_CLIENTS 5

#define MAX_ATT_DB_SIZE 350

// LE Device DB using TLV
#define NVM_NUM_LINK_KEYS              16
#define NVM_NUM_DEVICE_DB_ENTRIES      16

Matthias Ringwald

unread,
Feb 16, 2024, 7:12:17 AMFeb 16
to btsta...@googlegroups.com
Hi Sergey

Could you (always) post an HCI trace? you can enable it with hci_dump_init(..) and a logger engine, e.g. hci_dump_embedded_stdout_get_instance()

Your snippet doesn't show how you connect to the headphones. For LE, you use gap_connect and when you get the connected event, you can use the battery service client to connect to the remote service and query the battery.
Also, it's not mandatory for a headset, which use Bluetooth Classic for A2DP and HFP, that it a) supports LE, and even if it does, it's also optional to support the Battery Service.

Please use a BLE GATT tool on a smartphone for a quick check. e.g. nRF toolbox, LIghtBlue, or similar to see if your headset has a battery service.

Best regards
Matthias
> --
> You received this message because you are subscribed to the Google Groups "btstack-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to btstack-dev...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/btstack-dev/c0cffb7f-3d3d-4993-8da6-f8ee3c1eb242n%40googlegroups.com.

Sergey Grjazev

unread,
Feb 19, 2024, 12:40:46 AMFeb 19
to btstack-dev
Ok, thank Matthias for your advice.
I setup app, and my headphones do not support "Battery service".
Is there a universal way to find out information about the battery status?
Perhaps this is the 'AT+IPHONEACCEV=' analysis?

And I can find out about pressing the play, stop, next button.. (in HFP profile)
or need use AVRCP? (I can use HFP and AVRCP together?)

Thanks.

пятница, 16 февраля 2024 г. в 15:12:17 UTC+3, Matthias Ringwald:

Matthias Ringwald

unread,
Feb 19, 2024, 9:25:18 AMFeb 19
to btsta...@googlegroups.com
Hi Sergey

A headset that supports HFP can indicate it's battery status via their HF Indicators, the hfp_ag_demo should display them. It's usually on a scale from 1-5.

> AT+IPHONEACCEV
is an Apple extension which you could use as well if your headset supports it via the 'custom AT commands' feature.
It's documented here: https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf

You can register a custom command with hfp_ag_register_custom_at_command and respond with hfp_ag_send_unsolicited_result_code

According to the Apple document, you need to confirm the Apple features for 'AT+XAPL=' and should later get battery from 1-9 in 'AT+IPHONEACCEV''

--

In HFP, there's only Call Control and Volume +/-. You will get corresponding events automatically.
For media playback, you can use AVRCP, see a2dp_source_demo for an example.

Best
Matthias
> To view this discussion on the web visit https://groups.google.com/d/msgid/btstack-dev/5cdc70f1-c6ff-4a74-9793-86a308eed5b1n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages