Skip to content

Commit 31bcba3

Browse files
aventarideadprogram
authored andcommitted
Update gattc_linux.go to properly unsubscribe from notifications using dbus call
1 parent f868955 commit 31bcba3

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

gattc_linux.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,19 @@ func (c *DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) er
277277
if c.property == nil {
278278
return nil
279279
}
280-
281-
err := c.adapter.bus.RemoveMatchSignal(c.propertiesChangedMatchOption)
280+
// Make the D-Bus call to stop notifications on the characteristic.
281+
stopNotifyErr := c.characteristic.Call("org.bluez.GattCharacteristic1.StopNotify", 0).Err
282+
// Still clean up other resources if there was an error
283+
removeSignalErr := c.adapter.bus.RemoveMatchSignal(c.propertiesChangedMatchOption)
282284
c.adapter.bus.RemoveSignal(c.property)
283285
close(c.property)
284286
c.property = nil
285-
return err
287+
288+
// If there were errors, prioritize notify err
289+
if stopNotifyErr == nil {
290+
return removeSignalErr
291+
}
292+
return stopNotifyErr
286293
}
287294
}
288295

0 commit comments

Comments
 (0)