本文整理匯總了Golang中github.com/paypal/gatt.Peripheral.WriteCharacteristic方法的典型用法代碼示例。如果您正苦於以下問題:Golang Peripheral.WriteCharacteristic方法的具體用法?Golang Peripheral.WriteCharacteristic怎麽用?Golang Peripheral.WriteCharacteristic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/paypal/gatt.Peripheral
的用法示例。
在下文中一共展示了Peripheral.WriteCharacteristic方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: onPeriphConnected
func onPeriphConnected(p gatt.Peripheral, err error) {
log.Println("Connected")
peripheral = p
err = p.SetMTU(500)
if err != nil {
log.Printf("Failed to set MTU, err: %s\n", err)
}
uuid, err := gatt.ParseUUID("f000aa00-0451-4000-b000-000000000000")
if err != nil {
log.Printf("Failed to create UUID, err: %s\n", err)
return
}
ss, err := p.DiscoverServices(nil)
if err != nil {
log.Printf("Failed to discover IR sensor service, err: %s\n", err)
return
}
var s *gatt.Service
for _, s = range ss {
if s.UUID().Equal(uuid) {
break
}
}
cs, err := p.DiscoverCharacteristics(nil, s)
if err != nil {
log.Printf("Failed to discover characteristics, err: %s\n", err)
return
}
for _, c := range cs {
_, err = p.DiscoverDescriptors(nil, c)
if err != nil {
log.Printf("Failed to discover descriptors, err: %s\n", err)
return
}
}
data := cs[0]
config := cs[1]
samplerate := cs[2]
// Turn on notifications
err = p.SetNotifyValue(data, handleTempNotification)
if err != nil {
log.Printf("Failed to write config characteristics, err: %s\n", err)
return
}
// Set sample rate
err = p.WriteCharacteristic(samplerate, []byte{0xFF}, false)
if err != nil {
log.Printf("Failed to write samplerate characteristics, err: %s\n", err)
return
}
// Start sensors
err = p.WriteCharacteristic(config, []byte{0x01}, false)
if err != nil {
log.Printf("Failed to write config characteristics, err: %s\n", err)
return
}
}