Closed raowhizz closed 8 years ago
You can write your own handler, and register it with
SetNotifyValue(c *Characteristic, f func(*Characteristic, []byte, error)) error
Regarding p.SetNotifyValue(), the easiest way is to modify the examples/explorer.go and give it a try.
Note:
Roy
diff --git a/examples/explorer.go b/examples/explorer.go
index a25fa2f..ad2048a 100644
--- a/examples/explorer.go
+++ b/examples/explorer.go
@@ -8,6 +8,7 @@ import (
"log"
"os"
"strings"
+ "time"
"github.com/paypal/gatt"
"github.com/paypal/gatt/examples/option"
@@ -116,9 +117,22 @@ func onPeriphConnected(p gatt.Peripheral, err error) {
}
fmt.Printf(" value %x | %q\n", b, b)
}
+
+ // Subscribe the characteristic, if possible.
+ if (c.Properties() & (gatt.CharNotify | gatt.CharIndicate)) != 0 {
+ f := func(c *gatt.Characteristic, b []byte, err error) {
+ fmt.Printf("notified: % X | %q\n", b, b)
+ }
+ if err := p.SetNotifyValue(c, f); err != nil {
+ fmt.Printf("Failed to subscribe characteristic, err: %s\n", err)
+ continue
+ }
+ }
+
}
fmt.Println()
}
+ time.Sleep(5 * time.Second)
}
Can someone tell me what is didUpdateValueForCharacteristic() equivalent in GATT ? Basically I want to read notification .