-
Notifications
You must be signed in to change notification settings - Fork 131
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
Provide Write
capability on DeviceCharacteristic
#153
Comments
Isn't func (c DeviceCharacteristic) Write(p []byte) (n int, err error) {
c.service.device.prph.WriteCharacteristic(p, c.characteristic, true)
return len(p), nil
} in |
I would suggest For example, here is an implementation for Linux I wrote a few days ago: diff --git a/gattc_linux.go b/gattc_linux.go
index 4d3fcb5..7a5ec47 100644
--- a/gattc_linux.go
+++ b/gattc_linux.go
@@ -207,12 +207,20 @@ func (s *DeviceService) DiscoverCharacteristics(uuids []UUID) ([]DeviceCharacter
return chars, nil
}
+func (c DeviceCharacteristic) WriteRequest(p []byte) (n int, err error) {
+ err = c.characteristic.WriteValue(p, map[string]interface{}{"type": "request"})
+ if err != nil {
+ return 0, err
+ }
+ return len(p), nil
+}
+
// WriteWithoutResponse replaces the characteristic value with a new value. The
// call will return before all data has been written. A limited number of such
// writes can be in flight at any given time. This call is also known as a
// "write command" (as opposed to a write request).
func (c DeviceCharacteristic) WriteWithoutResponse(p []byte) (n int, err error) {
- err = c.characteristic.WriteValue(p, nil)
+ err = c.characteristic.WriteValue(p, map[string]interface{}{"type": "command"})
if err != nil {
return 0, err
} |
@aykevi I believe Should that be changed as well? It may break compatibility unnecessarily. Although this is early days, so now is a better time to change it than later on 🤔 |
Hmm, yes, you are right. (Also, I realized there are two different ways of calling them, either "write"/"write without response" or "write request"/"write command" - perhaps it's best to not mix those two). |
Yes, these are two separate concepts:
I've tested the code with changes I mentioned and everything seemed fine at the beginning but with two different sequential write requests when I read response for the second one I still got response for the first. I didn't have time to investigate what is the problem. I switched to bleak and can recommend it if you are not sticked to golang. |
The suggestion of @BYEDUCK did the trick for me. Did an awful workaround using My project uses the original Go compiler, but includes this library because it is the best option with regular maintenance. |
Is it possible for this library to provide
Write
method onDeviceCharacteristic
(MacOS) ?Some devices have disabled
writeWithoutResponse
and only enabledwrite
on their characteristics.The text was updated successfully, but these errors were encountered: