1

我正在为 Shelly 系列设备开发 openHAB2 绑定。http 接口运行良好,但我无法注册以获取 COAP 事件。

有人对 Californium 框架有经验吗?Shelly 使用非标准 Coap 选项(基于其 CoIoT 规范:https ://shelly-api-docs.shelly.cloud/images/CoIoT%20for%20Shelly%20devices%20(rev%201.0)%20.pdf )。

我正在使用 Java Californium 框架。

当我注册观察者时,不会执行回调。如果我发送一个命令,我会在日志中看到 ACK,但它们会报告一个未知选项 3332,Shelly 在他们的文档中对此进行了描述。我没有找到一种方法来向 Californium 框架注册/注入自定义选项,以便观察者可以阅读它们。任何帮助表示赞赏。

    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)");
                    }
                });

我在调试日志中看到的:

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
  • 显然设备正在响应(ip:port,uri)
  • 数据包被解码
  • 数据看起来一般(如规范中所述)
  • 但它显示 "OptionSet={"Unknown (3332)"..."

我不知道如何使用 Californium 注册自定义选项。似乎这些数据包被忽略了,所以应用程序没有得到任何数据。

任何想法?

4

2 回答 2

0

如果您为客户端和服务器提供请求和响应的日志,那就太好了。但是,我看到 ACK 响应不包含令牌(应该与请求中的相同),显然这就是 Californium 无法将其与相应请求匹配的原因。

Californium 应该适用于自定义选项。

在解决响应数学问题后尝试联系他们。应该是这样的:

response.getOptions().getOthers()

该“未知...”消息只是因为 Californium 消息格式化程序不知道如何正确记录它。无论如何,您应该能够从选项中获得它。

于 2019-08-20T12:59:28.420 回答
0

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.

于 2019-08-20T17:54:17.647 回答