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

Grouping variables using "/" fails with websockets and JSON #384

Closed
JimmyDaSilva opened this issue Jan 11, 2021 · 6 comments
Closed

Grouping variables using "/" fails with websockets and JSON #384

JimmyDaSilva opened this issue Jan 11, 2021 · 6 comments

Comments

@JimmyDaSilva
Copy link

Hi @facontidavide,

I am switching to your new plugin for Websockets communication with JSON.
Works great, except the key names via JSON seem to do not like the "/".
"/" is converted to "~1", so I can't group the variables.

To easily reproduce this, I have slightly modified websocket_client.py by adding a variable named: var/x

#!/usr/bin/python

# https://pypi.org/project/websocket_client/

import websocket
import math
import json
from time import sleep

ws = websocket.WebSocket()
ws.connect("ws://localhost:9871")

time = 0.0

while True:
    sleep(0.05)
    time += 0.05

    data = {
        "timestamp": time,
        "test_data": {
            "cos": math.cos(time),
            "sin": math.sin(time)
        },
        "var/x": 2
    }
    ws.send( json.dumps(data) )

Here is the result:
2021-01-11-screenshot

Is this a bug, or is this a constraint coming from a string encoding?

Grouping variables via JSON object encapsulation works.
Reading a CSV with a slash in the names works too.

I am using the lastest tag 3.0.7

Thanks for version 3, it is amazing!
Jimmy

@JimmyDaSilva
Copy link
Author

To remove one possibility regarding the issue, I made a new function in websocket_server.cpp connected to the WebSocket::binaryMessageReceived signals, and sent directly binary messages (QByteArray) from my c++ Client.
The result is still the same as above.

So I guess the problem comes from the reinterpret_cast here: https://github.com/facontidavide/PlotJuggler/blob/main/plugins/DataStreamWebsocket/websocket_server.cpp#L185

@JimmyDaSilva
Copy link
Author

I checked the cast. It is okay.

Printing data at every step got me to this line:
https://github.com/facontidavide/PlotJuggler/blob/main/src/nlohmann_parsers.cpp#L50

The conversion from / to ~1 happens here, unfortunately.
So I guess we are stuck. Meaning grouping variables when using JSON cannot be done with a forward slash.

@facontidavide
Copy link
Owner

well, what I can do is to reimplement that particular function. I don't expect it to be a big deal

@JimmyDaSilva
Copy link
Author

facontidavide added a commit that referenced this issue Jan 14, 2021
@facontidavide
Copy link
Owner

fixed!

@JimmyDaSilva
Copy link
Author

Wow, that was fast !
Thanks Davide :)

facontidavide added a commit that referenced this issue Feb 28, 2021
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

2 participants