Skip to content

Instantly share code, notes, and snippets.

@anisbhsl
Created May 30, 2020 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anisbhsl/d905d1b65cf6c5db40896225587518a5 to your computer and use it in GitHub Desktop.
Save anisbhsl/d905d1b65cf6c5db40896225587518a5 to your computer and use it in GitHub Desktop.
package service
import "github.com/bettercap/gatt"
func NewBatteryService() *gatt.Service {
lv := byte(100)
s := gatt.NewService(gatt.UUID16(0x180F))
c := s.AddCharacteristic(gatt.UUID16(0x2A19))
c.HandleReadFunc(
func(rsp gatt.ResponseWriter, req *gatt.ReadRequest) {
rsp.Write([]byte{lv})
lv--
})
// Characteristic User Description
c.AddDescriptor(gatt.UUID16(0x2901)).SetStringValue("Battery level between 0 and 100 percent")
// Characteristic Presentation Format
c.AddDescriptor(gatt.UUID16(0x2904)).SetValue([]byte{4, 1, 39, 173, 1, 0, 0})
return s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment