如何在乐山的已观察资源上检索更新的内容? [英] How to retrieve updated content on an Observed resource in Leshan?

查看:89
本文介绍了如何在乐山的已观察资源上检索更新的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在使用Leshan定期接收来自设备的日志消息,以进行概念验证。我们发现,观察请求是执行此方法的最佳方法。
暂时,由于我们还没有自定义对象(Wakama客户端尚未准备好),因此当客户端注册时,在服务器端,我观察到LeshanClientExample中Device上的资源15。
这是LeshanServer.java中的观察代码:

Currently I am working on proof of concept using Leshan to recieve log messages from devices on regular basis. We found that Observe request is the best way to go for this approach. So temporarily, since we don't have a custom object yet(Wakama client not ready yet), on the server side when the client registers, I observe resource 15 on Device in LeshanClientExample. Here is the Observe code in LeshanServer.java:

 this.clientRegistry.addListener(new ClientRegistryListener() {
    ....
    @Override
     public void registered(final Client client) {
        // TODO observe the client when it is registered.
        observeResource(client);
      }
      ....

private void observeResource(final Client client){
    ObserveRequest request = new ObserveRequest("/3/0/15");
    LwM2mResponse cResponse = this.send(client, request);
}

接下来,我想捕获每次资源更改时的更改并将其记录在数据库中,然后在

Next I want to capture the change every time there is a change in the resource and record in a database. I see that in

 org.eclipse.leshan.client.californium.impl.ObjectResource 

我得到的内容已更新(在handleGET())。这是从中检索更新的正确位置吗?
我想找出代码库中的哪个位置是corr哪里可以检索更新的内容?
我们将不胜感激。

I get content that was updated (in handleGET()). Is that the correct place to retrieve updates from ? I am trying to find out where in the code base is the correct place to retrieve updated content ? Your help will be highly appreciated.

谢谢

推荐答案

根据另一篇博客文章的建议。
有两种通知观察的方法。

As suggested on another blog post. There is 2 ways to be notified of observation.

// listen all observation via the ObservationRegistry
server.getObservationRegistry().addListener(new ObservationRegistryListener() {
 @Override
 public void newValue(Observation observation, LwM2mNode value) {}

@Override
public void cancelled(Observation observation) {}

@Override
public void newObservation(Observation observation) {}

});


// listen a particular observe request (recently added in master)
ObserveRequest request = new ObserveRequest("/3/0/13");
ObserveResponse response = server.send(client, request, TIMEOUT);
response.getObservation().addListener(new ObservationListener() {
@Override
public void newValue(Observation observation, LwM2mNode value) {}

@Override
public void cancelled(Observation observation) {}

});

这篇关于如何在乐山的已观察资源上检索更新的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