user134932
Member since Oct 2021 • Last active Oct 2022Most recent activity
-
This approach could work. Thanks. The puck may be accumulating events when not connected to the central and if there is nothing queued up in the Puck then I turn off the Puck's radio. When there is something, the Puck will start advertising, central will connect and write causing the Puck to batch up what's in the queue and notify central. Central writes, and if nothing left in queue, Puck goes to sleep again.
-
In Espruino on a Puck.js, I want to implement a BLE application that works as follows:
- Puck.js running as BLE peripheral
- Central, an iOS app, is not connected to Puck yet
- Puck button presses add a value to a FIFO queue in the Puck
- Central connects to Puck
- Each time the central reads from the characteristic, the next queue entry is read
- When there are no more queue entries, the characteristic returns a "no more entries" value such as an EoF
I have not found an onRead event in the NRF.setServices properties (like the onWrite that is available) or any event in Espruino that I can use to implement the above logic. Am I missing something in the docs that might allow this? Is there an approach I can use with Espruino? I could write to the characteristic to remove the queue entry in the Puck but I'd like to avoid doing this. I'm not looking for a workaround, just a method of knowing, in the Espruino code, when a characteristic is being or was read.
Edit 1: I understand that the Nordic SoftDevice does not provide an API to check if a characteristic has been read but there is a security event that I can watch so am wondering if I set up the characteristic in such a way that I'll get a security event on every read. I've tried the combinations supported according to the Espruino hardware reference but still luck on getting the security event on read to fire.
Thanks
Larry
- Puck.js running as BLE peripheral
-
-
I think so, if I could require authorization on every read then I could use this to know if a read is happening. Not sure how to configure security in Espruino to make this happen and if I would receive an NRF.on('security' event - that was the hope.
Edit: I don't see a JS event being fired for BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST in https://github.com/espruino/Espruino/blob/master/targets/nrf5x/bluetooth.c around line 1355 but I'm not that familiar with the Espruino source.