@@ -63,6 +63,7 @@ NimBLEClient::NimBLEClient(const NimBLEAddress &peerAddress) : m_peerAddress(pee
63
63
m_deleteCallbacks = false ;
64
64
m_pTaskData = nullptr ;
65
65
m_connEstablished = false ;
66
+ m_lastErr = 0 ;
66
67
67
68
m_pConnParams.scan_itvl = 16 ; // Scan interval in 0.625ms units (NimBLE Default)
68
69
m_pConnParams.scan_window = 16 ; // Scan window in 0.625ms units (NimBLE Default)
@@ -251,6 +252,8 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
251
252
252
253
} while (rc == BLE_HS_EBUSY);
253
254
255
+ m_lastErr = rc;
256
+
254
257
if (rc != 0 ) {
255
258
m_pTaskData = nullptr ;
256
259
return false ;
@@ -273,6 +276,7 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
273
276
return false ;
274
277
275
278
} else if (taskData.rc != 0 ){
279
+ m_lastErr = taskData.rc ;
276
280
NIMBLE_LOGE (LOG_TAG, " Connection failed; status=%d %s" ,
277
281
taskData.rc ,
278
282
NimBLEUtils::returnCodeToString (taskData.rc ));
@@ -314,6 +318,7 @@ bool NimBLEClient::secureConnection() {
314
318
315
319
int rc = NimBLEDevice::startSecurity (m_conn_id);
316
320
if (rc != 0 ){
321
+ m_lastErr = rc;
317
322
m_pTaskData = nullptr ;
318
323
return false ;
319
324
}
@@ -322,6 +327,7 @@ bool NimBLEClient::secureConnection() {
322
327
} while (taskData.rc == (BLE_HS_ERR_HCI_BASE + BLE_ERR_PINKEY_MISSING) && retryCount--);
323
328
324
329
if (taskData.rc != 0 ){
330
+ m_lastErr = taskData.rc ;
325
331
return false ;
326
332
}
327
333
@@ -372,6 +378,7 @@ int NimBLEClient::disconnect(uint8_t reason) {
372
378
}
373
379
374
380
NIMBLE_LOGD (LOG_TAG, " << disconnect()" );
381
+ m_lastErr = rc;
375
382
return rc;
376
383
} // disconnect
377
384
@@ -512,6 +519,7 @@ int NimBLEClient::getRssi() {
512
519
if (rc != 0 ) {
513
520
NIMBLE_LOGE (LOG_TAG, " Failed to read RSSI error code: %d, %s" ,
514
521
rc, NimBLEUtils::returnCodeToString (rc));
522
+ m_lastErr = rc;
515
523
return 0 ;
516
524
}
517
525
@@ -650,11 +658,13 @@ bool NimBLEClient::retrieveServices(const NimBLEUUID *uuid_filter) {
650
658
651
659
if (rc != 0 ) {
652
660
NIMBLE_LOGE (LOG_TAG, " ble_gattc_disc_all_svcs: rc=%d %s" , rc, NimBLEUtils::returnCodeToString (rc));
661
+ m_lastErr = rc;
653
662
return false ;
654
663
}
655
664
656
665
// wait until we have all the services
657
666
ulTaskNotifyTake (pdTRUE, portMAX_DELAY);
667
+ m_lastErr = taskData.rc ;
658
668
659
669
if (taskData.rc == 0 ){
660
670
NIMBLE_LOGD (LOG_TAG, " << retrieveServices" );
@@ -1136,6 +1146,15 @@ std::string NimBLEClient::toString() {
1136
1146
} // toString
1137
1147
1138
1148
1149
+ /* *
1150
+ * @brief Get the last error code reported by the NimBLE host
1151
+ * @return int, the NimBLE error code.
1152
+ */
1153
+ int NimBLEClient::getLastError () {
1154
+ return m_lastErr;
1155
+ } // getLastError
1156
+
1157
+
1139
1158
void NimBLEClientCallbacks::onConnect (NimBLEClient* pClient) {
1140
1159
NIMBLE_LOGD (" NimBLEClientCallbacks" , " onConnect: default" );
1141
1160
}
0 commit comments