How long does it take to time out? and does it time out if it's not inactive (it's writing every few seconds)?
If it does it repeatedly after some time there may be some issue I have to fix - but realistically the connection will drop at some point, so you need to be able to deal with it in your code.
For writing, you're stuck with converting to bytes really. I believe you can do:
value = new Uint32Array([my_int]).buffer
which will create a 4 element array from a 32 bit int (works with Float32,Float64,Int16,etc as well) - and then you can reconstruct that on the other side.
You could send the integer just as a string, but you're then sending more data than you really need to.
With !g_characteristic I wouldn't have said it was too bad. You could return the promise from connect though, and if you moved the catch outside connect then you could deal with the error there?
Also, if you store the device I think you can check device.gatt.connected to see if the connection has dropped?
Perhaps an option here is for me to provide some module that handles persistent connections?
© Espruino, powered by microcosm.
Report a problem