本文整理汇总了Java中org.eclipse.leshan.client.californium.LeshanClient类的典型用法代码示例。如果您正苦于以下问题:Java LeshanClient类的具体用法?Java LeshanClient怎么用?Java LeshanClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LeshanClient类属于org.eclipse.leshan.client.californium包,在下文中一共展示了LeshanClient类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: register_with_additional_attributes
import org.eclipse.leshan.client.californium.LeshanClient; //导入依赖的package包/类
@Test
public void register_with_additional_attributes() throws InterruptedException {
// Check registration
helper.assertClientNotRegisterered();
// HACK to be able to send a Registration request with additional attributes
LeshanClient lclient = helper.client;
lclient.getCoapServer().start();
Endpoint secureEndpoint = lclient.getCoapServer().getEndpoint(lclient.getSecuredAddress());
Endpoint nonSecureEndpoint = lclient.getCoapServer().getEndpoint(lclient.getUnsecuredAddress());
CaliforniumLwM2mRequestSender sender = new CaliforniumLwM2mRequestSender(secureEndpoint, nonSecureEndpoint);
// Create Request with additional attributes
Map<String, String> additionalAttributes = new HashMap<>();
additionalAttributes.put("key1", "value1");
additionalAttributes.put("imei", "2136872368");
Link[] objectLinks = Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>".getBytes());
RegisterRequest registerRequest = new RegisterRequest(helper.getCurrentEndpoint(), null, null, null, null,
objectLinks, additionalAttributes);
// Send request
RegisterResponse resp = sender.send(helper.server.getUnsecuredAddress(), false, registerRequest, 5000l);
helper.waitForRegistration(1);
// Check we are registered with the expected attributes
helper.assertClientRegisterered();
assertNotNull(helper.last_registration);
assertEquals(additionalAttributes, helper.last_registration.getAdditionalRegistrationAttributes());
assertArrayEquals(Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>".getBytes()),
helper.getCurrentRegistration().getObjectLinks());
sender.send(helper.server.getUnsecuredAddress(), false, new DeregisterRequest(resp.getRegistrationID()), 5000l);
lclient.getCoapServer().stop();
}
示例2: main
import org.eclipse.leshan.client.californium.LeshanClient; //导入依赖的package包/类
public static void main(final String[] args) {
if(ConfigLoader.LoadFile()){
SerialConnector sc = new SerialConnector();
TemperatureSensor tempSensor = new TemperatureSensor(sc);
HumiditySensor humiSensor = new HumiditySensor(sc);
LightActuator lightActuator = new LightActuator(sc);
// Get endpoint name
String endpoint = DEFAULT_ENDPOINT;
// Get server URI
String serverURI="coap://localhost:5083";
// byte[] pskIdentity = null;
// byte[] pskKey = null;
// get local address
String localAddress = "localhost";
int localPort = 6000;
// get secure local address
String secureLocalAddress = "localhost";
int secureLocalPort = 6001;
sc.start();
// Initialize object list
ObjectsInitializer initializer = new ObjectsInitializer();
initializer.setInstancesForObject(SECURITY, noSec(serverURI, 123));
initializer.setInstancesForObject(SERVER, new Server(123, 30, BindingMode.U, false));
initializer.setClassForObject(DEVICE, KETIVirtualDevice.class);
initializer.setInstancesForObject(3303, tempSensor);
initializer.setInstancesForObject(3304, humiSensor);
initializer.setInstancesForObject(3311, lightActuator);
List<LwM2mObjectEnabler> enablers = initializer.create(SECURITY, SERVER, DEVICE, 3303, 3304, 3311);
// Create client
LeshanClientBuilder builder = new LeshanClientBuilder(endpoint);
builder.setLocalAddress(localAddress, localPort);
builder.setLocalSecureAddress(secureLocalAddress, secureLocalPort);
builder.setObjects(enablers);
final LeshanClient client = builder.build();
// Start the client
client.start();
// De-register on shutdown and stop client.
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
client.destroy(true); // send de-registration request before destroy
}
});
} else {
LOG.error("Can not found the port.conf file!");
}
}
示例3: createAndStartClient
import org.eclipse.leshan.client.californium.LeshanClient; //导入依赖的package包/类
public static void createAndStartClient(String endpoint, String localAddress, int localPort,
String secureLocalAddress, int secureLocalPort, boolean needBootstrap, String serverURI, byte[] pskIdentity,
byte[] pskKey) {
// Initialize object list
ObjectsInitializer initializer = new ObjectsInitializer();
if (needBootstrap) {
if (pskIdentity == null)
initializer.setInstancesForObject(SECURITY, noSecBootstap(serverURI));
else
initializer.setInstancesForObject(SECURITY, pskBootstrap(serverURI, pskIdentity, pskKey));
} else {
if (pskIdentity == null) {
initializer.setInstancesForObject(SECURITY, noSec(serverURI, 123));
initializer.setInstancesForObject(SERVER, new Server(123, 30, BindingMode.U, false));
} else {
initializer.setInstancesForObject(SECURITY, psk(serverURI, 123, pskIdentity, pskKey));
initializer.setInstancesForObject(SERVER, new Server(123, 30, BindingMode.U, false));
}
}
initializer.setClassForObject(DEVICE, MyDevice.class);
initializer.setInstancesForObject(LOCATION, locationInstance);
List<LwM2mObjectEnabler> enablers = initializer.create(SECURITY, SERVER, DEVICE, CONNECTIVITY_MONITORING, LOCATION, CONNECTIVITY_STATISTICS);
// Create client
LeshanClientBuilder builder = new LeshanClientBuilder(endpoint);
builder.setLocalAddress(localAddress, localPort);
builder.setLocalSecureAddress(secureLocalAddress, secureLocalPort);
builder.setObjects(enablers);
final LeshanClient client = builder.build();
LOG.info("Press 'w','a','s','d' to change reported Location.");
// Start the client
client.start();
// De-register on shutdown and stop client.
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
client.destroy(true); // send de-registration request before destroy
}
});
// Change the location through the Console
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String nextMove = scanner.next();
locationInstance.moveLocation(nextMove);
}
scanner.close();
}
示例4: getConnector
import org.eclipse.leshan.client.californium.LeshanClient; //导入依赖的package包/类
private Connector getConnector(LeshanClient client) {
CoapEndpoint endpoint = (CoapEndpoint) helper.client.getCoapServer()
.getEndpoint(helper.client.getUnsecuredAddress());
return endpoint.getConnector();
}