-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sending binary frames? #14
Comments
Well I think Unicode is natively supported but I have not tried. You could
|
I tried on the test code (thanks to @johnlauer) , websocket.send('sendjson {"Cmd":"Write", "P":"/dev/ttyUSB1","Data": [{"D": "\x31"}]}') it is successful. But below code produced an parse error, websocket.send('sendjson {"Cmd":"Write", "P":"/dev/ttyUSB1","Data": [{"D": "\x01"}]}')
// OR
websocket.send('sendjson {"Cmd":"Write", "P":"/dev/ttyUSB1","Data": [{"D": "\u0001"}]}') I receive this response/error message, RESPONSE: {"Error" : "Problem decoding json. giving up.
json: {"Cmd":"Write", "P":"/dev/ttyUSB1","Data":[{"D": "�"}]},
err:invalid character '\x01' in string literal"} And also, when the serial port data arrives, there are also problems with this. For example real sended values are When hex value is greater than
As @stickystyle implies, it is missing for ASCII control characters. But I do not know where to start and the size of the job. Thank you for your effort in this excellent work @chilipeppr etc. |
Because you are sending the cmd as JSON, when its parsed on the server side, its going to try and parse it as utf8 which corrupts the data. JSON is a text format. Something like this will need to be added:
In this way, the binary data encoded as base64 will survive the utf8/json decoding unaffected, and then the server knows the payload needs to be further base64 decoded and sent to the serial port |
In fact you will have this problem in general over WebSockets as they will be sent and encoded/decoded as utf8. So even the normal send command won't work. The server should support base64 encoded data, and send it on as-is. Something like this:
|
Working on this right now.... |
Alright. Got it working for the SendJson case. |
Hmm, there is ambiguity in the send case, I'd have to clean up the code, and decide on how to specify "base64" encoding as different choices would make the literal string 'base64' difficult to send to a client if that is truly the value you want to send, and the data really isn't encoded. I will clean up the patch and get a pr in. |
sendjson working and PR #31 available |
Ugh, the problem of receiving binary data still exists. Hmm, how to handle? |
I realize this is called 'serial-port-json-server', but is there any way to send binary data through the websocket? I see the methods for sending files that exist on a filesystem for the arduino firmwares, but what about adhoc data?
My use case is that the barcode scanner that I'm interfacing with requires sending ACSII control characters back to it, like 0x1B 0x37 0x2C (ESC 7 ,). Is there a way to do this that I'm perhaps missing?
The text was updated successfully, but these errors were encountered: