-
• #3
You could use the
btoa
function to covert before sending down the socket.Also the ws module only supports 127 chars max for a message - that might be an issue for you..
-
• #4
...module says up to 65536 bytes...
-
• #5
It looks to me like that's still one complete message - like you're not sending small chunks, but are just sending one big chunk of wave file.
The Websocket library should handle binary data just fine, but will only notify you when it has received a complete frame of data (I think they all work like this). If that's a relatively big frame it could take a while - it may even run out of memory first.
I guess it's possible that the WebSocket library has some bug when handling frames >127 bytes? It might be worth testing it out with smaller size frames first
You can handle the binary data pretty easily once it's in - the trick is to try not to do any copies if you want to get a reasonable amount of speed out of it. Use
E.toUint8Array()
on the string, and then you can do things likeE.FFT
on it to pull out frequencies if you want to.Were you trying to stream live wave data to it? The connection is usually only 115200 baud and it looks like you're sending 16 bit data, so you'll struggle I think. To have much chance of handling it live you'd be looking at 4ksps, 8 bit, mono I reckon.
-
• #6
Are - right you are...
https://github.com/espruino/EspruinoDocs/blob/master/modules/ws.js#L146
-
• #7
Ah yeah those messages are a little larger they're 6k WAV with the header but I can break it up into 600 byte raw samples I forgot I was doing some conversion on the server!
I'll try smaller message sizes and report back
I've got the ws client implementation working, however my server sends binary messages over a websocket, (RAW PCM Audio frames) Is there any way to handle these in espruino, i'd like to so some visualisations of the data with neopixels eventually.
It seems that a binary message doesn't invoke the on message event. I put logging of on raw in and this is what I get: