Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect to device : Error Callback #78

Closed
gibbsvjy opened this issue Aug 26, 2014 · 15 comments
Closed

Unable to connect to device : Error Callback #78

gibbsvjy opened this issue Aug 26, 2014 · 15 comments

Comments

@gibbsvjy
Copy link

I have integrated plugin using CLI successfully and also listed connected android device but when i call bluetoothSerial.connect it is always go to error callback though Mac Address of remote device is correct.. I have also tried by put this into SETTIMEOUT but not working. please help me to resolve this issue I am stucked in this problem.

@don
Copy link
Owner

don commented Aug 29, 2014

Are you seeing the problem on iOS or Android?

What device are you trying to connect to?

@ankittanna
Copy link

Hi Don,

We are facing the same issue. We are trying to connect a Samsung S4 which is paired with Nexus 7 Tab. We have the mac address of the Nexus 7 Tab and we call the bluetoothSerial.connect API. But this always goes in error function saying "Unable to connect to device".

I am getting in to enabled success handler and I also got the list of devices.

Below is the code:

            var bluetoothSerial = cordova.require('bluetoothSerial');
    document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady()
    {
        bluetoothSerial.isConnected(success, failure);
        bluetoothSerial.isEnabled(bluetoothSerialSuccess, bluetoothSerialFailure);
        bluetoothSerial.list(deviceListSuccess, deviceListFailure);
    }

    function success()
    {
        console.log("Success");
    }

    function failure()
    {
        console.log("No Success");
    }

    function bluetoothSerialSuccess(enabled)
    {
        console.log("Success1");
        console.log("Success1 " + enabled);
    }

    function bluetoothSerialFailure()
    {
        console.log("not enabled");
    }


    function deviceListSuccess(devices)
    {
        bluetoothSerial.connect("60:A4:4C:96:22:F8", connectSuccess, connectFailure);
    }
    // 60:A4:4C:96:22:F8
    function deviceListFailure()
    {
        alert("Failed to read the list");
    }

    function connectWithDevice(deviceMacAddress)
    {
        bluetoothSerial.connect("60:A4:4C:96:22:F8", connectSuccess, connectFailure);
    }

    function connectSuccess(a)
    {
         alert("connection successful");
    }

    function connectFailure(e)
    {
        alert(JSON.stringify(e));
    }

@don
Copy link
Owner

don commented Sep 8, 2014

@ankittanna This plugin does not support Android to Android communication.

Android is using Bluetooth Classic and expects to connect to a generic RFCOMM uuid 00001101-0000-1000-8000-00805F9B34FB.

The plugin does not implement code that starts a server socket. If you had another Android app start a server socket it's theoretically possible for an app using this plugin to connect to it.

This Android code in the plugin is based on sample in the Android SDK. They have a good example of Android to Android chat.

@ankittanna
Copy link

Hi Don,

This would be the most common scenario of Android to Android Communication?

Do we have any alternative plugin for the same?

Thanks,
Ankit.

@don
Copy link
Owner

don commented Sep 8, 2014

I don't know of an alternative plugin.

Look at BluetoothSerialService.AcceptThread, you can probably modify it to open the socket on UUID_SPP (00001101-0000-1000-8000-00805F9B34FB) and add some JavaScript wrappers for cordova.

bluetoothSerial.acceptConnection(onConnect, onFailure)

If you get something to work, send a pull request. I'm not planning on adding this functionality unless a client needs it.

@booybooy
Copy link

booybooy commented Jan 4, 2015

Hi Don,

I'm getting "Unable to connect to device" when attempting to connect to a paired device with its MAC address on Android. I have gotten the mac address via a call to bluetoothSerial.list(), so I'm certain that the address is correct. Here are some information regarding the devices:

Running on: Android 4.4.4
Bluetooth device: AB Shutter 3 (a camera remote)

Any suggestions on how to troubleshoot?

@don
Copy link
Owner

don commented Jan 5, 2015

@ankittanna There is a fork that should work with Android to Android https://github.com/tomvanenckevort/BluetoothSerial

@don
Copy link
Owner

don commented Jan 5, 2015

@booybooy I'd guess that the camera doesn't support Serial Port Profile (SPP). The plugin expects to connect to UUID 00001101-0000-1000-8000-00805F9B34FB.

You can modify the plugin if the camera is using a different UUID, but I'd expect is using another Bluetooth Profile.

@booybooy
Copy link

booybooy commented Jan 9, 2015

This is probably out of scope, but any idea how to find out which profile this camera remote supports, i.e via API?

I'm also confused about: "The plugin expects to connect to UUID 00001101-0000-1000-8000-00805F9B34FB.". Does this pertain to only Android? Because BluetoothSerial.connect()'s documentation seems to suggest that if I were developing with iOS, I'd be able to pass in the UUID of the camera remote to make the connection.

@don
Copy link
Owner

don commented Jan 9, 2015

No idea on your camera.

For Android, the plugin used Bluetooth Classic and uses Serial Port Profile (SPP). 00001101-0000-1000-8000-00805F9B34FB is a well known RFCOMM UUID.

For iOS, this plugin uses Bluetooth Low Energy (BLE). BLE doesn't have SPP, but a bunch of the devices have custom UART services that behave similar to SPP. On iOS you're passing in the iOS generated UUID that is a reference to the BLE device that was discovered when scanning for devices. BLE doesn't pair like Bluetooth Classic.

@Sasikumariosdeveloper
Copy link

Hai Don,
AB Shutter3 have bluetooth address.using that address may i send alert to iphone devices.otherwise that bluetooth id might be helpful or not..seetings->general->about->bluetooth(this id)

@don
Copy link
Owner

don commented Sep 23, 2015

@Sasikumariosdeveloper I don't think the AB Shutter 3 will work with this plugin. I expect the AB Shutter 3 just emulates a HID (keyboard) on iOS.

The Bluetooth id in the settings is the MAC address of the adapter. This plugin uses Bluetooth Low Energy on iOS. For BLE, iOS needs a UUID to connect. You get the UUID by scanning for Bluetooth devices.

@Sasikumariosdeveloper
Copy link

Good Morning Don,
How can i get UUID while scanning for bluetooth devices.

@andymurakami
Copy link

Hi Don,

I try to connect in a Blue Bamboo PM25-M bluetooth. But when I send de connect command. They returns same error : Unable to connect to device.

I use ionic + angularJS

bluetoothSerial.connectInsecure(
app.macAddress, // device to connect to
app.openPort, // start listening if you succeed
app.showError // show the error if you fail
);

The MAC Address is correct .

Do you have any solution ?

@uninxc
Copy link

uninxc commented Mar 3, 2020

@booybooy booybooy follow code will be work!
` window.addEventListener('keydown', (e) => {
console.log('keydown');
console.log(e.key);
console.log(e.keyCode);
});

document.addEventListener('volumedownbutton', (e) => {
  console.log('volumedownbutton');
  console.log(e);
  console.log(JSON.stringify(e));
}, false);
document.addEventListener('volumeupbutton', (e) => {
  console.log('volumeupbutton');
  console.log(e);
  console.log(JSON.stringify(e));
}, false);`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants