0

I'm attempting to establish a connection with the Intel Edison as a central and a regular android phone as a peripheral.

The Edison detects the Android phone just fine and attempts to establish a connection like this:

 @Override
    public void onScanResult(int callbackType, final ScanResult result) {
        super.onScanResult(callbackType, result);
        BluetoothDevice device=result.getDevice());
        device.connectGatt(context, false, bluetoothGattCallback);
}

and also with the TRANSPORT variations:

device.connectGatt(context, false, bluetoothGattCallback, TRANSPORT_LE);

and

device.connectGatt(context, false, bluetoothGattCallback, TRANSPORT_AUTO);

But in all cases, the connection fails with a status 133 on the bluetoothGattCallback

using autoconnect as true results in nothing happening at all.

This is my BluetoothGattGallback:

 @Override
        public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
            super.onConnectionStateChange(gatt, status, newState);
               if (status == 133) {
                Log.e(TAG, "Got the status 133 bug. " + gatt.getDevice().getAddress());
                gatt.disconnect();
                gatt.close();
            }

I can confirm it's not an issue with the peripheral since connections between two android phones work just fine. It's just the Intel Edison that fails to connect.

0andriy
  • 4,183
  • 1
  • 24
  • 37
Roberto Betancourt
  • 2,375
  • 3
  • 27
  • 35
  • 1
    please show a full code replication of your problem. For example you don't show if you do anything with the returned `BluetoothGatt` from the method - but if i wrote that as an answer you'll probably say you do. Which wastes both our time. Try to show a full code replication of your problem to avoid this in all stackoverflow questions. – Blundell May 25 '17 at 19:55

1 Answers1

1

For what its worth, you should use auto-reconnect, (to keep the connection alive if lost for some reason) as an example:

private BluetoothGatt gatt; // store this incase you need it later

gatt = device.connectGatt(context, true, bluetoothGattCallback);

private final BluetoothGattCallback bluetoothGattCallback = new BluetoothGattCallback() {
 @Override
 public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
   super.onConnectionStateChange(gatt, status, state);
   Log.d("SO", "State: " + state); // Should get connected here (2)
  }
 };

but due to your incomplete question I cannot 100% prove if this is your solution

https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html https://developer.android.com/reference/android/bluetooth/BluetoothProfile.html#STATE_CONNECTED

when using false you would have to call gatt.connect() yourself.


I cannot see a status of 133 in this list https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html was that a typo?

Blundell
  • 75,855
  • 30
  • 208
  • 233
  • I've expanded my original question to show the code. 133 is not a typo but an uknown error that is not documented. When i receive status==133 on the onConnectionStateChange of the bluetoothGattCallback i disconnect and close the gatt and wait until the device is discovered again to retry. Setting autoconnect to true results in nothing happening at all; device is never connected and nothing is received in the onConnectionStateChange. – Roberto Betancourt May 25 '17 at 20:52
  • did you try calling `gatt.connect()` yourself? its in my answer – Blundell May 26 '17 at 07:50
  • Yes, definitely. – Roberto Betancourt May 26 '17 at 12:41
  • you don't show it in your question? How do you expect people to help without all the information. https://stackoverflow.com/help/mcve – Blundell May 26 '17 at 12:46