bluetooth icon indicating copy to clipboard operation
bluetooth copied to clipboard

Cannot disable notifications by passing nil to EnableNotifications as documented

Open Ranveer0508 opened this issue 7 months ago • 3 comments

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

Image

Ranveer0508 avatar May 29 '25 09:05 Ranveer0508

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) {
					})

kevin-activ avatar Aug 25 '25 23:08 kevin-activ

Fixed for linux here: https://github.com/tinygo-org/bluetooth/pull/393

aventari avatar Oct 29 '25 00:10 aventari

Labeled to close this issue on next release. Thanks, everyone!

deadprogram avatar Nov 11 '25 15:11 deadprogram