Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Interaction not shown in serialized TD #81

Closed
nsorin opened this issue Mar 1, 2018 · 4 comments
Closed

Interaction not shown in serialized TD #81

nsorin opened this issue Mar 1, 2018 · 4 comments

Comments

@nsorin
Copy link

nsorin commented Mar 1, 2018

Hello,

I created a test thing using the API to get acquainted with it, and ran an HTTP server to view my thing in the browser. The code of my index.js file is shown below:

const node_wot = require('./node-wot/packages/core');
const HttpServer = require('./node-wot/packages/binding-http').default;

const srv =  new node_wot.Servient();
srv.addServer(new HttpServer());
srv.start().then(wot => {
    let testThing = wot.produce({name: "TestThing"});
    testThing.addProperty({
        name: "Size",
        type: "number",
        value: 10,
        writable: true,
        readable: true
    }).addProperty({
        name: "IsOn",
        type: "boolean",
        value: false,
        readable: true
    }).addAction({
        name: "TurnOn"
    }).addAction({
        name: "TurnOff"
    });
});

This is inspired by the examples availables in the repo. My thing normally has 2 properties: Size (number) and IsOn (boolean), and 2 actions TurnOn and TurnOff.

However, when I run my index using node index.js, then go to the root of my TestThing to get the serialized JSON TD at http://localhost:8080/TestThing I get the output:

"{"@context":["http://w3c.github.io/wot/w3c-wot-td-context.jsonld"],"name":"TestThing","@type":["Thing"],"interaction":[]}"

As you can see, there are no interactions listed in the TD. But if I go directly to an interaction using the URI, for instance http://localhost:8080/TestThing/properties/Size, I get the expected result:

10

So my interactions seem to be added to the thing, but the serialized TD does not show them. Did I miss something there or is there a bug in TD serialization?

Thank you for your help. If you need more information about the test case, I will be happy to provide them.

