Skip to content

Getting Started : Client

sbernard31 edited this page Nov 22, 2017 · 9 revisions

Here you will see how to code your own LWM2M client with Leshan.

Get Leshan

To develop your client you need to use the leshan-client-cf module. To know the last version.

Using maven

<dependencies>
    <dependency>
        <groupId>org.eclipse.leshan</groupId>
        <artifactId>leshan-client-cf</artifactId>
        <version><!-- use the last version --></version>                  
    </dependency>
    <!-- add any slf4j backend, here we use one of the smallest one: slf4j-simple -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.10</version>
        <scope>runtime</scope>
    </dependency>
</dependencies>

Create a Simple Client.

You need to use Leshan builder to create client.

LeshanClientBuilder builder = new LeshanClientBuilder("myClient");
LeshanClient client = builder.build();
client.start();

You should see something like this in your log :

[main] INFO org.eclipse...LeshanClient - Leshan client[endpoint:myClient] started at coap://0.0.0.0/0.0.0.0:46535 coaps://0.0.0.0/0.0.0.0:36490
[RegistrationEngine#0] INFO org.eclipse...RegistrationEngine - Trying to register to coap://leshan.eclipse.org:5683 ...
[RegistrationEngine#0] INFO org.eclipse...RegistrationEngine - Registered with location '/rd/w50JjnP76l'.
[RegistrationEngine#0] INFO org.eclipse...RegistrationEngine - Next registration update in 270.0s...

That's means that you are successfully register your client to the leshan sandbox. You can check if you see your "myClient" device in the web UI and you can play with it (Read or Write on Device object).