From b4f6140b07c926f1eaf12232157399100678ca72 Mon Sep 17 00:00:00 2001 From: SoftyPIT Date: Sun, 16 Jan 2022 19:40:26 +0000 Subject: [PATCH] Unregister for notification after sending command to EQ-3 --- main/eq3_main.c | 27 +++++++++++++++++---------- main/eq3_main.h | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/main/eq3_main.c b/main/eq3_main.c index cfc00d5..a5f0a11 100644 --- a/main/eq3_main.c +++ b/main/eq3_main.c @@ -567,22 +567,29 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ ESP_LOGI(GATTC_TAG, "eq3 got response 0x%x, 0x%x\n", p_data->notify.value[0], p_data->notify.value[1]); } - /* Notify the successful command */ - command_complete(true); - /* 2 second delay until disconnect to allow any background GATTC stuff to complete */ - setnextcmd(EQ3_DISCONNECT, 2); - runtimer(); + if(ESP_OK != esp_ble_gattc_unregister_for_notify (gattc_if, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, gl_profile_tab[PROFILE_A_APP_ID].resp_char_handle)){ + ESP_LOGI(GATTC_TAG, "eq3 failed to unreg for notify\n"); + /* Notify the successful command */ + command_complete(true); + /* 2 second delay until disconnect to allow any background GATTC stuff to complete */ + setnextcmd(EQ3_DISCONNECT, 2); + runtimer(); + } break; case ESP_GATTC_UNREG_FOR_NOTIFY_EVT: { - /* Oops - this won't happen - * forgot to call unregister-for-notify before disconnecting - may need to revisit if it causes problems */ + /* We should now be unregistered for notification */ if (p_data->unreg_for_notify.status != ESP_GATT_OK){ ESP_LOGE(GATTC_TAG, "UNREG FOR NOTIFY failed: error status = %d", p_data->unreg_for_notify.status); - break; + //break; + /* Continue to disconnect */ } - - esp_ble_gattc_close (gl_profile_tab[PROFILE_A_APP_ID].gattc_if, gl_profile_tab[PROFILE_A_APP_ID].conn_id); + ESP_LOGI(GATTC_TAG, "eq3 unregistered for notification\n"); + /* Notify the successful command */ + command_complete(true); + /* 2 second delay until disconnect to allow any background GATTC stuff to complete */ + setnextcmd(EQ3_DISCONNECT, 2); + runtimer(); break; } diff --git a/main/eq3_main.h b/main/eq3_main.h index 398ec86..927a199 100644 --- a/main/eq3_main.h +++ b/main/eq3_main.h @@ -2,7 +2,7 @@ #define EQ3_MAIN_H #define EQ3_MAJVER "1" -#define EQ3_MINVER "63" +#define EQ3_MINVER "64" #define EQ3_EXTRAVER "-beta" void eq3_log_init(void);