Page 1 of 1

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

Posted: Tue Feb 14, 2017 11:31 pm
by irobux
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

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

Posted: Wed Feb 15, 2017 12:12 pm
by pcbreflux
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.

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

Posted: Mon Apr 10, 2017 3:21 am
by pineson
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.

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

Posted: Wed Apr 12, 2017 1:57 am
by pineson
My problem solved finally, this https://github.com/Nicholas3388/LuaNode ... 2_ble_conn
really helpful,you have to make sure of every parameter, every!

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

Posted: Thu Feb 08, 2018 1:10 pm
by Trialblazer47
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

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

Posted: Sat Feb 10, 2018 6:48 pm
by Trialblazer47
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.