• 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(f­unction() {
                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/blo­b/31c67baa20302b80aafc5b355aade9028a37c4­71/libs/bluetooth/jswrap_bluetooth.c#L78­ )

About

Avatar for John @John started