How to handle custom coap options (non-standard)

333 views Asked by At

I‘m working on a openHAB2 binding for the Shelly series of devices. The http interface is running well, but I can‘t register to get the COAP events.

Does someone has experience with the Californium framework? Shelly uses non-standard Coap options (based on their CoIoT specification: https://shelly-api-docs.shelly.cloud/images/CoIoT%20for%20Shelly%20devices%20(rev%201.0)%20.pdf).

I'm using the Java Californium framework.

When I register the observer no callback is performed. If I send a command I see ACKs in the log, but they report an unknown option 3332, which Shelly describes in their doc. I didn‘t found a way to register/inject custom options to the Californium framework so the observer can read them. Any help is appreciated.

    CoapClient           client;
    CoapObserveRelation  relation;

    public void start() {
        client = new CoapClient("coap://192.168.1.1:5683/cit/d");
        client.get(new CoapHandler() {
            @Override
            public void onLoad(CoapResponse response) {
                String content = response.getResponseText();
                logger.debug("RESPONSE 3: " + content);
            }

            @Override
            public void onError() {
                logger.warn("FAILED");
            }
        });

        relation = client.observe(
                new CoapHandler() {
                    @Override
                    public void onLoad(CoapResponse response) {
                        String content = response.getResponseText();
                        logger.debug("NOTIFICATION: " + content);
                    }

                    @Override
                    public void onError() {
                        logger.warn("OBSERVING FAILED (press enter to exit)");
                    }
                });

What I see in the debug log:

Aug 19, 2019 4:15:39 PM org.eclipse.californium.core.network.Matcher receiveResponse
INFORMATION: Ignoring unmatchable piggy-backed response from /192.168.6.81:5683: ACK-2.05   MID= 5718, Token=, OptionSet={"Unknown (3332)":0x534853572d3231233535394635352331}, "{"blk":[{"I":0,"D":"Rela".. 420 bytes
  • obviously the device is responding (ip:port, uri)
  • the packet gets decoded
  • data looks ok in general (as described in the spec)
  • but it shows "OptionSet={"Unknown (3332)"..."

I have no clue how to register custom options with Californium. It seems that those packets get ignored so the application doesn't get any data.

Any idea?

2

There are 2 answers

0
Achim Kraus On

Add a MessageInterceptor to the CoapEndpoint. That will call interceptor.receiveResponse(response); before the Matcher ignores that Response. You may throw an exception there to stop the standard processing. If you want to implement you own Request/Response matching, you may also record the outgoing Requests in interceptor.sendRequest(Request request);

But with the rest of the processing, your on your own.

0
eugene-nikolaev On

It would be great if you provide logs for both client and server, for requests and responses. However, I see the ACK response does not include a token (which should be the same as in request), apparently this is why Californium can't match it to a corresponding request.

Californium should work well with custom options.

Try reaching them after you fix the response mathching issue. That's how it is suppossed to be:

response.getOptions().getOthers()

That "Unknown ..." message is just because Californium message formatter does not know how to log it properly. You should be able to get it from options anyway.