GithubHelp home page GithubHelp logo

Comments (5)

philips77 avatar philips77 commented on August 22, 2024

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:

  1. 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.
  2. 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.

YannSDW avatar YannSDW commented on August 22, 2024

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.

philips77 avatar philips77 commented on August 22, 2024

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.

YannSDW avatar YannSDW commented on August 22, 2024

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.

philips77 avatar philips77 commented on August 22, 2024

Glad to hear that! Closing issue then. Good luck!

from android-dfu-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.