Bluetooth
Bluetooth copied to clipboard
Fix GATT Notifications
GATTServer
should not be sending GATT notifications to the connected client that wrote the value.
- [x] If the Peripheral wrote a new value, all connected clients should be notified.
- [x] If a Central wrote a value, all connected centrals, except the one that wrote the value, should be notified.
Initial work in https://github.com/PureSwift/Bluetooth/commit/ab33985b8621d122662be941b2a4f267cb80ba07 . Need to differentiate between:
- [x] Write triggered by Peripheral (inform all Centrals)
- [x] Write triggered by current Central (inform other Centrals)
- [x] Write triggered by other Central (Inform this Central)
Notifications for characteristics will not work for multiple characteristics with the same UUID in a service.
https://github.com/PureSwift/Bluetooth/blob/ab33985b8621d122662be941b2a4f267cb80ba07/Sources/GATTServer.swift#L280
There seems to also be issues in the GATTClient
implementation https://gist.github.com/wlisac/75650c0bc54ffb4a248b8aff306ff715
I can confirm the there is an issue around GATTClient processing notifications. A peripheral receives and processes the subscribe request from the GATTClient and the unsubscribe request when the GATTClient is closed. Notifications sent by the peripheral are not being processed correctly by the GATTClient. Before I debug further I thought I’d ask if anyone else is actively working on this and if so what progress has been made?
I am also getting this error
Assertion failed: Invalid range: file /data/scanner/SwiftScanner/.build/checkouts/Bluetooth/Sources/BluetoothGATT/GATTClient.swift, line 470
Whenever I start a notify on characteristic. It doesn't happen every time but does once about 1 in 3 times.