NimBLE-Arduino
NimBLE-Arduino copied to clipboard
Bonding must always be re-established after NimBLEDevice::deinit(false).
Hello, I am currently trying to equip a battery-powered device with NimBLE to send sensor data to a smartphone.
Hardware used: ESP32-S3 Programming environment: Arduino IDE 2.3.2 Library: NimBLE-Arduino 1.4.2
To save battery I use the command “NimBLEDevice::deinit(false)” after advertising when no device is connected to the server. I want to bond the server with the smartphone once and then a connection should always be possible.
Implementation of the secure connection:
class MyServerCallbacks : public NimBLEServerCallbacks {
void onConnect(NimBLEServer* pServer, ble_gap_conn_desc* desc) {
NimBLEDevice::setSecurityAuth(true,true,true);
NimBLEDevice::setSecurityIOCap (0x00);
NimBLEDevice::setSecurityInitKey (BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID);
NimBLEDevice::setSecurityRespKey(BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID);
_pin = esp_random() % 900000 + 100000;
NimBLEDevice::setSecurityPasskey(_pin);
Serial.println(_pin);
NimBLEDevice::startSecurity (desc-> conn_handle);
deviceConnected = true;
NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising();
pAdvertising->stop();
}
void onDisconnect(NimBLEServer *pServer, ble_gap_conn_desc *desc) {
deviceConnected = false;
}
};
Error message: E (231388) NimBLE: failed to configure restored IRK
The passkey must be entered again for each connection. I have not found any information about this problem. This problem does not occur without the deinit() function. I would be very grateful for help.