don / cordova-plugin-ble-central

Bluetooth Low Energy (BLE) Central plugin for Apache Cordova (aka PhoneGap)
Apache License 2.0
946 stars 609 forks source link

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

Open vinothkumartyson opened 4 years ago

vinothkumartyson commented 4 years ago

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));
         }); 
don commented 4 years ago

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.

joshdotblack commented 4 years ago

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 " )

Francois-Belanger commented 4 years ago

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 commented 4 years ago

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 !