1

i'm trying to update the firmware version of my Movesense sensors in my Flutter App, after investigating i found out that the steps to do that is put the device into update mode using the mds package, then start the device firmware update using the nordic package. here's what i'm doing:

  @override
  Future<void> startDeviceFirmwareUpdate(String deviceId, String serial, int value) async {
final Map<String, int> contract = {};
contract["NewState"] = value;
await MdsAsync.put(Mds.createRequestUri(serial, "/System/Mode"), jsonEncode(contract));

  NordicDfu().startDfu(
    deviceId,
    'assets/dfu.zip',
    fileInAsset: true,
    onDeviceDisconnecting: (string) {
      print('deviceAddress: $string');
    },
    onDeviceConnected: (address) {
      print("device is connected");
    },
    onDeviceConnecting: (address) {
      print("Device is connecting");
    },
    forceDfu: true,
    onError: (address, error, errorType, message) {
      print(" error  $error, errorType: $errorType, message: $message");
    },
    onProgressChanged: (
      deviceAddress,
      percent,
      speed,
      avgSpeed,
      currentPart,
      partsTotal,
    ) {
      print('deviceAddress: $deviceAddress, percent: $percent');
    },
  );

}

  void connectMovesenseBleDeviceById({
required BleDevice device,
required VoidCallback onConnect,
required VoidCallback onDisconnect,
 }) 
 bleDataSource.connectMovesenseDeviceById(
      device.id,
      onConnnect: (serial) async {
        final metaData = await bleDataSource.getMovesenseSensorInfo(device.serial);
        final deviceAppData = await bleDataSource.getMovesenseSensorAppInfo(device.serial);
        device.metaData = metaData;
        device.appData = deviceAppData;
        // HERE'S where I'm calling it ===>
        bleDataSource.startDeviceFirmwareUpdate(device.id, device.serial, 12);
        if (device.metaData!.isCompatible && device.appData!.isCompatible) {
          onConnect();
          bleDeviceLocalDataSource.persistBleDevice(bleDeviceModel: device as BleDeviceModel);
        }
        if (!_connectedDevicesStreamController.isClosed)
          _connectedDevicesStreamController
              .add(device.copyWith(status: BleDeviceConnectionStatus.connected) as BleDeviceModel);
      },
      onDisconnect: () {
        onDisconnect();
        if (!_connectedDevicesStreamController.isClosed)
          _connectedDevicesStreamController
              .add(device.copyWith(status: BleDeviceConnectionStatus.disconnected) as BleDeviceModel);
      },
      onError: () {
        //TODO: add translations and exception
        throw BluetoothException('Error occured when pairing the device');
      },
    );
  }

my problem here is that after putting the device into update mode, it disconnects from the phone, meaning i cant update it successfully. how can I achieve that?

Aymen Ziouche
  • 47
  • 3
  • 12
  • 1
    If this Movesense is using a nordic chip/firmware, then this disconnect is expected. What is happening is that the Movesense is resetting into bootloader mode, where it has a mini-firmware that can accept the new FW packets and overwrite the existing FW with the newly transferred packets. Of course because the device is resetting into this mode, the existing BLE connection will be lost. What you need to do is reconnect again and then start the transfer of the FW to the specified characteristics. – Youssif Saeed Aug 14 '23 at 09:09
  • Note that the bootloader might advertise with a different MAC address, by default it is the previous MAC + 1. See https://devzone.nordicsemi.com/f/nordic-q-a/11858/why-does-nordic-increase-the-ble-mac-address-by-one-in-dfu-bootloader for more infos – Michael Kotzjan Aug 16 '23 at 07:28
  • reconnecting is not possible because the device wont be visible to Bluetooth when in update mode. i also tried the different mac address approach but it's not working. - the device gets into update mode - the device disconnects - the device is not visible to reconnect – Aymen Ziouche Aug 21 '23 at 08:18

0 Answers0