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

Connection via MAC address does not seem to work #13

Closed
tchapi opened this issue Jul 20, 2017 · 2 comments
Closed

Connection via MAC address does not seem to work #13

tchapi opened this issue Jul 20, 2017 · 2 comments

Comments

@tchapi
Copy link

tchapi commented Jul 20, 2017

Hi,

Background

I'm using the latest SDK version (3.0.32), targeting API > 21, compiling on Android Studio 2.3.3 on Mac OS Sierra and I'm trying to connect to a board via its MAC address. I currently have a MetaWearRG board to test.

Code

My code is very basic :

public void connectToBoard(final String macAddr) {
        final BluetoothManager btManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
        final BluetoothDevice remoteDevice = btManager.getAdapter().getRemoteDevice(macAddr);
        board = serviceBinder.getMetaWearBoard(remoteDevice);

        board.connectAsync().continueWithTask(new Continuation<Void, Task<Void>>() {
            @Override
            public Task<Void> then(Task<Void> task) throws Exception {
                return task.isCancelled() || !task.isFaulted() ? task : reconnect(board);
            }
        }).continueWith(new Continuation<Void, Task<Void>>() {
            @Override
            public Task<Void> then(Task<Void> task) throws Exception {
                Log.i("COMPANION", "Connected to " + macAddr);
                return task
                });
            }
        });
    }

It's actually quite the same as the Freefall sample app.

Problems

The app never connects to the device. More specifically, here is the BluetoothGatt output :

I/MYAPP: Starting app, connecting ...
D/BluetoothGatt: connect() - device: FF:44:46:AA:21:AF, auto: false
D/BluetoothGatt: registerApp()
D/BluetoothGatt: registerApp() - UUID=54798817-8ffe-4289-bdea-5764162a6a2b
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=5
D/BluetoothGatt: refresh() - device: FF:44:46:AA:21:AF
D/BluetoothGatt: close()
D/BluetoothGatt: unregisterApp() - mClientIf=5
I/MYAPP: Reconnecting ...

( and on and on, it reconnects ad infinitum )

When using the Starter or sample app, the output is similar but onClientConnectionState() is called and the process unfolds normally afterwards. It seems that when connecting directly with a MAC address, the onClientConnectionState() never gets called.

connect() - device: FF:44:46:AA:21:4F, auto: false
registerApp()
registerApp() - UUID=83be2c2e-bf0a-414c-a760-cc82149d6e8e
onClientRegistered() - status=0 clientIf=5
onClientConnectionState() - status=0 clientIf=5 device=FF:44:46:AA:21:4F
discoverServices() - device: FF:44:46:AA:21:4F
onSearchComplete() = Device=FF:44:46:AA:21:4F Status=0
setCharacteristicNotification() - uuid: 326a9006-85cb-9195-d9dd-464cfbbae75a enable: true

Findings :

  • the official Freefall sample app does not work, it does not connect to the board
  • this is true on various Android devices (Samsung, OPO, HTC) that all have a working Bluetooth chipset
  • on these same devices, the Starter app works correctly
  • on these same devices, the sample app works correctly too
  • the board is fully charged and works perfectly (I have an iOS app that work as expected, connects to it, streams data, ...)

Any help would be greatly appreciated. I can provide more details if needed.
Thanks !

@scaryghost
Copy link
Contributor

scaryghost commented Jul 20, 2017

The free fall app works fine as is on our devices (Nexus 5, 6, 9, Galaxy S4, Galaxy S4 mini, virtualized Android x86 machines). This is the first time we've seen an issue with the connect by mac address code in the app which leads me to believe that is isn't an issue with the MetaWear API itself but rather a general issue with how Bluetooth is / should be used on those Android devices and OS builds.

Because of this, I am closing this issue for now and will reopen it if indeed there is a problem with the BLE code used in the API.

We can continue this discussion on the community forum.

@tchapi
Copy link
Author

tchapi commented Jul 21, 2017

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

2 participants