Skip to content
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

Multiple Bluetooth connections (Android) #152

Closed
Pmr-precure opened this issue Oct 24, 2024 · 5 comments
Closed

Multiple Bluetooth connections (Android) #152

Pmr-precure opened this issue Oct 24, 2024 · 5 comments
Assignees
Labels
needmoreinfo question Further information is requested

Comments

@Pmr-precure
Copy link

Pmr-precure commented Oct 24, 2024

Hi,

First of all, thank you so much for providing such a great package!

I’m currently implementing it into our MAUI app and have encountered a few issues. I’m not sure how significant the problem is, but for testing purposes, I’ve been flashing my device with two different firmware versions repeatedly to ensure everything runs smoothly. However, I noticed that each time I update the firmware, a new Bluetooth connection is created.

In this case i have flashed the my device 3 times:
image

Here 4 times, it keeps adding more connections:
image

image

I do
private void CleanupFirmwareInstaller()
{
_firmwareInstaller?.Disconnect();
_firmwareInstaller = null;
}
after each update.

BR Pelle.

@ksidirop-laerdal ksidirop-laerdal self-assigned this Nov 4, 2024
@ksidirop-laerdal ksidirop-laerdal added the question Further information is requested label Nov 4, 2024
@ksidirop-laerdal
Copy link
Collaborator

ksidirop-laerdal commented Nov 4, 2024

In terms of instantiating a new connection on each firmware-installation attempt this seems to be the intended behavior indeed (See the comment in the end however).

To be precise our library is not doing it. It's merely wrapping around the native Java libraries provided by Nordic and in the particular case of the firmware installer it simply instantiates a "FirmwareUpgradeManager" passing it a transport pointing to the desired BLE device and let's Nordic's manager figure out the rest:

As you noticed experimentally the manager instantiates a new android connection every time if you follow our code samples (which instantiate a new FirmwareInstaller() every time).

This is perfectly normal and it's the expected behavior. There is no reason for the underlying connection to be cached and reused in such a "firmware-installation context" considering that:

(1) the target device will reboot in the end and for that matter the ble-connection is trashed anyway (this immediately rules out the "reusable connection" concept)
and (2) re-installing a firmware over and over is not a typical use-case scenario (it only makes sense in test environments but not on production environments which are the most important ones)


In regard to the behavior you're seeing in the debug logs can you elaborate a bit more as to what leads you to believe that there are more than 1 connections active towards the device? The debug log you've provided is a bit fussy for me to make heads and tails out of it. I suspect that even though the disconnect method is called somehow it doesn't have the desired effect.

Can you share your C# code as a snippet to have a quick look at it?

PS: Come to think of it the .Disconnect() implementation can be simplified a bit. Will issue a new beta-version and let you try it out to see if it makes any difference (https://github.com/Laerdal/Laerdal.McuMgr/releases/tag/v2.49.3-beta). Appreciate the report. Let me know how it goes.

@Pmr-precure
Copy link
Author

In terms of instantiating a new connection on each firmware-installation attempt this seems to be the intended behavior indeed (See the comment in the end however).

To be precise our library is not doing it. It's merely wrapping around the native Java libraries provided by Nordic and in the particular case of the firmware installer it simply instantiates a "FirmwareUpgradeManager" passing it a transport pointing to the desired BLE device and let's Nordic's manager figure out the rest:

As you noticed experimentally the manager instantiates a new android connection every time if you follow our code samples (which instantiate a new FirmwareInstaller() every time).

This is perfectly normal and it's the expected behavior. There is no reason for the underlying connection to be cached and reused in such a "firmware-installation context" considering that:

(1) the target device will reboot in the end and for that matter the ble-connection is trashed anyway (this immediately rules out the "reusable connection" concept) and (2) re-installing a firmware over and over is not a typical use-case scenario (it only makes sense in test environments but not on production environments which are the most important ones)

In regard to the behavior you're seeing in the debug logs can you elaborate a bit more as to what leads you to believe that there are more than 1 connections active towards the device? The debug log you've provided is a bit fussy for me to make heads and tails out of it. I suspect that even though the disconnect method is called somehow it doesn't have the desired effect.

Can you share your C# code as a snippet to have a quick look at it?

PS: Come to think of it the .Disconnect() implementation can be simplified a bit. Will issue a new beta-version and let you try it out to see if it makes any difference (https://github.com/Laerdal/Laerdal.McuMgr/releases/tag/v2.49.3-beta). Appreciate the report. Let me know how it goes.

Thank you for your reply, i will test it next week, when im back from vacation.

Br

@Pmr-precure
Copy link
Author

Hallo i haven't had time to test it further. But i doubt its a big issue. They way i replicated was:
I put a log message in a Device_Connected eventlistener.
Then i updated my devices firmware. repeatedly. And every time i updated the same device i could see my log message got called multiple times, incrementing with 1 for every update. (Hope this makes somewhat sense)

@ksidirop-laerdal
Copy link
Collaborator

Hallo i haven't had time to test it further. But i doubt its a big issue. They way i replicated was: I put a log message in a Device_Connected eventlistener. Then i updated my devices firmware. repeatedly. And every time i updated the same device i could see my log message got called multiple times, incrementing with 1 for every update. (Hope this makes somewhat sense)

If you could share the snippet of the C# code I can try to replicate it on my end to be 100% sure that I'm not missing something obvious on Android (per the motto "when stumbling upon something fishy -> investigate" ;) )

Appreciate the feedback.

@Pmr-precure
Copy link
Author

You shouldnt spend time on it. I will close this for now and if it ever becomes an issue, i will open a new ticket.

BR Pelle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needmoreinfo question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants