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?
Add a
MessageInterceptor
to theCoapEndpoint
. That will callinterceptor.receiveResponse(response);
before theMatcher
ignores thatResponse
. 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 ininterceptor.sendRequest(Request request);
But with the rest of the processing, your on your own.