Most recent activity
-
Thanks @Gordon . The connection interval helps immensely! Thank you for directing me to that.
I've just numbered the below so that it's clear they are unrelated to each other!
(1)
I will work through how to add a some good error handling. Currently I think one of the "tasks" got "lost", so any
writeValue()
now fails with:Uncaught Error: Unhandled promise rejection: Error: BLE task 6 is already in progress
(2)
I've held BTN3, launched my app again, but my target BLE device has maintained the connection state, yet my app doesn't know about that. For robustness, maybe I need to store
gatt
in some kind of global that persists outside my app?(3)
In http://www.espruino.com/modules/ble_simple_uart.js -
function sender(resolve, reject) { if (text.length) { c.writeValue(text.substr(0,20)).then(function() { sender(resolve, reject); }).catch(reject); text = text.substr(20); } else { resolve(); } }
Why is it
catch(reject)
, notcatch(reject())
? -
Does https://github.com/gfwilliams/heatshrink-js help for that?
Alternatively, maybe https://github.com/systemmonkey42/node-heatshrink
-
A few related things I've found that I shall investigate
- https://github.com/espruino/Espruino/issues/1867 ( https://github.com/espruino/Espruino/commit/766a577e3f5da127ce4815544a31cb7562dfd96c )
- https://stackoverflow.com/questions/40328932/javascript-es6-promise-for-loop
- https://www.espruino.com/Compilation
I'm wondering if https://github.com/espruino/Espruino/blob/31c67baa20302b80aafc5b355aade9028a37c471/targets/nrf5x/bluetooth.c#L1593 is lacking error checking that the
sd_ble_gattc_write()
was successful, as per https://devzone.nordicsemi.com/f/nordic-q-a/49613/sd_ble_gattc_write-and-ble_gattc_evt_write_rsp - what led me there is trying to follow through how Espruino knows thesd_ble_gattc_write()
has completed, in case I can find a way to then write the next value quicker than currently. It looks like there's actually just one BLE-related promise at a time https://github.com/espruino/Espruino/blob/31c67baa20302b80aafc5b355aade9028a37c471/libs/bluetooth/jswrap_bluetooth.c#L90 , but I've not yet spotted how we get through to https://github.com/espruino/Espruino/blob/31c67baa20302b80aafc5b355aade9028a37c471/libs/bluetooth/jswrap_bluetooth.c#L96 - https://github.com/espruino/Espruino/issues/1867 ( https://github.com/espruino/Espruino/commit/766a577e3f5da127ce4815544a31cb7562dfd96c )
-
I have this so far, for writing as fast as possible to a gatt characteristic. The timing seems to vary though, and certainly the writing isn't 'continuous'. Is there a way to do better? I want to write 10 times per second, as stable as possible.
interval = 100; function writeValue() { return new Promise(function(resolve, reject) { if (!isConnected()) { console.log("not connected"); setTimeout(function() {writeValue().catch(function() {});}, 1000); reject(); return; } char.writeValue(calculateValue()).then(function() { setTimeout(function() {writeValue().catch(function() {});}, interval); resolve(); }).catch(function(e) { console.log(e); setTimeout(function() {writeValue().catch(function() {});}, interval); reject(); }); }); }
I'm most familiar with writing in C or Python, so unfamiliar with Promises. I think I need to use them here, since if I simply call
char.writeValue(calculateValue())
in a loop then often there's an error that BLE is busy (from https://github.com/espruino/Espruino/blob/31c67baa20302b80aafc5b355aade9028a37c471/libs/bluetooth/jswrap_bluetooth.c#L78 )
Oh yes, of course, my lack of JS familiarity forgot that I had this in my mind:
which, I suppose is actually the same thing as