-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conn.disconnect #277
Comments
Calling Your timeout function will never finish though due to the loop though, it should be sufficient to call disconnect() only once. As for advertising not starting, maybe enable some more logging to see if it's failing somewhere early. |
So from the logs: Ok(Some(GattEvent::Read(event))) => {
if event.handle() == level.handle {
let value = server.get(&level);
info!("[gatt] Read Event to Level Characteristic: {:?}", value);
} else if event.handle() == status.handle {
let value = server.get(&status);
info!("[gatt] Read Event to Status Characteristic: {:?}", value);
let success;
{
let result = *connection_success.lock().await;
success = result;
}
if success {
info!("has read success");
handle_read_state(&mut status, server, read_content, aes).await;
{
let mut read = read_content.lock().await;
if read.state == ReadState::Done {
read.state = ReadState::Price;
*character = 'M';
conn.disconnect();
generic_delay(embassy_time::Delay).await;
}
info!("done 2");
}
} else {
info!("has not read success");
*character = 'T';
conn.disconnect();
generic_delay(embassy_time::Delay).await;
continue;
}
}
} I notice that INFO - [gatt] disconnected: Err(Connection Terminated By Local Host) gets logged which is correct but after some seconds I get the error log BleHost(NotFound), which is called from ble_task async fn ble_task<C: Controller>(mut runner: Runner<'_, C>) -> bool{
loop {
if let Err(e) = runner.run().await {
let e = defmt::Debug2Format(&e);
panic!("[ble_task] error: {:?}", e);
}
}
} This error causes it not to start advertising again. I know I can just use a warn rather than a panic but I feel the panic is important because it stops you from using the ble when there is no BleHost anymore. |
Yes, this is the reason advertising is not running, the runner must be running for it to perform operations to the controller. The host should generally not exit unless there is a condition it cannot recover from. So we should figure out why it is not recovering from this. Could you share more of the logs? Are any of these two warnings printed? https://github.com/embassy-rs/trouble/blob/main/host/src/host.rs#L923-L929 Also, if you enable tracing, which of these gets printed? https://github.com/embassy-rs/trouble/blob/main/host/src/host.rs#L559-L570 |
This is the error that gets printed
|
Connection handles may be marked as disconnected before the runner has a chance to send responses to it. In that case, log and ignore error. Fixes #277
Thanks, I think I know what happens now. Could you try #279 to see if it fixes the issue for you? |
Connection handles may be marked as disconnected before the runner has a chance to send responses to it. In that case, log and ignore error. Fixes #277
Thanks for testing @Makuo12 ! |
Connection handles may be marked as disconnected before the runner has a chance to send responses to it. In that case, log and ignore error. Fixes #277
I wanted to ask if there is a specific way to use conn.disconnect.
Using the ble_bas_peripheral.rs example I created like a timeout async function
The would run along side gatt_events_task
I realized that when the timeout gets called sometimes the connection disconnects properly. However sometimes it disconnects and stops the ble from advertising again.
The text was updated successfully, but these errors were encountered: