Cannot disable notifications by passing nil to EnableNotifications as documented
According to the documentation, it is implied that passing a nil callback to EnableNotifications() should disable notifications for a given characteristic.
However, in practice, doing so results in a runtime error:
must provide a callback for EnableNotifications
This makes it unclear how to properly disable or stop active notifications, especially for cleanup after a reading session is complete.
Expected Behavior:
Calling char.EnableNotifications(nil) should disable notifications, as implied in the documentation.
Actual Behavior:
Calling EnableNotifications(nil) results in an error.
Question:
What is the correct way to stop notifications for a characteristic once you're done?
Please advise if this is a missing feature, a documentation error, or if there's a workaround we should use in the meantime.
I have attached a screenshot of the source code that is responsible for this below
I've tried setting the characteristic notification function to an empty function, which works SOMETIMES, but sometimes I get a segfault error: "exit status 0xc0000005" Probably because it's attempting to reset the notification function when it's in the middle of running the old notification function.. Not sure how to set up mutexes or something to stop this.
This is how I reset it..
err = characteristic.EnableNotifications(func(value []byte) {
})
Fixed for linux here: https://github.com/tinygo-org/bluetooth/pull/393
Labeled to close this issue on next release. Thanks, everyone!