Java Code Examples for org.eclipse.californium.core.CoapServer#add()

The following examples show how to use org.eclipse.californium.core.CoapServer#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExternalCommandsDriver.java    From SoftwarePilot with MIT License 6 votes vote down vote up
public ExternalCommandsDriver() {
		//ecdLogger.log(Level.FINEST, "In Constructor");
		try {
				NetworkConfig nc = new NetworkConfig();
				cs = new CoapServer(nc); //create a new coapserver
				InetSocketAddress bindToAddress = new InetSocketAddress( LISTEN_PORT);
				cs.addEndpoint(new CoapEndpoint(bindToAddress));//Adds an Endpoint to the server.
				driverPort = bindToAddress.getPort();

				cs.add(new ecdResource());//Add a resource to the server
		}
		catch(Exception e) {
		}



}
 
Example 2
Source File: CoapReceiverServer.java    From datacollector with Apache License 2.0 6 votes vote down vote up
public List<Stage.ConfigIssue> init(Stage.Context context) {
  List<Stage.ConfigIssue> issues = new ArrayList<>();
  NetworkConfig networkConfig = NetworkConfig.createStandardWithoutFile();
  networkConfig.set(NetworkConfig.Keys.DEDUPLICATOR, NetworkConfig.Keys.NO_DEDUPLICATOR);
  networkConfig.set(NetworkConfig.Keys.PROTOCOL_STAGE_THREAD_COUNT, coAPServerConfigs.maxConcurrentRequests);
  networkConfig.set(NetworkConfig.Keys.NETWORK_STAGE_RECEIVER_THREAD_COUNT, coAPServerConfigs.maxConcurrentRequests);
  if (coAPServerConfigs.networkConfigs != null) {
    for (String key: coAPServerConfigs.networkConfigs.keySet()) {
      networkConfig.set(key, coAPServerConfigs.networkConfigs.get(key));
    }
  }
  coapServer = new CoapServer(networkConfig, coAPServerConfigs.port);
  coapReceiverResource = new CoapReceiverResource(context, receiver, errorQueue);
  coapServer.add(coapReceiverResource);
  coapServer.start();
  return issues;
}
 
Example 3
Source File: TestCoapClientTarget.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  int port =  TestHttpClientTarget.getFreePort();
  coapServer = new CoapServer(NetworkConfig.createStandardWithoutFile(), port);
  coapServer.add(new CoapResource("test") {
    @Override
    public void handlePOST(CoapExchange exchange) {
      serverRequested = true;
      if (returnErrorResponse) {
        exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
        return;
      }
      requestPayload = new String(exchange.getRequestPayload());
      exchange.respond(CoAP.ResponseCode.VALID);
    }
  });
  resourceURl = "coap://localhost:" + port + "/test";
  coapServer.start();
}
 
Example 4
Source File: HelloWorld2.java    From hands-on-coap with Eclipse Public License 1.0 6 votes vote down vote up
public static void main(String[] args) {

        // binds on UDP port 5683
        CoapServer server = new CoapServer();

        // "hello"
        server.add(new HelloResource());

        // "subpath/Another"
        CoapResource path = new CoapResource("subpath");
        path.add(new AnotherResource());
        server.add(path);

        // "removeme!, "time", "writeme!"
        server.add(new RemovableResource(), new TimeResource(), new WritableResource());

        server.start();
    }
 
Example 5
Source File: CaptureImageV2Driver.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public CaptureImageV2Driver() throws Exception {
	//NetworkConfig.getStandard().set(NetworkConfig.Keys.MAX_RESOURCE_BODY_SIZE,10000000);
	bdLogger.log(Level.FINEST, "In Constructor");
	cs = new CoapServer(); //initilize the server
	InetSocketAddress bindToAddress =
			new InetSocketAddress( LISTEN_PORT);//get the address
	CoapEndpoint tmp = new CoapEndpoint(bindToAddress); //create endpoint
	cs.addEndpoint(tmp);//add endpoint to server
	startTime = System.currentTimeMillis();
	tmp.start();//Start this endpoint and all its components.
	driverPort = tmp.getAddress().getPort();
	cs.add(new bdResource());

	try {
		Class.forName("org.h2.Driver");
		Connection conn = DriverManager.getConnection("jdbc:h2:mem:CaptureImageV2Driver;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1",
				"user", "password");
		conn.createStatement().executeUpdate("CREATE TABLE data (" +" key  INTEGER AUTO_INCREMENT,"
				+" time BIGINT, "
				+" X VARCHAR(16), "
				+" Y VARCHAR(16), "
				+" Z VARCHAR(16), "
				+" Filename VARCHAR(1023) )");
		conn.close();
	}
	catch(Exception e) {
		e.printStackTrace();
	}

}
 
Example 6
Source File: FlyDroneDriver.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public FlyDroneDriver() throws Exception {
		fddLogger.log(Level.FINEST, "In Constructor");
		cs = new CoapServer(); //initilize the server
		InetSocketAddress bindToAddress = new InetSocketAddress( LISTEN_PORT);//get the address
		CoapEndpoint tmp = new CoapEndpoint(bindToAddress); //create endpoint
		cs.addEndpoint(tmp);//add endpoint to server
		tmp.start();//Start this endpoint and all its components.
		driverPort = tmp.getAddress().getPort();

		cs.add(new fddResource());

}
 
Example 7
Source File: MissionDriver.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public MissionDriver() throws Exception {
mdLogger.log(Level.FINEST, "In Constructor");
cs = new CoapServer(); //initilize the server
InetSocketAddress bindToAddress =
		new InetSocketAddress("localhost", LISTEN_PORT);//get the address
CoapEndpoint tmp = new CoapEndpoint(bindToAddress); //create endpoint
cs.addEndpoint(tmp);//add endpoint to server
tmp.start();//Start this endpoint and all its components.
driverPort = tmp.getAddress().getPort();
cs.add(new mdResource());
}
 
