• Hi,

    It's not out of the question but I think it's probably a bit early to assume it's an error in the interpreter source code.

    You may be hitting issues with the connection interval. Espruino negotiates how fast it'll talk with another device, and it may end up (especially for the first few seconds) having only a few intervals a second (so not enough for 10Hz).

    When you connect to a device, you can set the connection interval you want as an option - see http://www.espruino.com/Reference#l_Blue­toothRemoteGATTServer_connect - and setting that to something far below 100ms should really help.

    The code you have won't manage 10Hz because it's running the next step 100ms after the write completes, and the write definitely won't be instantaneous.

    Once you've got a high enough connection interval, something like this should be possible:

    setInterval(function() {
    }, 100);

    But you're right, writeValue may cause an exception if the data hasn't been sent yet (eg it fails first and has to retry).

    In that case it should be possible to do something like this:

    var promise = Promise.resolve();
    setInterval(function() {
       if (!isConnected()) { // if not connected, remove previous promises
        promise = Promise.resolve();
      promise = promise.then(() => char.writeValue(calculateValue()));
    }, 100);

    So now the next send is always queued up behind the last, even if the last hasn't completed. Obviously you might want some checking here because if you end up with a low connection interval, the chain of promises will just keep getting longer until you run out of memory!

    If you want to push output as fast as possible you could also see what I do for the UART code: http://www.espruino.com/modules/ble_simp­le_uart.js


Avatar for Gordon @Gordon started