Yes, socket.write expects a string (or does a simple toString on whatever data type you give it). The simplest way around it is to use E.toString(...), for instance:
>E.toString([0,1,2,3,4])
="\x00\x01\x02\x03\x04"
If you did socket.write(E.toString([0,1,2,3,4])) you'd send just the 5 bytes 0..4.
You could use String.fromCharCode(...) which is standard JS, but E.toString is a bit easier and more efficient when dealing with arrays.
Sending floats is a bit more tricky, but you have 2 main options:
Typed Arrays
var a = new Float32Array(1); // one element array
a[0]=564654.24245
xyz.write(E.toString(a.buffer))
DataView
This got added as of 1v92, and it lets you store and read all kinds of data really conveniently:
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Yes,
socket.write
expects a string (or does a simpletoString
on whatever data type you give it). The simplest way around it is to useE.toString(...)
, for instance:If you did
socket.write(E.toString([0,1,2,3,4]))
you'd send just the 5 bytes 0..4.You could use
String.fromCharCode(...)
which is standard JS, butE.toString
is a bit easier and more efficient when dealing with arrays.Sending floats is a bit more tricky, but you have 2 main options:
Typed Arrays
DataView
This got added as of 1v92, and it lets you store and read all kinds of data really conveniently:
http://www.espruino.com/Reference#DataView