简体   繁体   English

如何处理自定义coap选项(非标准)

[英]How to handle custom coap options (non-standard)

I'm working on a openHAB2 binding for the Shelly series of devices. 我正在为Shelly系列设备开发openHAB2绑定。 The http interface is running well, but I can't register to get the COAP events. http界面运行良好,但是我无法注册获取COAP事件。

Does someone has experience with the Californium framework? 有人对Californium框架有经验吗? 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 ). Shelly使用非标准的Coap选项(基于其CoIoT规范: https ://shelly-api-docs.shelly.cloud/images/CoIoT%20for%20Shelly%20devices%20(rev%201.0)%20.pdf)。

I'm using the Java Californium framework. 我正在使用Java Californium框架。

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. 如果我发送命令,我会在日志中看到ACK,但是它们报告了一个未知选项3332,Shelly在其文档中对此进行了描述。 I didn't found a way to register/inject custom options to the Californium framework so the observer can read them. 我没有找到将自定义选项注册/注入到Californium框架的方法,以便观察者可以读取它们。 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) 显然设备正在响应(ip:port,uri)
  • the packet gets decoded 数据包被解码
  • data looks ok in general (as described in the spec) 数据总体上看起来不错(如规范中所述)
  • but it shows "OptionSet={"Unknown (3332)"..." 但显示“ OptionSet = {“未知(3332)” ...“

I have no clue how to register custom options with Californium. 我不知道如何在Californium中注册自定义选项。 It seems that those packets get ignored so the application doesn't get any data. 这些数据包似乎被忽略了,因此应用程序不会获得任何数据。

Any idea? 任何想法?

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. 但是,我看到ACK响应中不包含令牌(应与请求中的令牌相同),显然这就是Californium无法将其与相应请求匹配的原因。

Californium should work well with custom options. for应与自定义选项一起很好地工作。

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. 该“未知...”消息只是因为Californium消息格式化程序不知道如何正确记录它。 You should be able to get it from options anyway. 无论如何,您应该能够从选项中获得它。

Add a MessageInterceptor to the CoapEndpoint . 将一个MessageInterceptor添加到CoapEndpoint That will call interceptor.receiveResponse(response); 那将调用interceptor.receiveResponse(response); before the Matcher ignores that Response . Matcher忽略该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); 如果要实现自己的请求/响应匹配,还可以将传出的请求记录在interceptor.sendRequest(Request request);

But with the rest of the processing, your on your own. 但是,通过其余的处理过程,您可以自行完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM