The device GattServer stops advertising after connecting to it

隐身守侯 提交于 2019-12-08 04:39:04

问题


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?


回答1:


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:


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();
        }
    }


来源:https://stackoverflow.com/questions/47676988/the-device-gattserver-stops-advertising-after-connecting-to-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!