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

observe property deserialized value (may) not (be) completely consistent #1294

Closed
VigneshVSV opened this issue Jun 13, 2024 · 5 comments · Fixed by #1298
Closed

observe property deserialized value (may) not (be) completely consistent #1294

VigneshVSV opened this issue Jun 13, 2024 · 5 comments · Fixed by #1298

Comments

@VigneshVSV
Copy link

VigneshVSV commented Jun 13, 2024

The observable change events are pushed through HTTP SSE in may case. The following is the property affordance:

"position": {
      "title": "position",
      "description": "current position, write operation does not cause movement but overwrite register value.",
      "type": "number",
      "forms": [
        {
          "href": "https://localhost:8080/linear-stage/position",
          "op": "readproperty",
          "htv:methodName": "GET",
          "contentType": "application/json"
        },
        {
          "href": "https://localhost:8080/linear-stage/position",
          "op": "writeproperty",
          "htv:methodName": "PUT",
          "contentType": "application/json"
        },
        {
          "href": "https://localhost:8080/linear-stage/position/change-event",
          "subprotocol": "sse",
          "op": "observeproperty",
          "htv:methodName": "GET",
          "contentType": "text/plain"
        }
      ],
      "observable": true
    }

Either using text/plain or application/json as contentType , one still only retrieves the entire event object, not the event.data

Web browser gives the following output as expected from the event-stream. Server set header is text/event-stream:

data: 20.36

data: 20.005

data: 19.585

data: 19.07

data: 18.4825

data: 17.83

data: 17.0825

But what I get from node-wot (please ignore the stringification)

movements.tsx:24 Position changed to:
movements.tsx:25 "{\"type\":\"message\",\"data\":\"17.1025\",\"lastEventId\":\"\",\"origin\":\"https://localhost:8080\"}"
movements.tsx:24 Position changed to:
movements.tsx:25 "{\"type\":\"message\",\"data\":\"17.70375\",\"lastEventId\":\"\",\"origin\":\"https://localhost:8080\"}"
movements.tsx:24 Position changed to:
movements.tsx:25 "{\"type\":\"message\",\"data\":\"18.36\",\"lastEventId\":\"\",\"origin\":\"https://localhost:8080\"}"
movements.tsx:24 Position changed to:
movements.tsx:25 "{\"type\":\"message\",\"data\":\"18.96375\",\"lastEventId\":\"\",\"origin\":\"https://localhost:8080\"}"
movements.tsx:24 Position changed to:
movements.tsx:25 "{\"type\":\"message\",\"data\":\"19.48375\",\"lastEventId\":\"\",\"origin\":\"https://localhost:8080\"}"
movements.tsx:24 Position changed to:
movements.tsx:25 "{\"type\":\"message\",\"data\":\"19.92625\",\"lastEventId\":\"\",\"origin\":\"https://localhost:8080\"}"
movements.tsx:24 Position changed to:
movements.tsx:25 "{\"type\":\"message\",\"data\":\"20.3\",\"lastEventId\":\"\",\"origin\":\"https://localhost:8080\"}"
movements.tsx:24 Position changed to:
movements.tsx:25 "{\"type\":\"message\",\"data\":\"20.59\",\"lastEventId\":\"\",\"origin\":\"https://localhost:8080\"}"
movements.tsx:24 Position changed to:
movements.tsx:25 "{\"type\":\"message\",\"data\":\"20.7825\",\"lastEventId\":\"\",\"origin\":\"https://localhost:8080\"}"
movements.tsx:24 Position changed to:
movements.tsx:25 "{\"type\":\"message\",\"data\":\"20.915\",\"lastEventId\":\"\",\"origin\":\"https://localhost:8080\"}"
movements.tsx:24 Position changed to:
movements.tsx:25 "{\"type\":\"message\",\"data\":\"20.9925\",\"lastEventId\":\"\",\"origin\":\"https://localhost:8080\"}"
movements.tsx:24 Position changed to:
movements.tsx:25 "{\"type\":\"message\",\"data\":\"21.0\",\"lastEventId\":\"\",\"origin\":\"https://localhost:8080\"}"

client side code is like this:

const updatePosition = async (data) => {
      try {
          data.ignoreValidation = true 
          console.log("Position changed to:") 
          console.log(JSON.stringify(await data.value()))
      } catch (error) {
          console.error("Cannot read the observed property position");
          console.error(error);
      }
}

const subscribe = async() => {
      await motor.observeProperty('position', updatePosition) // motor is the node-wot client
      console.log("subscribed to motor position")
} 

setting ignoreValidation to false causes schema error as well

Position changed to:
movements.tsx:26 Cannot read the observed property position
Error: Invalid value according to DataSchema
    at InteractionOutput.<anonymous> (wot-bundle.min.js:69486:23)

I think the schema error is one reason why the event.data object must be returned instead of the event object itself.

@VigneshVSV
Copy link
Author

Please ignore my JSON.stringify. I think that was an error from my side, but the general point might be correct.

@danielpeintner
Copy link
Member

IF the object is returned (compared to the actual event data) it clarifies also why DataSchema validation fails.
Anyhow, I will not have time to look into it the next 2 weeks.

@VigneshVSV
Copy link
Author

No hurry, the data is still accessible.

@danielpeintner
Copy link
Member

Can you share your file movements.tsx with us?
I assume you call emitPropertyChange() right? I would like to see how this is done...

Thanks!

@VigneshVSV
Copy link
Author

VigneshVSV commented Jul 2, 2024

The data is sent from my backend in python, not node-wot server side. I mainly use node-wot as a client. The payload is a simple number in this case.

Is this what you wanted to know? The file is here anyway : https://gitlab.com/node-clients/phymotion-controllers-app/-/blob/main/src/components/movements.tsx?ref_type=heads

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

Successfully merging a pull request may close this issue.

2 participants