Skip to content

Commit

Permalink
Add CoAP endpoint based on java-coap to leshan-server-demo
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Oct 19, 2023
1 parent 7322032 commit edc4edf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions leshan-server-demo/pom.xml
Expand Up @@ -49,6 +49,10 @@ Contributors:
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-server-redis</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-tl-javacoap-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>californium-core</artifactId>
Expand Down
Expand Up @@ -61,6 +61,7 @@
import org.eclipse.leshan.server.redis.RedisSecurityStore;
import org.eclipse.leshan.server.security.EditableSecurityStore;
import org.eclipse.leshan.server.security.FileSecurityStore;
import org.eclipse.leshan.transport.javacoap.server.endpoint.JavaCoapServerEndpointsProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -249,8 +250,14 @@ public static LeshanServer createLeshanServer(LeshanServerDemoCLI cli) throws Ex
: new InetSocketAddress(cli.main.secureLocalAddress, coapsPort);
endpointsBuilder.addEndpoint(coapsAddr, Protocol.COAPS);

// Create CoAP endpoint based on java-coap
int jcoapPort = cli.main.jlocalPort;
InetSocketAddress jcoapAddr = cli.main.secureLocalAddress == null ? new InetSocketAddress(jcoapPort)
: new InetSocketAddress(cli.main.jlocalAddress, jcoapPort);
JavaCoapServerEndpointsProvider javacoapEndpointsProvider = new JavaCoapServerEndpointsProvider(jcoapAddr);

// Create LWM2M server
builder.setEndpointsProviders(endpointsBuilder.build());
builder.setEndpointsProviders(endpointsBuilder.build(), javacoapEndpointsProvider);
return builder.build();
}

Expand Down
Expand Up @@ -19,6 +19,7 @@

import org.eclipse.leshan.core.demo.cli.StandardHelpOptions;
import org.eclipse.leshan.core.demo.cli.VersionProvider;
import org.eclipse.leshan.core.demo.cli.converters.PortConverter;
import org.eclipse.leshan.server.core.demo.cli.DtlsSection;
import org.eclipse.leshan.server.core.demo.cli.GeneralSection;
import org.eclipse.leshan.server.core.demo.cli.IdentitySection;
Expand Down Expand Up @@ -55,6 +56,19 @@ public class LeshanServerDemoCLI implements Runnable {
public ServerGeneralSection main = new ServerGeneralSection();

public static class ServerGeneralSection extends GeneralSection {
@Option(names = { "-jh", "--java-coap-host" },
description = { //
"Set the local CoAP address of endpoint based on java-coap library.", //
"Default: any local address." })
public String jlocalAddress;

@Option(names = { "-jp", "--java-coap-port" },
description = { //
"Set the local CoAP port of endpoint based on java-coap library.", //
"Default: ${DEFAULT-VALUE}" },
converter = PortConverter.class)
public Integer jlocalPort = 5685;

@Option(names = { "-r", "--redis" },
description = { //
"Use redis to store registration and securityInfo.", //
Expand Down

0 comments on commit edc4edf

Please sign in to comment.