Skip to content

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

@VigneshVSV

Description

@VigneshVSV

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions