3

This is the link to the GATT Server sample for Android Things on GitHub:

https://github.com/androidthings/sample-bluetooth-le-gattserver

Setting up the server on RPi-3 is easy enough.

What I do not understand is why the GATT server stops advertising once you have connected to then disconnected from the device (BLE connect).

...gattserver I/GattServerActivity: BluetoothDevice CONNECTED: 67:2F:1A:B4:1F:86
...gattserver D/BluetoothGattServer: onConnectionUpdated() - Device=67:2F:1A:B4:1F:86 interval=6 latency=0 timeout=2000 status=0
...gattserver D/BluetoothGattServer: onConnectionUpdated() - Device=67:2F:1A:B4:1F:86 interval=39 latency=0 timeout=2000 status=0
...gattserver I/GattServerActivity: Read CurrentTime
...gattserver I/GattServerActivity: Read CurrentTime
...gattserver I/GattServerActivity: Read CurrentTime
...gattserver I/GattServerActivity: Read CurrentTime
...gattserver I/GattServerActivity: Read CurrentTime
...gattserver D/GattServerActivity: Config descriptor read
...gattserver I/GattServerActivity: Read LocalTimeInfo
...gattserver D/BluetoothGattServer: onServerConnectionState() - status=0 serverIf=5 device=67:2F:1A:B4:1F:86
...gattserver I/GattServerActivity: BluetoothDevice DISCONNECTED: 67:2F:1A:B4:1F:86
...gattserver I/GattServerActivity: No subscribers registered

The above is what shows in the LogCat for the device. First line shows that my phone was able to connect to the device. (using this free and excellent app: https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp )

When connected I can read it's characteristics (Read CurrentType, Read LocalTimeInfo etc.)

When disconnecting the phone/app from the device the GattServerActivity states that I disconnected with grace and keeps on running...

But trying to scan for devices from the phone/app again reveals that the GATT Server on the RPi has gone zombie...

No errors in the LogCat (not in app, not in system)...

Thoughts anyone?

3
  • So the issue is that the GATT server doesn't start advertising again on disconnection? Can you just add a new line here to start advertising again? Dec 6, 2017 at 18:21
  • @Nick Felker I can (and thanks). It's just that I never expected it to stop... Is this normal behavior for BLE advertising? Dec 7, 2017 at 7:27
  • I'm not an expert in the BLE behavior, so I do not know if it is intentional. I will check with the sample. But I will reformat the comment above as the canonical answer. Dec 7, 2017 at 18:32

2 Answers 2

2

The issue seems to be that the GATT server doesn't start advertising again on disconnection? You should be able to add a new line here to start advertising again.

2
  • I tested the same with my Polar H7, and it has similar behaviour. So answer accepted! Thanks! Dec 8, 2017 at 13:20
  • A gatt server is by spec REQUIRED to stop advertising (a connectable advertisement) on connection. Jan 27, 2018 at 15:05
1

Tried just re-starting advertising, but that didn't work so I stopped and started and that worked. Test on RPi 3B

@Override
    public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
        if (newState == BluetoothProfile.STATE_CONNECTED) {
            Log.i(TAG, "BluetoothDevice CONNECTED: " + device);
        } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
            Log.i(TAG, "BluetoothDevice DISCONNECTED: " + device);
            //Remove device from any active subscriptions
            mRegisteredDevices.remove(device);
            stopAdvertising();
            startAdvertising();
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.