Pilloxa / react-native-nordic-dfu

Nordic Device Firmware Update for React Native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Could not find device with deviceAddress [3.2.1]

marcopiraccini opened this issue · comments

commented

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?

commented

OK, this is probably a duplicate of: #121 (I am also using react-native-ble-plx )

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);
commented

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

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

@marcopiraccini Did you get around to preparing the PR?

@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' })

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