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

CoAP example hangs after first GET #724

Closed
danielpeintner opened this issue Mar 29, 2022 · 9 comments · Fixed by #744
Closed

CoAP example hangs after first GET #724

danielpeintner opened this issue Mar 29, 2022 · 9 comments · Fixed by #744
Labels
binding-coap Issues related to coap protocol binding bug Something isn't working examples Issues related examples in the repository

Comments

@danielpeintner
Copy link
Member

see #721 (comment)


Maybe I was not very clear... it hangs from the beginning on after the first GET.. NO result is reported.

Note1: I did try locally and then it reports values. It seems it has to do again with reaching out to the web again.
Note2: The PR #720 is integrated. So this is not the issue. Maybe the Eclipse vserver?
Note3: Attached the test-file I am using.

// example-client.js
Servient = require("@node-wot/core").Servient;
CoapClientFactory = require("@node-wot/binding-coap").CoapClientFactory;

Helpers = require("@node-wot/core").Helpers;

// create Servient and add CoAP binding
let servient = new Servient();
servient.addClientFactory(new CoapClientFactory(null));

let wotHelper = new Helpers(servient);
wotHelper
    .fetch("coap://plugfest.thingweb.io:5683/testthing") // coap://localhost:5683/testthing
    .then(async (td) => {
        // using await for serial execution (note 'async' in then() of fetch())
        try {
            const WoT = await servient.start();
            const thing = await WoT.consume(td);

            // read property
            const read1 = await thing.readProperty("string");
            console.log("string value is: ", await read1.value());
        } catch (err) {
            console.error("Script error:", err);
        }
    })
    .catch((err) => {
        console.error("Fetch error:", err);
    });
@danielpeintner danielpeintner added binding-coap Issues related to coap protocol binding examples Issues related examples in the repository labels Mar 29, 2022
@relu91 relu91 added the bug Something isn't working label Mar 29, 2022
@relu91
Copy link
Member

relu91 commented Mar 29, 2022

might it be related to this: #71 ?

@danielpeintner
Copy link
Member Author

might it be related to this: #71 ?

Mhh, not sure, .. coapjs/node-coap#204 has been merged by now.,,

@JKRhb
Copy link
Member

JKRhb commented Apr 3, 2022

We just identified and fixed a problem that was related to the observe parameter in node-coap (see coapjs/node-coap#330) that should actually also fix this issue :) I already made sure that removing the observe parameter from the request options lets the client determinate. After the PR above has been merged and a new version of node-coap has been released, we should check again – we might able to close this issue then.

@danielpeintner
Copy link
Member Author

to me #741 seems related...

@danielpeintner
Copy link
Member Author

danielpeintner commented Apr 26, 2022

I tried after #744

1st Test - Web

wotHelper.fetch("coap://localhost:5683/testthing")

It still hangs when reaching out to the web?
Mhh, not sure whether the issue is in the Eclipse vserver.

2nd Test - Local

wotHelper.fetch("coap://localhost:5683/testthing")

succeeds if an instance is running locally 👍

Note: However the same "hanging" happens if one does not start any server coap instance locally. I would have said it should timeout after a while but that does not happen..
It just waits forever... I don't think this is expected.. @relu91 @JKRhb

@JKRhb
Copy link
Member

JKRhb commented Apr 26, 2022

1st Test - Web

Are you using the code form above (with coap://plugfest.thingweb.io:5683/testthing) here? Hmm, in my case, the test actually works:

[core/helpers] Helpers found scheme 'coap'
[core/servient] Servient creating client for scheme 'coap'
[binding-coap] CoapClientFactory creating client for 'coap'
[core/helpers] WoTImpl fetching TD from 'coap://plugfest.thingweb.io:5683/testthing' with [CoapClient]
[binding-coap] CoapClient got Form 'contentType' application/td+json
[binding-coap] CoapClient sending GET to coap://plugfest.thingweb.io:5683/testthing
[binding-coap] CoapClient received 2.05 from coap://plugfest.thingweb.io:5683/testthing
[binding-coap] CoapClient received Content-Format: undefined
[td-tools/td-parser] parseTD() parsing
[...]
[core/wot-impl] WoTImpl consuming TD 'urn:uuid:0a6dad67-fe3d-4554-8366-c15312dc352a' to instantiate ConsumedThing 'TestThing'
[core/helpers] Helpers found scheme 'http'
[core/helpers] Helpers found scheme 'coap'
[core/consumed-thing] ConsumedThing 'TestThing' has no client in cache (-1)
[core/servient] Servient checking for 'http' scheme in 1 ClientFactories
[core/servient] Servient checking for 'coap' scheme in 1 ClientFactories
[core/servient] Servient creating client for scheme 'coap'
[binding-coap] CoapClientFactory creating client for 'coap'
[core/consumed-thing] ConsumedThing 'TestThing' got new client for 'coap'
[core/consumed-thing] ConsumedThing 'TestThing' setting credentials for [CoapClient] based on thing security
[core/servient] Servient looking up credentials for 'urn:uuid:0a6dad67-fe3d-4554-8366-c15312dc352a' (@deprecated)
[core/consumed-thing] ConsumedThing 'TestThing' reading coap://plugfest.thingweb.io:5683/testthing/properties/string
[binding-coap] CoapClient got Form 'contentType' application/json
[binding-coap] CoapClient sending GET to coap://plugfest.thingweb.io:5683/testthing/properties/string
[binding-coap] CoapClient received 2.05 from coap://plugfest.thingweb.io:5683/testthing/properties/string
[binding-coap] CoapClient received Content-Format: application/json
[core/content-serdes] ContentSerdes deserializing from application/json
string value is:  hello

(I added the line await thing.writeProperty("string", "hello"); to the example).

@danielpeintner
Copy link
Member Author

1st Test - Web

Are you using the code form above (with coap://plugfest.thingweb.io:5683/testthing) here? Hmm, in my case, the test actually works.

Yes, it just hangs. Maybe it depends on my business network setting!?
Can someone else try?

BTW, what happens locally if there is no CoAP server running in your case?

@JKRhb
Copy link
Member

JKRhb commented Apr 26, 2022

Yes, it just hangs. Maybe it depends on my business network setting!?

Oh, that sounds plausible!

BTW, what happens locally if there is no CoAP server running in your case?

With the server not started, the example stops during the fetch operation, timing out after the default CoAP timeout span:

[core/helpers] Helpers found scheme 'coap'
[core/servient] Servient creating client for scheme 'coap'
[binding-coap] CoapClientFactory creating client for 'coap'
[core/helpers] WoTImpl fetching TD from 'coap://localhost:5683/testthing' with [CoapClient]
[binding-coap] CoapClient got Form 'contentType' application/td+json
[binding-coap] CoapClient sending GET to coap://localhost:5683/testthing
Fetch error: RetrySendError: No reply in 247 seconds.
    at Timeout.<anonymous> (.../thingweb.node-wot/node_modules/coap/dist/lib/retry_send.js:56:25)
    at listOnTimeout (node:internal/timers:556:17)
    at processTimers (node:internal/timers:499:7) {
  retransmitTimeout: 247
}

@danielpeintner
Copy link
Member Author

Interesting!
I did not know that the timeout is more than 4 minutes 🙃

Both tests fail in my case after the timeout.
Hence, the web test seems to be an issue on my system/network setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binding-coap Issues related to coap protocol binding bug Something isn't working examples Issues related examples in the repository
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants