-
Notifications
You must be signed in to change notification settings - Fork 554
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
Unable to Parse any WS payload using JSON !! #204
Comments
the library only abstracts the websocket part of the socket.io protocol, the numbers befor the json are part of socket.io. https://github.com/socketio/socket.io-protocol#socketio-protocol JSON basics:
numbers: |
thank you , So , i tested , by sending each column , one at a time , in a 10 frames per second frequency , but it seams too much for the ESP (?) I think i should go with binary instead , of text . Will search if i found some guidance here , if not will open other "help Request" if you don't mind - For " How to work with binary Data frames" |
you can try this branch: sure, each issue is a good help for others too, and shows my what need to be improved on the library. |
before trying other branch, is there a way , to make the server, and client , not to buffer messages ?, just keep the most recent one ? ( similar than an udp type of connection , i guess) . |
no the ws TCP stream need to be interpreted complete, you only know where the next message will be if you have read the header of the last one. |
good, will try that .. other question , i have again the same problem with parsing the message , it is too strange , and debugging is not helping in my example , i get this , where json2 is indicating the message received as payload , but the parser says it can parse it successfully , and no clue why ... [WS][0][handleWebsocket] ------- read massage frame ------- |
i found the problem , the parsing needs to be prepared exactly for the payload you are going to use , and probably , later will go to a more elaborated ( or simpler) protocol for leds ( OPC , tpm2net , artnet ,...) |
I know its really late but i hope its useful..... For ESP8266 WebSocketClientIO #include <ArduinoJson.h> --- use this library --> payload = 42["arduino",{"message":"forward"}] case WStype_TEXT:
|
im looking for an example help that combines web sockets event with the JSON library , i wasn't able to find any working example . ( using the socket.io client )
here is the problem
somehow the payload received by the library function on message , gets more info than the one sent with the original message , this alone wounds be a problem, if there were an easy way to get rid of it , or to access , to the "true" message inside the payload.
for example :
original payload :
"{"msgName":"time","type":3,"message":"18:40:27 GMT+0000 (UTC)"}"
received payload
42["time","{"msgName":"time","type":3,"message":"18:40:27 GMT+0000 (UTC)"}"]
the consequence is that the original Json is not son anymore, so we have to gather the substring of it .
something like
String text = ((char *)&payload[0]);
int pos = text.indexOf('{'); // position of { json object start
String json1 = text.substring(pos,text.length()-2);
and finally apply
JsonObject& root = jsonBuffer.parseObject(json1);
But, parsing fails , even when the string is correctly formatted ,
in fact if i manually define the json as
const char* json1 = "{"msgName":"time","type":3,"message":"22:40:49 GMT+0000 (UTC)"}";
it is parsed ok as expected .
in summary , how to get easy access to the underlaying string that is referenced on the payload ?
The text was updated successfully, but these errors were encountered: