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?