Example 8
Source File: LocationDriver.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public LocationDriver() throws Exception {
		bdLogger.log(Level.FINEST, "In Constructor");
		cs = new CoapServer(); //initilize the server
		InetSocketAddress bindToAddress =
				new InetSocketAddress( LISTEN_PORT);//get the address
		CoapEndpoint tmp = new CoapEndpoint(bindToAddress); //create endpoint
		cs.addEndpoint(tmp);//add endpoint to server
		startTime = System.currentTimeMillis();
		tmp.start();//Start this endpoint and all its components.
		driverPort = tmp.getAddress().getPort();
		cs.add(new bdResource());
		makeH2();
}
 
Example 9
Source File: PicTraceDriver.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public PicTraceDriver() throws Exception {
		bdLogger.log(Level.FINEST, "In Constructor");
		cs = new CoapServer(); //initilize the server
		InetSocketAddress bindToAddress =
				new InetSocketAddress( LISTEN_PORT);//get the address
		CoapEndpoint tmp = new CoapEndpoint(bindToAddress); //create endpoint
		cs.addEndpoint(tmp);//add endpoint to server
		startTime = System.currentTimeMillis();
		tmp.start();//Start this endpoint and all its components.
		driverPort = tmp.getAddress().getPort();
		cs.add(new bdResource());
		makeH2();
}
 
Example 10
Source File: DroneGimbalDriver.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public DroneGimbalDriver() throws Exception {
		dgdLogger.log(Level.FINEST, "In Constructor");
		cs = new CoapServer(); //initilize the server
		InetSocketAddress bindToAddress = new InetSocketAddress( LISTEN_PORT);//get the address
		CoapEndpoint tmp = new CoapEndpoint(bindToAddress); //create endpoint
		cs.addEndpoint(tmp);//add endpoint to server
		tmp.start();//Start this endpoint and all its components.
		driverPort = tmp.getAddress().getPort();

		cs.add(new dgdResource());

}
 
Example 11
Source File: VisionDriver.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public VisionDriver() throws Exception {
		fddLogger.log(Level.FINEST, "In Constructor");
		cs = new CoapServer(); //initilize the server
		InetSocketAddress bindToAddress = new InetSocketAddress( LISTEN_PORT);//get the address
		CoapEndpoint tmp = new CoapEndpoint(bindToAddress); //create endpoint
		cs.addEndpoint(tmp);//add endpoint to server
		tmp.start();//Start this endpoint and all its components.
		driverPort = tmp.getAddress().getPort();

		cs.add(new fddResource());
}
 
Example 12
Source File: TemplateDriver.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public TemplateDriver() throws Exception {
		logger.log(Level.FINEST, "In Constructor");
		cs = new CoapServer(); //initilize the server
		InetSocketAddress bindToAddress =
				new InetSocketAddress("localhost", LISTEN_PORT);//get the address
		CoapEndpoint tmp = new CoapEndpoint(bindToAddress); //create endpoint
		cs.addEndpoint(tmp);//add endpoint to server
		tmp.start();//Start this endpoint and all its components.
		driverPort = tmp.getAddress().getPort();
		cs.add(new Resource());
}
 
Example 13
Source File: BatteryDriver.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public BatteryDriver() throws Exception {
	bdLogger.log(Level.FINEST, "In Constructor");
	cs = new CoapServer(); //initilize the server
	InetSocketAddress bindToAddress =
			new InetSocketAddress("localhost", LISTEN_PORT);//get the address
	CoapEndpoint tmp = new CoapEndpoint(bindToAddress); //create endpoint
	cs.addEndpoint(tmp);//add endpoint to server
	startTime = System.currentTimeMillis();
	tmp.start();//Start this endpoint and all its components.
	driverPort = tmp.getAddress().getPort();
	cs.add(new bdResource());

	try {
			Class.forName("org.h2.Driver");
			Connection conn = DriverManager.getConnection("jdbc:h2:mem:BatteryDriver;DB_CLOSE_DELAY=-1",
																						 "user", "password");
			conn.createStatement().executeUpdate("CREATE TABLE data ("
																					 +" key  INTEGER AUTO_INCREMENT,"
																					 +" time BIGINT, "
																					 +" type VARCHAR(16), "
																					 +" value VARCHAR(1023) )");
			conn.close();
	}
	catch(Exception e) {
									e.printStackTrace();
	}

}
 
Example 14
Source File: IOTCoapServer.java    From IOT-Technical-Guide with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws UnknownHostException {

        CoapServer server = new CoapServer();


        server.add(new HelloResource());

        CoapResource path = new CoapResource("subpath");
        path.add(new AnotherResource());
        server.add(path);

        server.add(new RemovableResource(), new TimeResource(), new WritableResource());


        server.start();
    }
 
Example 15
Source File: HelloWorld2.java    From hands-on-coap with Eclipse Public License 1.0 3 votes vote down vote up
public static void main(String[] args) {

        // binds on UDP port 5683
        CoapServer server = new CoapServer();

        // "hello"
        server.add(new HelloResource());

        // TODO "subpath/Another"

        // TODO "removeme!, "time", "writeme!"

        server.start();
    }
 
Example 16
Source File: HelloWorld1.java    From hands-on-coap with Eclipse Public License 1.0 3 votes vote down vote up
public static void main(String[] args) {

        // binds on UDP port 5683
        CoapServer server = new CoapServer();

        server.add(new HelloResource());

        server.start();
    }