Skip to content
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

escape character over ws #45

Open
mzi1sk opened this issue Feb 26, 2016 · 6 comments
Open

escape character over ws #45

mzi1sk opened this issue Feb 26, 2016 · 6 comments

Comments

@mzi1sk
Copy link

mzi1sk commented Feb 26, 2016

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
Copy link
Collaborator

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 [email protected] 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
#45.

@mzi1sk
Copy link
Author

mzi1sk commented Feb 26, 2016

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
Copy link
Collaborator

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 [email protected] 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
#45 (comment)
.

@mzi1sk
Copy link
Author

mzi1sk commented Feb 26, 2016

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
Copy link
Owner

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

@chilipeppr
Copy link
Collaborator

There's no forum but feel free to set one up.
On Feb 26, 2016 8:39 AM, "John Lauer" [email protected] 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
#45 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants