Pilloxa / react-native-nordic-dfu

Nordic Device Firmware Update for React Native
MIT License
137 stars 118 forks source link

Could not find device with deviceAddress [3.2.1] #160

Open marcopiraccini opened 2 years ago

marcopiraccini commented 2 years ago

I am having this issue when I startDFU on iOS (on Android it works). I already checked and the deviceAddress is the UUID of the device (at it should be). Any idea?

marcopiraccini commented 2 years ago

I guess the error comes from here: https://github.com/Pilloxa/react-native-nordic-dfu/blob/master/ios/RNNordicDfu.m#L210

marcopiraccini commented 2 years ago

OK, this is probably a duplicate of: https://github.com/Pilloxa/react-native-nordic-dfu/issues/121 (I am also using react-native-ble-plx )

david-gettins commented 2 years ago

To save people from having to follow various links and collate the information, here is the solution that works for me when using react-native-ble-plx...

1. Your AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // ...

  [RNNordicDfu setCentralManagerGetter:^() {
      return [[CBCentralManager alloc] initWithDelegate:nil queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)];
  }];

  [RNNordicDfu setOnDFUComplete:^() {
  }];

  [RNNordicDfu setOnDFUError:^() {
  }];

  // ...
}

Originally from here

2. Inside the react-native-nordic-dfu folder in node_modules - RNNordicDfu.m

At line 200 or underneath the line: CBCentralManager * centralManager = getCentralManager(); add this:

[NSThread sleepForTimeInterval: 2];

Originally from here

Now everything works as expected. Apologies for duplicating this information but it took me 15mins to bring various bits from other issue comments together, hopefully this saves someone that time.

Finally, here is the patch I generated to apply this on install using patch-package:

diff --git a/node_modules/react-native-nordic-dfu/ios/RNNordicDfu.m b/node_modules/react-native-nordic-dfu/ios/RNNordicDfu.m
index ed58530..4c8b4a7 100644
--- a/node_modules/react-native-nordic-dfu/ios/RNNordicDfu.m
+++ b/node_modules/react-native-nordic-dfu/ios/RNNordicDfu.m
@@ -197,6 +197,7 @@ - (void)logWith:(enum LogLevel)level message:(NSString * _Nonnull)message
     reject(@"nil_central_manager_getter", @"Attempted to start DFU without central manager getter", nil);
   } else {
     CBCentralManager * centralManager = getCentralManager();
+    [NSThread sleepForTimeInterval: 2];

     if (!centralManager) {
       reject(@"nil_central_manager", @"Call to getCentralManager returned nil", nil);
marcopiraccini commented 2 years ago

OK, but there is a reason why this patch is not applied directly to the code? I can prepare a PR

p4bl1t0 commented 2 years ago

Yes, this should be a Pull Request or be added to the library

david-gettins commented 2 years ago

@marcopiraccini Did you get around to preparing the PR?

Irenedan commented 2 years ago

@marcopiraccini, I'm using the "react-native-ble-plx" too, but I don't know what parts are zip made of. Could you please put a zip file of yours here?

NordicDFU.startDFU({ deviceAddress: '94:54:93:17:63:75', deviceName: 'test', filePath: fs.CachesDirectoryPath + '/dry.zip' })

p4bl1t0 commented 2 years ago

The zip file should be your firmware code compiled by Arduino or Platform.io with the upload_protocol in nrfutil