I've been playing around with BLE with Espruino Puck, and it's been quite pleasant so far. I've got a question and I can't find the answer- which means it's probably staring me in the face.
I'm experimenting/learning and used NRF.setServices to create a characteristic and I can read the value from it using Nordic nRF connect on my phone. I can also use NRF.updateServices to update the value, and if I use notify the value automatically updates on the phone screen. Yay: Bluetooth success!
My question: Suppose (hypothetically) I turned the puck into a BLE thermometer. This might be used really infrequently, so I don't want to use setInterval with updateServices as this would keep taking temperature readings which were never used, and use more power than necessary.
I only want to do the temperature reading (or whatever power hungry thing) when the data is requested by the phone.
I want something like an 'onRead' function for the characteristic, much as there is onWrite. So my code would be something like
I can't find out how to do such a thing. Is this possible or is it a limitation of BLE/The Nordic SDK? (I can imagine some sort of timing restriction in BLE or something - what if my function took a long time to execute.).
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hello,
I've been playing around with BLE with Espruino Puck, and it's been quite pleasant so far. I've got a question and I can't find the answer- which means it's probably staring me in the face.
I'm experimenting/learning and used NRF.setServices to create a characteristic and I can read the value from it using Nordic nRF connect on my phone. I can also use NRF.updateServices to update the value, and if I use notify the value automatically updates on the phone screen. Yay: Bluetooth success!
My question: Suppose (hypothetically) I turned the puck into a BLE thermometer. This might be used really infrequently, so I don't want to use setInterval with updateServices as this would keep taking temperature readings which were never used, and use more power than necessary.
I only want to do the temperature reading (or whatever power hungry thing) when the data is requested by the phone.
I want something like an 'onRead' function for the characteristic, much as there is onWrite. So my code would be something like
onRead : function() { return doReallyPowerHungryThingThatReturnsAValue() }
I can't find out how to do such a thing. Is this possible or is it a limitation of BLE/The Nordic SDK? (I can imagine some sort of timing restriction in BLE or something - what if my function took a long time to execute.).
I'm grateful for any teachings!
Thanks,
Colin