fengqiangboy / flutter-nordic-dfu

Flutter Nordic dfu
MIT License
109 stars 76 forks source link

PlatformException(2, DFU FAILED, ...) on DFU attempt #31

Closed MBjoern closed 3 years ago

MBjoern commented 3 years ago

Hi

I'm following your instructions to use the dfu feature. But no matter what i do, i'm getting the same exception: PlatformException(2, DFU FAILED, device address: DC:3E:41:AC:F3:75, null)

Any hints on why this is happening? I've also seen the log entry:

W/DfuBaseService(15862): DFU Service not found.

maybe that helps. I'd suspect the service to be declared in the Manifest of your library, isn't it?

  Future<void> _updateFirmware() async {
    print("START DFU HERE");
    try {
      await FlutterNordicDfu.startDfu(
        widget.request.gadget.getDeviceAddress(),
        // _firmwarePath,
        'assets/file.zip',
        fileInAsset: true,
        progressListener:
            DefaultDfuProgressListenerAdapter(onProgressChangedHandle: (
          deviceAddress,
          percent,
          speed,
          avgSpeed,
          currentPart,
          partsTotal,
        ) {
          print('deviceAddress: $deviceAddress, percent: $percent');
        }),
      );
    } catch (exception) {
      print("Firmware Update Failed: $exception");
    }
  }

I'm getting the following log:

I/flutter (15862): START DFU HERE
D/BluetoothAdapter(15862): STATE_ON
D/BluetoothGatt(15862): connect() - device: DC:3E:41:AC:F3:75, auto: false
D/BluetoothAdapter(15862): isSecureModeEnabled
D/BluetoothGatt(15862): registerApp()
D/BluetoothGatt(15862): registerApp() - UUID=648c2f50-01a1-4427-a54d-25e04930fae5
D/BluetoothGatt(15862): onClientRegistered() - status=0 clientIf=13
D/BluetoothGatt(15862): onClientConnectionState() - status=0 clientIf=13 device=DC:3E:41:AC:F3:75
D/BluetoothGatt(15862): discoverServices() - device: DC:3E:41:AC:F3:75
D/BluetoothGatt(15862): onConnectionUpdated() - Device=DC:3E:41:AC:F3:75 interval=6 latency=0 timeout=500 status=0
D/BluetoothGatt(15862): onSearchComplete() = Device=DC:3E:41:AC:F3:75 Status=0
W/DfuBaseService(15862): DFU Service not found.
D/BluetoothGatt(15862): cancelOpen() - device: DC:3E:41:AC:F3:75
D/BluetoothGatt(15862): onClientConnectionState() - status=0 clientIf=13 device=DC:3E:41:AC:F3:75
D/BluetoothGatt(15862): refresh() - device: DC:3E:41:AC:F3:75
D/BluetoothGatt(15862): close()
D/BluetoothGatt(15862): unregisterApp() - mClientIf=13
I/flutter (15862): Firmware Update Failed: PlatformException(2, DFU FAILED, device address: DC:3E:41:AC:F3:75, null)
MBjoern commented 3 years ago

Solution in my case

Adding

enableUnsafeExperimentalButtonlessServiceInSecureDfu: true,

to the startDfu call fixed it on Android for my nordic firmware.