Skip to content

Commit f579401

Browse files
committed
java/iot3examples: define multiple Lwm2mIoT3ServiceEndpoint instances on client side for now
Ideally, they should be created automatically on the fly according to the number of endpoints defined server-side, but I haven't found how to achieve this yet... Signed-off-by: Mathieu LEFEBVRE <mathieu1.lefebvre@orange.com>
1 parent 594f5ca commit f579401

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

java/iot3/examples/src/main/java/com/orange/Lwm2mExample.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ public static void main(String[] args) {
3333
}
3434

3535
private static void bootstrapExample() {
36-
Lwm2mInstance[] lwm2mInstances = new Lwm2mInstance[] {
37-
new Lwm2mIoT3Identity(),
38-
new Lwm2mIoT3ServiceEndpoint()
39-
};
36+
int maxInstanceNb = 20;
37+
Lwm2mInstance[] lwm2mInstances = new Lwm2mInstance[maxInstanceNb];
38+
for(int i = 0; i < maxInstanceNb; i++) {
39+
// create one instance of IoT3Identity
40+
if(i == 0) lwm2mInstances[i] = new Lwm2mIoT3Identity();
41+
// and multiple instances of IoT3ServiceEndpoints
42+
else lwm2mInstances[i] = new Lwm2mIoT3ServiceEndpoint();
43+
}
4044

4145
// instantiate LwM2M client
4246
Lwm2mClient lwm2mClient = new Lwm2mClient(
@@ -70,12 +74,14 @@ public void onBootstrap(Throwable bootstrapFailure) {
7074
}
7175
if(lwm2mInstance instanceof Lwm2mIoT3ServiceEndpoint endpoint) {
7276
IoT3ServiceEndpoint ioT3ServiceEndpoint = endpoint.toModel();
73-
System.out.println("IoT3ServiceEndpoint:"
74-
+ "\nService name: " + ioT3ServiceEndpoint.getServiceName()
75-
+ "\nPayload: " + ioT3ServiceEndpoint.getPayload()
76-
+ "\nURI: " + ioT3ServiceEndpoint.getServiceUri()
77-
+ "\nTopic root: " + ioT3ServiceEndpoint.getTopicRoot()
78-
+ "\nServer public key: " + Arrays.toString(ioT3ServiceEndpoint.getServerPublicKey()));
77+
if(!ioT3ServiceEndpoint.getServiceName().isEmpty()) {
78+
System.out.println("IoT3ServiceEndpoint:"
79+
+ "\nService name: " + ioT3ServiceEndpoint.getServiceName()
80+
+ "\nPayload: " + ioT3ServiceEndpoint.getPayload()
81+
+ "\nURI: " + ioT3ServiceEndpoint.getServiceUri()
82+
+ "\nTopic root: " + ioT3ServiceEndpoint.getTopicRoot()
83+
+ "\nServer public key: " + Arrays.toString(ioT3ServiceEndpoint.getServerPublicKey()));
84+
}
7985
}
8086
}
8187
} else {

0 commit comments

Comments
 (0)