Fix 'GATT operation not permitted' by picking the writable characteristic - #28
Merged
Conversation
Contributor
|
This is a great contribution! Thank you. I will be testing it asap to include it in the repo. :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Sending any command to the robot fails with the following error in the browser console, even though the device pairs and connects successfully:
Chrome throws
NotSupportedError: GATT operation not permitted.whenwriteValue()is called on a characteristic whose properties include neitherwritenorwriteWithoutResponse.gotCharacteristics()injs/bluetooth.jspicked the target characteristic by position:getCharacteristics()does not guarantee any order, and several BLE 4.0 serial modules (HM-10 clones such as CC41-A, AT-09 or MLT-BT05) expose more than one characteristic inside the FFE0 service, sometimes splitting the serial port into a notify-only characteristic and a separate writable one. When the first characteristic in the list happens to be the read/notify-only one, the connection and the sensor notifications work, but every command sent bysendData()is rejected.Changes
All changes are in
js/bluetooth.js, which is shared byindex.html,ninja.htmlandcalibration.html, so all three pages are covered.write/writeWithoutResponseis used to send commands, the one advertisingnotify/indicateis used to receive sensor values.blueToothCharacteristicis kept and now points at the writable characteristic, so nothing else in the codebase had to change.writeValueWithoutResponse(), thenwriteValueWithResponse(), then the deprecatedwriteValue()for older browsers.Notes
connectToBle(),sendData(),gotValue()andonDisconnected()keep the same names and signatures.Testing
Tested on Windows 10 / Chrome with an Otto and a bluetooth module: pairing, sending movement and gesture commands, and receiving sensor values.