diff --git a/leshan-client-core/src/main/java/org/eclipse/leshan/client/resource/BaseInstanceEnabler.java b/leshan-client-core/src/main/java/org/eclipse/leshan/client/resource/BaseInstanceEnabler.java index ba382b96b8..5d729170b1 100644 --- a/leshan-client-core/src/main/java/org/eclipse/leshan/client/resource/BaseInstanceEnabler.java +++ b/leshan-client-core/src/main/java/org/eclipse/leshan/client/resource/BaseInstanceEnabler.java @@ -184,7 +184,7 @@ public WriteResponse write(ServerIdentity identity, int resourceid, int resource if (instances.containsKey(resourceInstanceId)) { instances.put(resourceInstanceId, value); return write(identity, resourceid, - new LwM2mMultipleResource(resourceInstanceId, value.getType(), instances.values())); + new LwM2mMultipleResource(resourceid, value.getType(), instances.values())); } } } diff --git a/leshan-client-core/src/main/java/org/eclipse/leshan/client/resource/DummyInstanceEnabler.java b/leshan-client-core/src/main/java/org/eclipse/leshan/client/resource/DummyInstanceEnabler.java index 587203bc8d..ff528bf27e 100644 --- a/leshan-client-core/src/main/java/org/eclipse/leshan/client/resource/DummyInstanceEnabler.java +++ b/leshan-client-core/src/main/java/org/eclipse/leshan/client/resource/DummyInstanceEnabler.java @@ -96,6 +96,7 @@ protected LwM2mMultipleResource initializeMultipleResource(ObjectModel objectMod switch (resourceModel.type) { case STRING: values.put(0, createDefaultStringValueFor(objectModel, resourceModel)); + values.put(1, createDefaultStringValueFor(objectModel, resourceModel)); break; case BOOLEAN: values.put(0, createDefaultBooleanValueFor(objectModel, resourceModel)); diff --git a/leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/text/LwM2mNodeTextEncoder.java b/leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/text/LwM2mNodeTextEncoder.java index 1d3d2fd268..44e847abd7 100644 --- a/leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/text/LwM2mNodeTextEncoder.java +++ b/leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/text/LwM2mNodeTextEncoder.java @@ -100,7 +100,7 @@ public void visit(LwM2mResource resource) { public void visit(LwM2mResourceInstance instance) { LOG.trace("Encoding resource instance {} into text", instance); - ResourceModel rSpec = model.getResourceModel(path.getObjectId(), instance.getId()); + ResourceModel rSpec = model.getResourceModel(path.getObjectId(), path.getResourceId()); Type expectedType = rSpec != null ? rSpec.type : instance.getType(); Object val = converter.convertValue(instance.getValue(), instance.getType(), expectedType, path); diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/WriteTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/WriteTest.java index 63b8bea6f1..2146274b4c 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/WriteTest.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/WriteTest.java @@ -202,34 +202,40 @@ private void write_integer_resource(ContentFormat format) throws InterruptedExce @Test public void can_write_string_resource_json_instance() throws InterruptedException { - write_string_resource_instance(ContentFormat.JSON); + write_string_resource_instance(ContentFormat.JSON, 0); } @Test public void can_write_string_resource_old_json_instance() throws InterruptedException { - write_string_resource_instance(ContentFormat.fromCode(ContentFormat.OLD_JSON_CODE)); + write_string_resource_instance(ContentFormat.fromCode(ContentFormat.OLD_JSON_CODE), 0); } @Test public void can_write_string_resource_text_instance() throws InterruptedException { - write_string_resource_instance(ContentFormat.TEXT); + write_string_resource_instance(ContentFormat.TEXT, 0); + } + + @Test + public void can_write_string_multiple_resource_text_instance() throws InterruptedException { + write_string_resource_instance(ContentFormat.TEXT, 0); + write_string_resource_instance(ContentFormat.TEXT, 1); } @Test public void can_write_string_resource_tlv_instance() throws InterruptedException { - write_string_resource_instance(ContentFormat.TLV); + write_string_resource_instance(ContentFormat.TLV, 0); } @Test public void can_write_string_resource_old_tlv_instance() throws InterruptedException { - write_string_resource_instance(ContentFormat.fromCode(ContentFormat.OLD_TLV_CODE)); + write_string_resource_instance(ContentFormat.fromCode(ContentFormat.OLD_TLV_CODE), 0); } - private void write_string_resource_instance(ContentFormat format) throws InterruptedException { + private void write_string_resource_instance(ContentFormat format, int resourceInstance) throws InterruptedException { // read device model number String valueToWrite = "newValue"; WriteResponse response = helper.server.send(helper.getCurrentRegistration(), - new WriteRequest(format, TEST_OBJECT_ID, 0, STRING_RESOURCE_INSTANCE_ID, 0, valueToWrite, Type.STRING)); + new WriteRequest(format, TEST_OBJECT_ID, 0, STRING_RESOURCE_INSTANCE_ID, resourceInstance, valueToWrite, Type.STRING)); // verify result assertEquals(CHANGED, response.getCode()); @@ -238,7 +244,7 @@ private void write_string_resource_instance(ContentFormat format) throws Interru // read resource to check the value changed ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), - new ReadRequest(format, TEST_OBJECT_ID, 0, STRING_RESOURCE_INSTANCE_ID, 0)); + new ReadRequest(format, TEST_OBJECT_ID, 0, STRING_RESOURCE_INSTANCE_ID, resourceInstance)); // verify result LwM2mResourceInstance resource = (LwM2mResourceInstance) readResponse.getContent();