Sending command fomr gatt client to server (central to peripheric)

irobux
Posts: 9
Joined: Tue Jan 03, 2017 9:36 am

Sending command fomr gatt client to server (central to peripheric)

Postby irobux » Tue Feb 14, 2017 11:31 pm

Hi,

I am still using the gatt client sample and can scan the advertised peripherics in the area with this sample.
I need to drive (put on/off) a beewi smart led.

As far as i understood I have to call the write function with good parameters like conn_id, gatt_if, value length, value to write, etc...
But there are many function in the API

esp_ble_gattc_write_char
esp_ble_gattc_write_char_descr
esp_ble_gattc_prepare_write
esp_ble_gattc_execute_write

I have 2 important questions for my project please and I need to undestand:
1/ Should I prepare write before writing ? And what is the difference between write characteristic (esp_ble_gattc_write_char) and write descriptor (esp_ble_gattc_write_char_descr) ?

2/ How to send the command, the API provided by a BLE to control mentionned the command as an opcode for example [0x03 0x01]... I did not yet catch hox to use them, can someone explain this to me or send me a sample of code about gatt client send command to a BLE peripheric ?

Thanks
Iro

User avatar
pcbreflux
Posts: 28
Joined: Sat Feb 11, 2017 1:00 am
Location: germany
Contact:

Re: Sending command fomr gatt client to server (central to peripheric)

Postby pcbreflux » Wed Feb 15, 2017 12:12 pm

Hi,

the difference between esp_ble_gattc_write_char is writing to a characteristic (this is mainly what you want to send commands to your BLE device i.e. GATT Server) and esp_ble_gattc_write_char_descr writing to the descriptor (mostly used to enable the notification for reading characteristics with notify events). The necessary steps (init,scan,open,search_service,get_characteristic,get_descriptor,write_char_descr,register_for_notify) are demonstrated in the esp-idf example https://github.com/espressif/esp-idf/tr ... att_client and here https://github.com/pcbreflux/espressif/ ... gattc_demo).
Never used esp_ble_gattc_prepare_write or esp_ble_gattc_execute_write.

pineson
Posts: 2
Joined: Mon Apr 10, 2017 2:58 am

Re: Sending command fomr gatt client to server (central to peripheric)

Postby pineson » Mon Apr 10, 2017 3:21 am

Hi,

I try this "https://github.com/pcbreflux/espressif/ ... gattc_demo", it works well except that esp_ble_gattc_write_char_descr() doesn't work, peripheric didn't receive written command, but demo get ESP_GATTC_WRITE_DESCR_EVT, so far no write function work for me. Do I miss something? Thanks for any suggestion in advance.

pineson
Posts: 2
Joined: Mon Apr 10, 2017 2:58 am

Re: Sending command fomr gatt client to server (central to peripheric)

Postby pineson » Wed Apr 12, 2017 1:57 am

My problem solved finally, this https://github.com/Nicholas3388/LuaNode ... 2_ble_conn
really helpful,you have to make sure of every parameter, every!

Trialblazer47
Posts: 60
Joined: Mon Jun 26, 2017 5:36 am

Re: Sending command fomr gatt client to server (central to peripheric)

Postby Trialblazer47 » Thu Feb 08, 2018 1:10 pm

Hi, I have some thing similar problem my devices work like this:
NRF51 starts advertisement and ESP32 connects for the first time enables notification takes data and disconnects.
then whenever nrf51 has data it starts advertising. but when esp32 again writes to notify it does not write to nrf51 and a log on ESP32 shows

Code: Select all

I (225547) GATTC_DEMO: ESP_GATTC_OPEN_EVT conn_id 0, if 3, status 0, mtu 0
I (225547) GATTC_DEMO: REMOTE BDA  c7:7f:3a:11:95:cd
I (225557) GATTC_DEMO: EVT 2, gattc if 3
I (225557) GATTC_DEMO: open success
I (225567) GATTC_DEMO: EVT 7, gattc if 3
I (225567) GATTC_DEMO: EVT 7, gattc if 3
I (225577) GATTC_DEMO: EVT 7, gattc if 3
I (225577) GATTC_DEMO: EVT 6, gattc if 3
I (225587) GATTC_DEMO: EVT 35, gattc if 3
I (225587) GATTC_DEMO: register notify   <----this one
E (225587) BT: notification already registered
I (225597) GATTC_DEMO: EVT 38, gattc if 3
I (225597) GATTC_DEMO: REG FOR NOTIFY: status 0
I (225607) GATTC_DEMO: NOTIFICATION ENABLING SUCCESS.
I (225617) GATTC_DEMO: EVT 35, gattc if 3
I (225617) GATTC_DEMO: EVT 36, gattc if 3
E (225627) BT: GATTC_Write GATT_BUSY conn_id = 3
E (225627) BT: No pending command
I (225627) GATTC_DEMO: EVT 35, gattc if 3
E (225697) BT: No pending command
Thanks.

Trialblazer47
Posts: 60
Joined: Mon Jun 26, 2017 5:36 am

Re: Sending command fomr gatt client to server (central to peripheric)

Postby Trialblazer47 » Sat Feb 10, 2018 6:48 pm

this one is frustrating I am enabling notification but I alway get notification already registered.

Code: Select all

E (279690) BT: notification already registered
And it does not register notification again once it has registered notification and disconnects.
Please help.
Thanks.

Who is online

Users browsing this forum: No registered users and 29 guests