cordova-plugin-ble-central icon indicating copy to clipboard operation
cordova-plugin-ble-central copied to clipboard

connected callback is not called on ble.connect() in iOS when peripheral advertises no services

Open vinothkumartyson opened this issue 4 years ago • 4 comments

ble.connect(myDeviceID, function(device) { alert("Successfully connected to device"); console.log("Send Data method success call back called"); var success = function() { alert("Write Successfully"); }; var failure = function(err) { alert("Failed writing data : "+JSON.stringify(err)); };

             var ID = '7';
             var data = stringToBytes(ID);
             var test = device.characteristics;
             console.log(JSON.stringify(test[10]));
             var chars = device.characteristics;
             var service = chars[10].service;
             var characteristics = chars[10].characteristic;
             var deviceID = device.id;
             console.log("Device ID : "+deviceID);
             console.log("Serivce : "+service);
             console.log("Device ID : "+characteristics);
             console.log("DResult : "+JSON.stringify(device));

             ble.writeWithoutResponse(deviceID,service,characteristics, data, success, failure);
         }, function(err) {
            console.log("Send Data method failed call back called");
            alert("Failed to connect"+JSON.stringify(err));
         }); 

vinothkumartyson avatar Jun 23 '20 13:06 vinothkumartyson

This is probably and app or device issue. The plugin works well with iOS. Maybe the connection is waiting for a timeout? Try resetting the peripheral. Turn Bluetooth on and off on the iOS device or reboot it. I recommend that you write a simple app the scans and connects to help debug this.

don avatar Jun 23 '20 17:06 don

I'm seeing the same issue too, building a basic scan & connect app to test the plugin out.

Scanning works great but when I call connect with the UUID of a device the callback is never fired.

I've tried cycling the bluetooth & power-cycling the device with no luck, I've also set an interval to call isConnected every second & its returning as not connected.

Interestingly, I also tried autoConnect instead of connect and that seems to work fine. I noticed in the xcode logger that when I call connect no call to the Native Cordova bridge gets logged (when I call other methods I see something similar to: "To Native Cordova -> BLE <METHOD_HERE>" )

joshdotblack avatar Jul 16 '20 21:07 joshdotblack

Hi, I have the same issue with iOS. I can see the connection is made, but the callback is never called :-(. Did you find a reason or a fix ?

Francois-Belanger avatar Oct 08 '20 22:10 Francois-Belanger

Ok, this is a device bug, not iOS. But still.. would have been fun for iOS to flag a mistake. My device didn't adv any services... Thanks for the great work !

Francois-Belanger avatar Oct 08 '20 23:10 Francois-Belanger