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/tree/master/examples/bluetooth/gatt_client and here https://github.com/pcbreflux/espressif/tree/master/esp32/app/ESP32_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/tree/master/esp32/app/ESP32_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!

Who is online

Users browsing this forum: No registered users and 2 guests