johnlauer / serial-port-json-server

A serial port JSON websocket server for Windows, Mac, Linux, Raspberry Pi, or BeagleBone Black that lets you communicate with your serial port from a web application. This enables web apps to be written that can communicate with your local serial device such as an Arduino, CNC controller, or any device that communicates over the serial port.
http://chilipeppr.com
GNU General Public License v2.0
355 stars 174 forks source link

escape character over ws #45

Open mzi1sk opened 8 years ago

mzi1sk commented 8 years ago

If I send this command to json server using websocket I am getting error : err:invalid character '\x1b' in string literal. If I send command using localhost:8989 it works. As for my device is escape character(\x1b ) a must symbol any idea what I do wrong is appreciated.

sendjson {"Data":[{"D":"\u001bb\r\n","ID":"100","Pause":100},{"D":"Nazov Pocet Jedn.Cena Dan Suma \r\n","ID":"101","Pause":100},{"D":"Aglio olio e peperoncino \r\n","ID":"102","Pause":100},{"D":" 1 Ks 7.5 \u001b1 7,50 EUR \r\n","ID":"103","Pause":100},{"D":"Pasta salmone zucchine \r\n","ID":"104","Pause":100},{"D":" 1 Ks 11.0 \u001b1 11,00 EUR \r\n","ID":"105","Pause":100},{"D":"Aglio olio e peperoncino \r\n","ID":"106","Pause":100},{"D":" 1 Ks 7.5 \u001b1 7,50 EUR \r\n","ID":"107","Pause":100},{"D":"Pasta salmone zucchine \r\n","ID":"108","Pause":100},{"D":" 1 Ks 11.0 \u001b1 11,00 EUR \r\n","ID":"109","Pause":100},{"D":"Linguine frutti di mare \r\n","ID":"110","Pause":100},{"D":" 1 Ks 11.0 \u001b1 11,00 EUR \r\n","ID":"111","Pause":100},{"D":"\u001bk 48,00 \r\n","ID":"112","Pause":100},{"D":"\u001bP1 48,00 EUR \r\n","ID":"113","Pause":100},{"D":"\u001be \r\n","ID":"114","Pause":100}],"P":"COM3"}

and here is my simple websocket.js

function senddocument( message) { timeoutID = window.setTimeout(senddocument2ws, 200,message); }

function senddocument2ws( message) { window.socket.send(message); }

function opensocket(address) { window.socket = new WebSocket(address); window.socket.onopen = function() { console.log('open'); } window.socket.onerror=window.socket.onclose = function (errorEvent) { alert("Spojenie s fiskalnou pokladnou je uzavrete!!"); }

window.socket.onmessage = function(msg) {
    console.log('receive');
    console.log(msg);
}

}

function closesocket() {

window.socket.close();

}

Thank you Michal

chilipeppr commented 8 years ago

I'm not really sure what you're asking? You're saying it works from localhost:8989 so there's no error.

On Fri, Feb 26, 2016 at 5:49 AM, mzi1sk notifications@github.com wrote:

If I send this command to json server using websocket I am getting error : err:invalid character '\x1b' in string literal. If I send command using localhost:8989 it works. As for my device is escape character(\x1b ) a must symbol any idea what I do wrong is appreciated.

sendjson {"Data":[{"D":"\u001bb\r\n","ID":"100","Pause":100},{"D":"Nazov Pocet Jedn.Cena Dan Suma \r\n","ID":"101","Pause":100},{"D":"Aglio olio e peperoncino \r\n","ID":"102","Pause":100},{"D":" 1 Ks 7.5 \u001b1 7,50 EUR \r\n","ID":"103","Pause":100},{"D":"Pasta salmone zucchine \r\n","ID":"104","Pause":100},{"D":" 1 Ks 11.0 \u001b1 11,00 EUR \r\n","ID":"105","Pause":100},{"D":"Aglio olio e peperoncino \r\n","ID":"106","Pause":100},{"D":" 1 Ks 7.5 \u001b1 7,50 EUR \r\n","ID":"107","Pause":100},{"D":"Pasta salmone zucchine \r\n","ID":"108","Pause":100},{"D":" 1 Ks 11.0 \u001b1 11,00 EUR \r\n","ID":"109","Pause":100},{"D":"Linguine frutti di mare \r\n","ID":"110","Pause":100},{"D":" 1 Ks 11.0 \u001b1 11,00 EUR \r\n","ID":"111","Pause":100},{"D":"\u001bk 48,00 \r\n","ID":"112","Pause":100},{"D":"\u001bP1 48,00 EUR \r\n","ID":"113","Pause":100},{"D":"\u001be \r\ n","ID":"114","Pause":100}],"P":"COM3"}

and here is my simple websocket.js

function senddocument( message) { timeoutID = window.setTimeout(senddocument2ws, 200,message); }

