Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [leshan-dev] LeshanClient howTo add multiple LwM2M Objects

Hello John,

Thanks for the answer.

I've just seen, there is already a similar discussion about multi instance objects....

 

Ingo

 

Von: leshan-dev-bounces@xxxxxxxxxxx [mailto:leshan-dev-bounces@xxxxxxxxxxx] Im Auftrag von J.F. Schloman
Gesendet: Mittwoch, 15. Juli 2015 16:33
An: leshan developer discussions
Betreff: Re: [leshan-dev] LeshanClient howTo add multiple LwM2M Objects

 

Ingo,

 

What you came upon is a current limitation of the Leshan Client that needs to be implemented:  support for initial multiple object instances.  The member instances map in ObjectsInitializer should probably be expanded out to a Map<Integer, Collection<LwM2mInstanceEnabler>> that would then be used in createNodeEnabler to fill the local instances Map.  There then probably needs to be a setInstancesForObject public method created and check conditions added to make sure the use would then comply with the JSON model...

 

Right now I believe the only support for multiple instances are those that allow for those generated via create requests from the server.

 

-John

 

On Mon, Jul 13, 2015 at 6:14 AM, Schaal Ingo (INST/ESY4) <Ingo.Schaal@xxxxxxxxxxxx> wrote:

Hello,

 

I have a question about how to add multiple lwm2m Objects to a Lesahan Client so that the server could read the Object from the Client.

 

In the class ObjectsInitializer the method createNodeEnabler(ObjectModel objectModel) which is called from the mehtod  create(int... objectId) only add a new Objectinstance if the Object ist  specified  as single and not aas multiple.

 

protected ObjectEnabler createNodeEnabler(ObjectModel objectModel) {

        final Map<Integer, LwM2mInstanceEnabler> instances = new HashMap<Integer, LwM2mInstanceEnabler>();

        if (!objectModel.multiple) {

            LwM2mInstanceEnabler newInstance = createInstance(objectModel);

            if (newInstance != null) {

                instances.put(0, newInstance);

                return new ObjectEnabler(objectModel.id, objectModel, instances, getClassFor(objectModel));

            }

        }

        return new ObjectEnabler(objectModel.id, objectModel, instances, getClassFor(objectModel));

    }

       

       

The Example Client adds new Object in this way:

 

        // Initialize object list

      final ObjectsInitializer initializer = new ObjectsInitializer( model );

 

      initializer.setClassForObject( 3, Device.class );

      initializer.setInstanceForObject( 6, locationInstance );

      final List<ObjectEnabler> enablers = initializer.createMandatory();

 

      enablers.addAll( initializer.create( 6 ) );

 

      // Create client

      final InetSocketAddress clientAddress = new InetSocketAddress( localHostName, localPort );

      final InetSocketAddress serverAddress = new InetSocketAddress( serverHostName, serverPort );

 

      final LeshanClient client = new LeshanClient( clientAddress, serverAddress, new ArrayList<LwM2mObjectEnabler>(

         enablers ) );

 

      // Start the client

      client.start();

       

 

So I created a new Object an added it in the same way:

 

 

  public static class MyObject extends BaseInstanceEnabler {

 

      public MyObject() {

         System.out.println( "create MyObject" );

      }

 

      @Override

      public ValueResponse read( final int resourceid ) {

         System.out.println( "Read on MyObject Resource " + resourceid );

         switch( resourceid ) {

            case 0:

               return new ValueResponse( ResponseCode.CONTENT, new LwM2mResource( resourceid,

                  Value.newBooleanValue( getResource0() ) ) );

 

            case 1:

               return new ValueResponse( ResponseCode.CONTENT, new LwM2mResource( resourceid,

                  Value.newIntegerValue( getResource1() ) ) );

                                 

            case 2:

               return new ValueResponse( ResponseCode.CONTENT, new LwM2mResource( resourceid,

                  Value.newStringValue( getResource2() ) ) );

                                 

            case 3:

               return new ValueResponse( ResponseCode.CONTENT, new LwM2mResource( resourceid,

                  Value.newStringValue( getResource3() ) ) );

                                 

            case 4:

               return new ValueResponse( ResponseCode.CONTENT, new LwM2mResource( resourceid,

                  Value.newStringValue( getResource4() ) ) );

 

            default:

               return super.read( resourceid );

         }

      }

 

And in the Clientexample:

 

initializer.setInstanceForObject( 10245, new MyObject());

enablers.addAll( initializer.create( 6 , 10245 ) );

 

Of course I have added the description for this Object in the oma-objects-spec.json.

In the Json the instancetype is described as multiple.

 

A new multiple Object could not be added this way. The Instance could not be added because of

if (!objectModel.multiple) {

...

}

 

How could i add a instances for multiple Objects?

 

Thanks and Regards

 

Ingo

 


_______________________________________________
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