Additional information

  • I am using the current version of the master branch (I pulled it right before posting this issue to make sure it was up to date).
  • node --version gives me v6.9.1 as output.
  • I am running Windows 10 Home 64bits (I don't think this is relevant, but just in case).
  • npm run test at the root of the repository does not show any error so my build seems to be working properly.

Here are the complete logs of my servient:

$ node index.js
HttpServer starting on port 8080
WoTImpl creating new ExposedThing 'TestThing'
ConsumedThing 'TestThing' created
Servient adding TDResourceListener '/TestThing'
HttpServer on port 8080 adding resource '/TestThing'
ExposedThing 'TestThing' adding Property 'Size'
Servient adding PropertyResourceListener '/TestThing/properties/Size'
HttpServer on port 8080 adding resource '/TestThing/properties/Size'
serializeTD() produced

{"@context":["http://w3c.github.io/wot/w3c-wot-td-context.jsonld"],"name":"TestThing","@type":["Thing"],"interaction":[]}

ExposedThing 'TestThing' adding Property 'IsOn'
Servient adding PropertyResourceListener '/TestThing/properties/IsOn'
HttpServer on port 8080 adding resource '/TestThing/properties/IsOn'
serializeTD() produced

{"@context":["http://w3c.github.io/wot/w3c-wot-td-context.jsonld"],"name":"TestThing","@type":["Thing"],"interaction":[]}

ExposedThing 'TestThing' adding Action 'TurnOn'
Servient adding ActionResourceListener '/TestThing/actions/TurnOn'
HttpServer on port 8080 adding resource '/TestThing/actions/TurnOn'
serializeTD() produced

{"@context":["http://w3c.github.io/wot/w3c-wot-td-context.jsonld"],"name":"TestThing","@type":["Thing"],"interaction":[]}

ExposedThing 'TestThing' adding Action 'TurnOff'
Servient adding ActionResourceListener '/TestThing/actions/TurnOff'
HttpServer on port 8080 adding resource '/TestThing/actions/TurnOff'
serializeTD() produced

{"@context":["http://w3c.github.io/wot/w3c-wot-td-context.jsonld"],"name":"TestThing","@type":["Thing"],"interaction":[]}

HttpServer on port 8080 received GET /TestThing from ::1 port 51319
serializeTD() produced

{"@context":["http://w3c.github.io/wot/w3c-wot-td-context.jsonld"],"name":"TestThing","@type":["Thing"],"interaction":[]}

ContentSerdes serializing to application/json
JsonCodec serializing {"@context":["http://w3c.github.io/wot/w3c-wot-td-context.jsonld"],"name":"TestThing","@type":["Thing"],"interaction":[]}
HttpServer replied with 200 to ::1 port 51319
HttpServer sent Content-Type: 'application/json'
HttpServer on port 8080 received GET /TestThing from ::1 port 51323
serializeTD() produced

{"@context":["http://w3c.github.io/wot/w3c-wot-td-context.jsonld"],"name":"TestThing","@type":["Thing"],"interaction":[]}

ContentSerdes serializing to application/json
JsonCodec serializing {"@context":["http://w3c.github.io/wot/w3c-wot-td-context.jsonld"],"name":"TestThing","@type":["Thing"],"interaction":[]}
HttpServer replied with 200 to ::1 port 51323
HttpServer sent Content-Type: 'application/json'
HttpServer on port 8080 received GET /TestThing from ::1 port 51393
serializeTD() produced

{"@context":["http://w3c.github.io/wot/w3c-wot-td-context.jsonld"],"name":"TestThing","@type":["Thing"],"interaction":[]}

ContentSerdes serializing to application/json
JsonCodec serializing {"@context":["http://w3c.github.io/wot/w3c-wot-td-context.jsonld"],"name":"TestThing","@type":["Thing"],"interaction":[]}
HttpServer replied with 200 to ::1 port 51393
HttpServer sent Content-Type: 'application/json'
HttpServer on port 8080 received GET /TestThing/properties/Size from ::1 port 51393
ContentSerdes serializing to application/json
JsonCodec serializing 10
HttpServer replied with 200 to ::1 port 51393
HttpServer sent Content-Type: 'application/json'

@mkovatsc
Copy link
Contributor

mkovatsc commented Mar 3, 2018

@danielpeintner The whole architecture is unfortunately a bit messed up, as there is mix of using the software object and using the TD representation: ConsumedThing delegated to its .td member, while ExposedThing of course needs actual members representing the interactions and other stuff.

I think the whole idea of ExposedThing extending ConsumedThing is just introducing confusion unless the software object is really a common base. I guess this can get better in the next iteration (see w3c/wot-scripting-api#96)

I guess for now, we just go for a hotfix..

@sebastiankb
Copy link
Contributor

I just pulled the latest version of node-wot and the bug seems to be still in there...

@mkovatsc
Copy link
Contributor

mkovatsc commented Mar 17, 2018

Not sure what version you are using.

08d7599 fixed the missing interactions:

{"@context":["https://w3c.github.io/wot/w3c-wot-td-context.jsonld"],"@type":["Thing"],"name":"counter","security":{"description":"node-wot development Servient, no security"},"interaction":[{"name":"count","@type":["Property"],"schema":{"type":"number"},"observable":true,"form":[{"href":"http://31.133.145.227:8080/counter/properties/count","mediaType":"application/json"},{"href":"http://192.168.56.1:8080/counter/properties/count","mediaType":"application/json"}]},{"name":"increment","@type":["Action"],"form":[{"href":"http://31.133.145.227:8080/counter/actions/increment","mediaType":"application/json"},{"href":"http://192.168.56.1:8080/counter/actions/increment","mediaType":"application/json"}]},{"name":"decrement","@type":["Action"],"form":[{"href":"http://31.133.145.227:8080/counter/actions/decrement","mediaType":"application/json"},{"href":"http://192.168.56.1:8080/counter/actions/decrement","mediaType":"application/json"}]},{"name":"reset","@type":["Action"],"form":[{"href":"http://31.133.145.227:8080/counter/actions/reset","mediaType":"application/json"},{"href":"http://192.168.56.1:8080/counter/actions/reset","mediaType":"application/json"}]}]}

@sebastiankb
Copy link
Contributor

It turned out that the sample above has some non valid (e.g., type) or missing TD elements (e.g., observable) in the properties.

Rewrtiting the sample above to:

const node_wot = require('../../packages/core');
const HttpServer = require('../../packages/binding-http').default;

const srv =  new node_wot.Servient();
srv.addServer(new HttpServer());
srv.start().then(wot => {
    let testThing = wot.produce({name: "TestThing"});
    testThing.addProperty({
        name: "Size",
        schema : '{ "type": "number"}',
        value: 10,
        writable: true,
        observable: true

    }).addProperty({
        name: "IsOn",
        schema : '{ "type": "boolean"}',
        value: false,
        writable: true,
        observable: true
    }).addAction({
        name: "TurnOn"
    }).addAction({
        name: "TurnOff"
    });

});

The expected TD with interaction is generated:

{
    "@context": ["https://w3c.github.io/wot/w3c-wot-td-context.jsonld"],
    "@type": ["Thing"],
    "name": "TestThing",
    "security": {"description": "node-wot development Servient, no security"},
    "interaction": [
        {
            "name": "Size",
            "@type": ["Property"],
            "schema": {"type": "number"},
            "writable": true,
            "observable": true,
            "form": [{
                "href": "http://192.168.2.76:8080/TestThing/properties/Size",
                "mediaType": "application/json"
            }]
        },
        {
            "name": "IsOn",
            "@type": ["Property"],
            "schema": {"type": "boolean"},
            "writable": true,
            "observable": true,
            "form": [{
                "href": "http://192.168.2.76:8080/TestThing/properties/IsOn",
                "mediaType": "application/json"
            }]
        },
        {
            "name": "TurnOn",
            "@type": ["Action"],
            "form": [{
                "href": "http://192.168.2.76:8080/TestThing/actions/TurnOn",
                "mediaType": "application/json"
            }]
        },
        {
            "name": "TurnOff",
            "@type": ["Action"],
            "form": [{
                "href": "http://192.168.2.76:8080/TestThing/actions/TurnOff",
                "mediaType": "application/json"
            }]
        }
    ]
}

However, another problem occurs: The generated TD contains also the security field (why?) which is also not valid regarding TD specification (must be in array style).

I will close this issue an reopen another one that points out this new problem.

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

No branches or pull requests

3 participants