ble client how to read without notification

Olfox59
Posts: 13
Joined: Tue May 02, 2017 12:36 pm

ble client how to read without notification

Postby Olfox59 » Sat Oct 29, 2022 8:58 am

Hi,

I need to read each second my sensor . esp32 is ble client. i want to use timer each second that read ble charac. I don't use notification to save batterie, as i know i have to read each second.

All example use notification.

I call in timer :

Code: Select all

      esp_gatt_status_t status =  esp_ble_gattc_read_by_type(    
                                        gl_profile_tab[GATTC_PROFILE_A_APP_ID].gattc_if,       //on lance la lecture, on a recupere la data dans l'event de succes de lecture dans gatt handler
                                        gl_profile_tab[GATTC_PROFILE_A_APP_ID].conn_id,
                                        gl_profile_tab[GATTC_PROFILE_A_APP_ID].service_start_handle,
                                        gl_profile_tab[GATTC_PROFILE_A_APP_ID].service_end_handle,
                                        &filter_service_av,
                                        ESP_GATT_AUTH_REQ_SIGNED_NO_MITM);


It raise well read event in ble client handler but after going out from the handler, it crash with
Guru Meditation Error: Core 0 panic'ed (StoreProhibited) error

I can rea dmy sensor if instead of esp_ble_gattc_read_by_type, i try to discover service to generate ESP_GATTC_SEARCH_CMPL_EVT and then call: esp_ble_gattc_get_char_by_uuid and just after esp_ble_gattc_read_char

Should i call directly esp_ble_gattc_read_char in timer ?

But how to know whitch handle to call ?

Thanks a lot for your help !

ESP_XuLZ
Posts: 173
Joined: Fri Mar 26, 2021 6:04 am

Re: ble client how to read without notification

Postby ESP_XuLZ » Thu Nov 03, 2022 12:58 pm

Hi, Olfox59
I think you can refer to the flow in the gatt_client example
1. First of all, you must know the UUID of the characteristic you want to read and the UUID of the service where it is located, otherwise you cannot find the characteristic unless there is only one service and there is only one characteristic under the service

2. Second, you should use APIs such as esp_ble_gattc_search_service, esp_ble_gattc_get_attr_count, esp_ble_gattc_get_char_by_uuid to add filter conditions to find this characteristic, then you can get the handle value of this characteristic

3. At this point, you can save the conn_id and handle parameters to call esp_ble_gattc_read_char in the timer to use

Hope the above can help you!

Who is online

Users browsing this forum: No registered users and 78 guests