-
• #2
There wasn't a way, but I just added one:
https://github.com/espruino/Espruino/commit/c79fa0093fc95ca0f50fb3ec3dc1ed9d2fb75e9f
So if you use a cutting edge build (or 2v15 when released), you can now do:
NRF.setServices({ 0xBCDE : { 0xABCD : { value : "Hello", // optional maxLen : 5, // optional (otherwise is length of initial value) readable : true, // optional, default is false notify : true, // optional, default is false onWriteDesc : function(evt) { console.log("Notifications enabled = ", evt.data[0]&1); } } } });
I kept it quite broad as this seems like quite a niche thing, and this way it's more flexible.
https://www.oreilly.com/library/view/getting-started-with/9781491900550/ch04.html says:
A CCCD’s value is nothing more than a two-bit bitfield, with one bit corresponding to notifications and the other to indications
I have a few characteristics that wait for a device to connect and subscribe to the notifications. If the connected device hasn't subscribed to notifications, there is no reason to update the characteristic. As far as I can tell, the only event we can subscribe to currently for characteristics is onWrite, as well as more general BLE connection and security events. Is there currently any way to accomplish this that I have missed? If not, any idea how much effort it would be to implement?