• How much data are you looking at sending? If you don't mind a bit of (short-term) memory overhead you can do:

    // to hex
    // from hex

    This should be reasonably fast, but it'll allocate an array so for anything over a few hundred bytes it could cause problems.

    String append is actually pretty fast & efficient in Espruino, so using your idea with a few of the hacks from above you might find this is better:

    // from hex
    for (var x of data)msg+=(256+x.charCodeAt()).toString(­16).substr(-2);
    // to hex
    var l = recvData[1]*2;
    var s="";
    for (var i=0;i<l;i+=2) s+=String.fromCharCode(data.substr(i,2))­;

    It might be that you can configure the module to output data in binary though? That might be an easier way of working.


Avatar for Gordon @Gordon started