Comments (5)
Hi,
The difference is that you are switching to DFU on your own, not using the library for that. The DFU lib, which nRF Connect and nRF Toolbox are using, take care of clearing the cache after sending "jump to bootloader" command. If your device does not change device address when in bootloader mode (it does, when you switch mode using a button, that's why it works) but changes the services Android is not aware of it. It should not cache services if Service Changed char is present in the attribute list on the peripheral (for not-bonded devices) but Android always caches them (this bug will be fixed one day).
So the solutions are:
- Use DFU lib to switch to DFU mode. If yo have the correct service (DFU Service) with "jump to BL mode" feature in the app mode, simple start DFU while being connected to it. DFU Lib will send correct command, clear cache, wait for disconnection and reconnect and continue with DFU.
- Clear the cache after you disconnect, before you start DFU. Here's how we do it: https://github.com/NordicSemiconductor/Android-DFU-Library/blob/release/dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java#L1318
from android-dfu-library.
Hello Philips,
I'm a gcerto colleague. I'm personally facing the problem. Thank you for your rapid answer.
I already tried the solution of clearing cache. I tried before the BluetoothGatt disconnect(), after the disconnect() and after the BluetoothGatt close() without any success.
I have another information : our device is PAIRED (bonded) just before the disconnection : That means the methods does nothing if I don’t modify it or force the flag every time. Then I removed the test to be sure about refreshing every time :
mBluetoothGatt.getDevice().getBondState()
If I call the method just after the disconnect() the invoke method cannot be executed (invoke returns false):
public void close()
{
Logger.getInstance().logWarning(TAG, "close()");
synchronized(m_BluetoothGattMutex){
// Clean the GATT object
if (mBluetoothGatt == null)
{
return;
}
mBluetoothGatt.disconnect();
refreshDeviceCache();
}
}
If I call the method just after the close() in the BluetoothGattCallback, the invoke method cannot be executed (returns false). But if I call it in the callback before the close(), the invoke success but nothing changes in the dfu process after… :
private final BluetoothGattCallback m_gattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
(…)
if (newState == BluetoothProfile.STATE_DISCONNECTED) {
Logger.getInstance().logWarning(TAG, "m_gattCallback STATE_DISCONNECTED");
// End the service
disconnect();
refreshDeviceCache(); // HERE success to call the method but nothing happens
synchronized(m_BluetoothGattMutex){
if(mBluetoothGatt != null){
Logger.getInstance().logWarning(TAG, "m_bluetoothGatt close()");
mBluetoothGatt.close();
//refreshDeviceCache(); // HERE failed to call the method
mBluetoothGatt = null;
Logger.getInstance().logWarning(TAG, "m_bluetoothGatt nulled");
}
}
(…)
}
For your first point, the only thing I do with your library is simply calling the previous written method startUpdate() after my device disconnection. You wrote “simple start DFU while being connected to it ». I must not disconnect?
Any help can be appreciated. Thank you by advance
Best regards
Yann
from android-dfu-library.
Hello,
I have another information : our device is PAIRED (bonded) just before the disconnection : That means the methods does nothing if I don’t modify it or force the flag every time. Then I removed the test to be sure about refreshing every time :
I don't understand. You use your device as not bonded and then bond just before disconnection? What methods? What flag? What test?
refreshDeviceCache(); // HERE success to call the method but nothing happens
This is exactly how we do it.
call gatt.disconnect();
// wait for onConnectionStateChange(newState = Disconnected)
in this callback call refreshDeviceCache() and then close().
There is no callback for clearing the cache, but Android should perform service discovery next time you call discoverServices() as the cache will be empty.
Keep in mind, that if your device is bonded, and you are using Legacy DFU from SDK 8+, where the bootloader supports sending Service Changed indication, you don't have to clear the cache at all. The bond information will be copied to the bootloader and the after connecting to bootloader it will send the indication and Android will perform service discovery on its own.
For your first point, the only thing I do with your library is simply calling the previous written method startUpdate() after my device disconnection. You wrote “simple start DFU while being connected to it ». I must not disconnect?
The DFU lib handles switching to bootloader mode on its own. The requirements for Legacy DFU are as follows:
- In your app mode you have to have DFU Service with 1, 2 or 3 characteristics (DFU Packet (optional, not present in mbed impl), DFU Control Point (mandatory), and for bootloaders from SDK 7+: DFU Version)
- After enabling DFU Control Point notifications and writing 01-04 the device should restart in bootloader mode.
- The service will take care of disconnection and will reconnect to the same device address. If necessary it will also clear cache (necessary = device was not bonded || device was bonded and DFU Version was not present or returned value lower than 0.8 (?) (0x08-00) ).
You may, bot don't have to disconnect from your device before calling initiator.start(). On Android each BluetoothGatt object sees the connection independently, so the service will connect to already connected device and will see it as if it has just been connected. It will not be aware that some other app or component in your app is already connected. Sending 01-04 will enforce disconnection from target side, so all connected components will get disconnect event.
from android-dfu-library.
Yes that was it!
In the same time you wrote your answer, I test without disconnection and it perfectly works like that...
I test on 2 mobiles for the moment. It seems to be OK.
I now start testing on the full Android devices we have but I’m quite sure everything will be OK!
Thank you for your time. I think you can close the thread :-)
Best regards
from android-dfu-library.
Glad to hear that! Closing issue then. Good luck!
from android-dfu-library.
Related Issues (20)
- Hello! HOT 1
- Unable to use version 2.3.1 with Unity due to Java 17 not being supported. HOT 2
- [Version Android - 14] - java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts HOT 10
- Crash on Android 14 because of no type on startForeground HOT 5
- Android 14 requires starting FGS with service type specified HOT 2
- Android 14 - Permission FOREGROUND_SERVICE_CONNECTED_DEVICE requires video for play store HOT 1
- Problems with binding for xamarin/maui: string with multiple placeholders HOT 6
- Application stuck after Discovering services. HOT 2
- DFU Service Not Disconnecting and Restarting After Unplanned Disconnections
- `startForeground` doesn't specify a `foregroundServiceType` HOT 2
- nRF connect crashes when device reports 0 bytes for DFU partition HOT 2
- Causing MissingForegroundServiceTypeException on android 14 HOT 1
- Dfu Failing HOT 5
- Fatal Exception: android.app.ForegroundServiceStartNotAllowedException on Android 13 / 14 HOT 6
- What are the Vendor commands used by DFU? HOT 1
- Automatic Reconnection not available on Android 14 HOT 2
- Android 14 GATT 133 1 HOT 3
- Error 8(0x8): GATT CONN TIMEOUT HOT 1
- DfuServiceInitiator requires a new method
- GATT ERROR on Realme C33 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-dfu-library.