function senddocument2ws( message) { window.socket.send(message); }

function opensocket(address) { window.socket = new WebSocket(address); window.socket.onopen = function() { console.log('open'); } window.socket.onerror=window.socket.onclose = function (errorEvent) { alert("Spojenie s fiskalnou pokladnou je uzavrete!!"); }

window.socket.onmessage = function(msg) { console.log('receive'); console.log(msg); }

}

function closesocket() {

window.socket.close();

}

Thank you Michal

— Reply to this email directly or view it on GitHub https://github.com/johnlauer/serial-port-json-server/issues/45.

mzi1sk commented 8 years ago

yes exactly. From localhost it runs perfect. If I try to send it over ws, I get :

{"Error" : "Problem decoding json. giving up. json: {"Data":[{"D":"b ","ID":"100","Pause":100},{"D":"Nazov Pocet Jedn.Cena Dan Suma ","ID":"101","Pause":100},{"D":"Aglio olio e peperoncino ","ID":"102","Pause":100},{"D":" 1 Ks 7.5 1 7,50 EUR ","ID":"103","Pause":100},{"D":"Pasta salmone zucchine ","ID":"104","Pause":100},{"D":" 1 Ks 11.0 1 11,00 EUR ","ID":"105","Pause":100},{"D":"Aglio olio e peperoncino ","ID":"106","Pause":100},{"D":" 1 Ks 7.5 1 7,50 EUR ","ID":"107","Pause":100},{"D":"Pasta salmone zucchine ","ID":"108","Pause":100},{"D":" 1 Ks 11.0 1 11,00 EUR ","ID":"109","Pause":100},{"D":"Linguine frutti di mare ","ID":"110","Pause":100},{"D":" 1 Ks 11.0 1 11,00 EUR ","ID":"111","Pause":100},{"D":"k 48,00 ","ID":"112","Pause":100},{"D":"P1 48,00 EUR ","ID":"113","Pause":100},{"D":"e ","ID":"114","Pause":100}],"P":"COM3"} , err:invalid character '\x1b' in string literal"}

chilipeppr commented 8 years ago

This forum is for bugs, not to help you figure out how to write code.

On Fri, Feb 26, 2016 at 8:12 AM, mzi1sk notifications@github.com wrote:

yes exactly. From localhost it runs perfect. If I try to send it over ws, I get :

{"Error" : "Problem decoding json. giving up. json: {"Data":[{"D":"�b ","ID":"100","Pause":100},{"D":"Nazov Pocet Jedn.Cena Dan Suma ","ID":"101","Pause":100},{"D":"Aglio olio e peperoncino ","ID":"102","Pause":100},{"D":" 1 Ks 7.5 �1 7,50 EUR ","ID":"103","Pause":100},{"D":"Pasta salmone zucchine ","ID":"104","Pause":100},{"D":" 1 Ks 11.0 �1 11,00 EUR ","ID":"105","Pause":100},{"D":"Aglio olio e peperoncino ","ID":"106","Pause":100},{"D":" 1 Ks 7.5 �1 7,50 EUR ","ID":"107","Pause":100},{"D":"Pasta salmone zucchine ","ID":"108","Pause":100},{"D":" 1 Ks 11.0 �1 11,00 EUR ","ID":"109","Pause":100},{"D":"Linguine frutti di mare ","ID":"110","Pause":100},{"D":" 1 Ks 11.0 �1 11,00 EUR ","ID":"111","Pause":100},{"D":"�k 48,00 ","ID":"112","Pause":100},{"D":"�P1 48,00 EUR ","ID":"113","Pause":100},{"D":"�e ","ID":"114","Pause":100}],"P":"COM3"} , err:invalid character '\x1b' in string literal"}

— Reply to this email directly or view it on GitHub https://github.com/johnlauer/serial-port-json-server/issues/45#issuecomment-189347977 .

mzi1sk commented 8 years ago

ok isnt it an issue? if I submit json from localhost:8989 and it works, but if I use websocket and send very same json over there it will not work. As I think problem is on json server side. When it receives escape format "\u001b" it converts it to � aka '\x1b' that jsonserver is not able to process ?

Anyway is there any other forum to the project ? Maybe you can consider to set one, as that would really help to avoid your waste of time with us not smart enough to get over some probably stupid mistakes.

johnlauer commented 8 years ago

localhost?:8989 is over Websockets. so if it works there, it works over Websockets. so this is your code.

chilipeppr commented 8 years ago

There's no forum but feel free to set one up. On Feb 26, 2016 8:39 AM, "John Lauer" notifications@github.com wrote:

localhost?:8989 is over Websockets. so if it works there, it works over Websockets. so this is your code.

— Reply to this email directly or view it on GitHub https://github.com/johnlauer/serial-port-json-server/issues/45#issuecomment-189363271 .