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 ) );
final InetSocketAddress
clientAddress = new InetSocketAddress(
localHostName, localPort );
final InetSocketAddress
serverAddress = new InetSocketAddress(
serverHostName, serverPort );
final LeshanClient client = new
LeshanClient( clientAddress, serverAddress, new
ArrayList<LwM2mObjectEnabler>(
So
I created a new Object an added it in the same way:
public static class MyObject extends
BaseInstanceEnabler {
System.out.println( "create
MyObject" );
public ValueResponse read( final
int resourceid ) {
System.out.println( "Read on
MyObject Resource " + resourceid );
return new ValueResponse(
ResponseCode.CONTENT, new LwM2mResource( resourceid,
Value.newBooleanValue(
getResource0() ) ) );
return new ValueResponse(
ResponseCode.CONTENT, new LwM2mResource( resourceid,
Value.newIntegerValue(
getResource1() ) ) );
return new ValueResponse(
ResponseCode.CONTENT, new LwM2mResource( resourceid,
Value.newStringValue(
getResource2() ) ) );
return new ValueResponse(
ResponseCode.CONTENT, new LwM2mResource( resourceid,
Value.newStringValue(
getResource3() ) ) );
return new ValueResponse(
ResponseCode.CONTENT, new LwM2mResource( resourceid,
Value.newStringValue(
getResource4() ) ) );
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?