From f835042e16c77c43ab3a65b0411ba6f4995fe645 Mon Sep 17 00:00:00 2001 From: Pangodream <44610297+pangodream@users.noreply.github.com> Date: Fri, 8 Feb 2019 18:59:48 +0100 Subject: [PATCH 1/3] Update BLERemoteService.cpp --- src/BLERemoteService.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/BLERemoteService.cpp b/src/BLERemoteService.cpp index c2b7d34..25b744e 100644 --- a/src/BLERemoteService.cpp +++ b/src/BLERemoteService.cpp @@ -165,7 +165,9 @@ BLERemoteCharacteristic* BLERemoteService::getCharacteristic(BLEUUID uuid) { * @return N/A */ void BLERemoteService::retrieveCharacteristics() { - ESP_LOGD(LOG_TAG, ">> getCharacteristics() for service: %s", getUUID().toString().c_str()); + esp_gatt_status_t status; + try{ + ESP_LOGD(LOG_TAG, ">> retrieveCharacteristics() for service: %s", getUUID().toString().c_str()); removeCharacteristics(); // Forget any previous characteristics. @@ -209,11 +211,13 @@ void BLERemoteService::retrieveCharacteristics() { m_characteristicMap.insert(std::pair(pNewRemoteCharacteristic->getUUID().toString(), pNewRemoteCharacteristic)); m_characteristicMapByHandle.insert(std::pair(result.char_handle, pNewRemoteCharacteristic)); offset++; // Increment our count of number of descriptors found. + m_haveCharacteristics = true; // Remember that we have received the characteristics. } // Loop forever (until we break inside the loop). - - m_haveCharacteristics = true; // Remember that we have received the characteristics. - ESP_LOGD(LOG_TAG, "<< getCharacteristics()"); -} // getCharacteristics + }catch(const std::exception&){ + ESP_LOGE(LOG_TAG, "Catched exception inside retrieveCharacteristics!!!"); + } + ESP_LOGD(LOG_TAG, "<< retrieveCharacteristics()"); +} // retrieveCharacteristics /** From cc2b884dee06f44d7683b97aa93db04e8cbdb57a Mon Sep 17 00:00:00 2001 From: Pangodream <44610297+pangodream@users.noreply.github.com> Date: Fri, 8 Feb 2019 19:05:04 +0100 Subject: [PATCH 2/3] Update BLERemoteService.cpp --- src/BLERemoteService.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BLERemoteService.cpp b/src/BLERemoteService.cpp index 25b744e..b199f8d 100644 --- a/src/BLERemoteService.cpp +++ b/src/BLERemoteService.cpp @@ -175,7 +175,7 @@ void BLERemoteService::retrieveCharacteristics() { esp_gattc_char_elem_t result; while (true) { uint16_t count = 10; // this value is used as in parameter that allows to search max 10 chars with the same uuid - esp_gatt_status_t status = ::esp_ble_gattc_get_all_char( + status = ::esp_ble_gattc_get_all_char( getClient()->getGattcIf(), getClient()->getConnId(), m_startHandle, From 181e90ff8bdf5707961210e458cc7d65cbaf6c21 Mon Sep 17 00:00:00 2001 From: Pangodream <44610297+pangodream@users.noreply.github.com> Date: Fri, 8 Feb 2019 19:11:54 +0100 Subject: [PATCH 3/3] Update BLERemoteService.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reboot occurs ocassionally when retrieving characteristics if exceptions are not catched. ´ [D][BLERemoteService.cpp:168] retrieveCharacteristics(): >> getCharacteristics() for service: 0000181d-0000-1000-8000-00805f9b34fb Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled. ´ --- src/BLERemoteService.cpp | 90 ++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/BLERemoteService.cpp b/src/BLERemoteService.cpp index b199f8d..4de31f3 100644 --- a/src/BLERemoteService.cpp +++ b/src/BLERemoteService.cpp @@ -166,55 +166,55 @@ BLERemoteCharacteristic* BLERemoteService::getCharacteristic(BLEUUID uuid) { */ void BLERemoteService::retrieveCharacteristics() { esp_gatt_status_t status; - try{ - ESP_LOGD(LOG_TAG, ">> retrieveCharacteristics() for service: %s", getUUID().toString().c_str()); - - removeCharacteristics(); // Forget any previous characteristics. - - uint16_t offset = 0; - esp_gattc_char_elem_t result; - while (true) { - uint16_t count = 10; // this value is used as in parameter that allows to search max 10 chars with the same uuid - status = ::esp_ble_gattc_get_all_char( - getClient()->getGattcIf(), - getClient()->getConnId(), - m_startHandle, - m_endHandle, - &result, - &count, - offset - ); - - if (status == ESP_GATT_INVALID_OFFSET) { // We have reached the end of the entries. - break; - } + try{ + ESP_LOGD(LOG_TAG, ">> retrieveCharacteristics() for service: %s", getUUID().toString().c_str()); + + removeCharacteristics(); // Forget any previous characteristics. + + uint16_t offset = 0; + esp_gattc_char_elem_t result; + while (true) { + uint16_t count = 10; // this value is used as in parameter that allows to search max 10 chars with the same uuid + status = ::esp_ble_gattc_get_all_char( + getClient()->getGattcIf(), + getClient()->getConnId(), + m_startHandle, + m_endHandle, + &result, + &count, + offset + ); + + if (status == ESP_GATT_INVALID_OFFSET) { // We have reached the end of the entries. + break; + } - if (status != ESP_GATT_OK) { // If we got an error, end. - ESP_LOGE(LOG_TAG, "esp_ble_gattc_get_all_char: %s", BLEUtils::gattStatusToString(status).c_str()); - break; - } + if (status != ESP_GATT_OK) { // If we got an error, end. + ESP_LOGE(LOG_TAG, "esp_ble_gattc_get_all_char: %s", BLEUtils::gattStatusToString(status).c_str()); + break; + } - if (count == 0) { // If we failed to get any new records, end. - break; - } + if (count == 0) { // If we failed to get any new records, end. + break; + } - ESP_LOGD(LOG_TAG, "Found a characteristic: Handle: %d, UUID: %s", result.char_handle, BLEUUID(result.uuid).toString().c_str()); - - // We now have a new characteristic ... let us add that to our set of known characteristics - BLERemoteCharacteristic *pNewRemoteCharacteristic = new BLERemoteCharacteristic( - result.char_handle, - BLEUUID(result.uuid), - result.properties, - this - ); - - m_characteristicMap.insert(std::pair(pNewRemoteCharacteristic->getUUID().toString(), pNewRemoteCharacteristic)); - m_characteristicMapByHandle.insert(std::pair(result.char_handle, pNewRemoteCharacteristic)); - offset++; // Increment our count of number of descriptors found. - m_haveCharacteristics = true; // Remember that we have received the characteristics. - } // Loop forever (until we break inside the loop). + ESP_LOGD(LOG_TAG, "Found a characteristic: Handle: %d, UUID: %s", result.char_handle, BLEUUID(result.uuid).toString().c_str()); + + // We now have a new characteristic ... let us add that to our set of known characteristics + BLERemoteCharacteristic *pNewRemoteCharacteristic = new BLERemoteCharacteristic( + result.char_handle, + BLEUUID(result.uuid), + result.properties, + this + ); + + m_characteristicMap.insert(std::pair(pNewRemoteCharacteristic->getUUID().toString(), pNewRemoteCharacteristic)); + m_characteristicMapByHandle.insert(std::pair(result.char_handle, pNewRemoteCharacteristic)); + offset++; // Increment our count of number of descriptors found. + m_haveCharacteristics = true; // Remember that we have received the characteristics. + } // Loop forever (until we break inside the loop). }catch(const std::exception&){ - ESP_LOGE(LOG_TAG, "Catched exception inside retrieveCharacteristics!!!"); + ESP_LOGE(LOG_TAG, "Catched exception inside retrieveCharacteristics!!!"); } ESP_LOGD(LOG_TAG, "<< retrieveCharacteristics()"); } // retrieveCharacteristics