Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[leshan-dev] Observing a reource on a device on registration is not working.

Hi,
I want to observe a resource on a device. I have implemented it such that when a client registers with the server it starts observing that resource. I updated code in LeshanServer.java as follows :

     // Cancel observations on client unregistering
        this.clientRegistry.addListener(new ClientRegistryListener() {
            @Override
            public void updated(final Client clientUpdated) {
            }
            @Override
            public void unregistered(final Client client) {
                SandCLeshanServer.this.observationRegistry.cancelObservations(client);
            }
            @Override
            public void registered(final Client client) {
                observeResource(client);
            }
        }); 

    private void observeResource(final Client client){
        ObserveRequest request = new ObserveRequest("/500/10/0");
        ObserveResponse cResponse = this.send(client, request);
        LOG.debug("cResponse : " + cResponse);
        cResponse.getObservation().addListener(new ObservationListener() {
            @Override
            public void cancelled(Observation observation) {
                LOG.debug("Observation Cancelled ....");
            }
            @Override
            public void newValue(Observation observation, LwM2mNode value) {
                writeToFile(observation, value);
            }
        });
    }

I updated the oma-objects-spec.json file and the device too has a resource with that id.

This all works fine with ClientExample. But now that the actual device is ready to talk to the server, I am not able to observe the resource.

I see this in the logs :
cResponse : ObserveResponse [code=NOT_FOUND, errormessage=]

I have used wireshark to find out what is going on with the request. My guess is that, the client is waiting for an ACK from the server that it has been registered. But before it gets this ACK it gets an ObserveRequest instead. And does not accept the ObserveRequest. Is that correct ?

If that is the case, which would be a good place to start observing a resource on a device after the client has registered?

Thanks

Back to the top