Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [leshan-dev] objectID is always 0 in Observe.onResponse

Hi, It seems you try to get the object id, but you actually get the instance ID : LwM2mObjectInstance content = (LwM2mObjectInstance) res.getContent();  // here you get the instance
int objectId = content.getId(); // So here you get the Id of the instance.

If you want to access too object ID, I advice you to use :
      observation.getPath().getObjectId()

HTH.

Simon

Le 13/04/2017 à 12:33, Cobalt F a écrit :
Hi,

I'm trying to set up a custom server based on Leshan-server code.
I want to store some data received from devices into a database. 
Currently I'm using the provided leshan-client-demo as the only client, for testing purpose.

My plan is to listen to observation responses, with an ObservationListener.onResponse handler.

For each of these events, I also need to retrieve the name of each resource to write them accordingly into my database.
For that, I use server.getModelProvider related methods.

Here is a code snippet of my handler:

        private LeshanServer server;
private ObservationListener obsListener = new ObservationListener() {
public void onResponse(Observation obs, Registration reg, ObserveResponse res) {
LwM2mObjectInstance content = (LwM2mObjectInstance) res.getContent();
int objectId = content.getId(); // Here I retrieve the object ID, but it's always 0
LwM2mModel objectModel = server.getModelProvider().getObjectModel(reg);
for (Map.Entry<Integer, LwM2mResource> r : content.getResources().entrySet()) {
int resId = r.getValue().getId(); // This one is okay
ResourceModel model = objectModel.getResourceModel(objectId, resId); // and here I'm trying to use it
if (model != null) {
System.out.println(model.name);
}
}
}
                // Other handlers next...
        }

The issue is to retrieve correctly the object id.
Here my objectId is always 0. So except for the first object, the resource model is null (as I suppose it doesen't match anything).
I don't see any other data in the ObserveResponse.

When I manually set objectId to other values (1, 2, 3, ...8), it works like a charm for the corresponding object.

I think it's not normal. What could be the origin of this bug?
Thanks.

Sincerely,


_______________________________________________
leshan-dev mailing list
leshan-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/leshan-dev


Back to the top