-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store and load bond info using nrf_softdevice::Flash
#237
Comments
The following is the trace log, it seems the bond info has been saved correctly, but the board is disconnected everytime after saving system attributes:
I also tried to use Nrf-Connected mobile app to test the program, the app always shows the following log:
|
That means that your central device is trying to connect using keys that don't match the keys you're providing as part of the pairing procedure. You need to forget the device on the central and then re-pair to generate new keys. You then need to save those keys after receiving the |
@alexmoon Thanks for the reply! I just made my device reconnect to host by saving keys in This error only occurs after reconnection. If I delete the device from host, connect the device as a new device, all the functions work well, no |
In your |
@alexmoon I cannot find any match peripheral::advertise_pairable(sd, adv, &config, bonder).await {
Ok(conn) => {
// Run the GATT server on the connection. This returns when the connection gets disconnected.
let ble_fut = gatt_server::run(&conn, &ble_server, server_callback);
}
Err(e) => {
error!("Advertise error: {}", e)
}
} |
Sorry, |
Thanks a lot! I've got my project work. Pairing-bonding and storing keys are quite common in BLE apps. NRF has one already: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.3.0%2Flib_peer_manager.html Is it possible to have a built-in peer manager in |
That's outside the scope of |
@HaoboGu have you had to go through address resolution as well? Would you be ok with sharing your solution? |
NRF's peer manager is quite more complex, I just have a simplest version of it. You can checkout here: https://github.com/HaoboGu/rmk/blob/main/rmk/src/ble/bonder.rs |
Nice work, impressively simple, thanks for sharing! I wonder what feature does the SDK Peer manager provide that your approach doesn't? |
AFAIK, random device addresses is not supported currently. |
I just found I didn't really solve the problem. I called match peripheral::advertise_pairable(sd, adv, &config, bonder).await {
Ok(conn) => {
info!("Connected to BLE");
bonder.load_sys_attrs(&conn);
let ble_fut = gatt_server::run(&conn, &ble_server, server_callback);
}
Err(e) => {
error!("Advertise error: {}", e)
}
}
where my fn load_sys_attrs(&self, conn: &Connection) {
let addr = conn.peer_address();
info!("Loading system attributes for {}", addr);
let bond_info = self.bond_info.borrow();
let sys_attr = bond_info
.iter()
.filter(|(_, b)| b.sys_attr.length != 0 && b.removed == false)
.find(|(_, b)| b.peer.peer_id.is_match(addr))
.map(|(_, b)| &b.sys_attr.data[0..b.sys_attr.length]);
info!("call set_sys_attrs in load_sys_attrs: {}, {}", sys_attr, sys_attr.unwrap().len());
if let Err(err) = set_sys_attrs(conn, sys_attr) {
warn!("SecurityHandler failed to set sys attrs: {:?}", err);
}
} The first connection and reconnection are both good, but once I tried to send HID report, the first(all good):
second(reconnection, notify value error):
And same as before, if I remove @alexmoon Do you have any ideas? I'll much appreciate if you can help! |
In the bond peripheral example, the bond info is not actually saved and loaded. Is there any concern of not saving the bond info to
nrf_softdevice::Flash
?I tried to save
sys_attr
to flash but had problems, the program was just not work and I don't know why. It would be great if there was a full example of bond peripheral.The text was updated successfully, but these errors were encountered: