espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.43k stars 7.25k forks source link

Is it possible to trigger manually read /write events in BLE Stack(Nimble) (IDFGH-5067) #6851

Closed JosueSanchezEZM closed 3 years ago

JosueSanchezEZM commented 3 years ago

Hi everybody. I would like to know if there is any possibility to manually trigger one of these two events: BLE_GATT_ACCESS_OP_READ_CHR and BLE_GATT_ACCESS_OP_WRITE_CHR when needed.

I am trying to implement a communication base on "customs commands" through a BLE Central (Gatt server) and a BLE client (My phone). I would like to send "read_table1" as a command using Tx Characteristic to receive this command into the BLE_GATT_ACCESS_OP_WRITE_CHR, which I correctly do, but what I want to know is that if there is any way to inside this case section of the "access_callback" that handle this event, could I trigger a response event handled by this same function to the case BLE_GATT_ACCESS_OP_READ_CHR ?

I want this because based on the custom command received I want immediately to send a response with data of table 1.

I am using esp-idf/bluetooth/nimble/bleprph_wifi_coex 4.3 release version code for the BLE implementation, exactly the same structure.

I will appreciate all your help and support. Thanks

prasad-alatkar commented 3 years ago

I would like to know if there is any possibility to manually trigger one of these two events: BLE_GATT_ACCESS_OP_READ_CHR and BLE_GATT_ACCESS_OP_WRITE_CHR when needed.

@JosueSanchezEZM, if you are looking for CLI support then yes it is possible to manually issue commands for read/write, but you may have to rework the application (BLE central/client) for it. We have already provided bleprph example demonstrating minuscule CLI support: bleprph_cli, it may come handy to you.

I am trying to implement a communication base on "customs commands" through a BLE Central (Gatt server) and a BLE client (My phone). I would like to send "read_table1" as a command using Tx Characteristic to receive this command into the BLE_GATT_ACCESS_OP_WRITE_CHR, which I correctly do, but what I want to know is that if there is any way to inside this case section of the "access_callback" that handle this event, could I trigger a response event handled by this same function to the case BLE_GATT_ACCESS_OP_READ_CHR ?

If I have understood your requirement correctly, you would like to write to BLE GATT server (ESP32) characteristic from phone (BLE central) custom commands like "read_table1" and you expect the GATT server to send the corresponding custom data from the table. It is very much possible to achieve your requirement using BLE_GATT_ACCESS_OP_READ_CHR. What you need to do is depending upon the content received in BLE_GATT_ACCESS_OP_WRITE_CHR, you will have to change gatt_svr_sec_test_static_val to get the appropriate response. Please do remember, after write operation you will have to manually read the characteristic value to see the response and the response size shall be limited to 512 Bytes by BLE spec. I would also like to request you to take a look at NOTIFY ATT operation as well. The notify operation is demonstrated in blehr nimble app, ref: blehr. The reason to recommend notify ATT operation is it will help you send notification from server without any client side input. It will also help you to send the custom data depending upon the contents received in BLE_GATT_ACCESS_OP_WRITE_CHR callback using notify operation. Please let me know if it helps you resolve the issue.

JosueSanchezEZM commented 3 years ago

Thanks @prasad-alatkar for your recommendations, right now I have a good implementation example base on your suggestions.