LDP-CoAP consists of the following sub-projects:
You can try LDP-CoAP as described in the following examples (also available on github).
final String BASE_URI = "coap://example.org";
CoAPLDPServer server = new CoAPLDPServer(BASE_URI);
/*** Init server settings and LDP-CoAP resources ***/
init();
server.start();
// Server running
server.shutdown();
/*** Handle additional namespaces ***/
server.addHandledNamespace(SSN_XG.PREFIX, SSN_XG.NAMESPACE + "#");
/*** Handle read-only properties ***/
server.setReadOnlyProperty("http://purl.org/dc/terms/created");
/*** Handle not persisted properties ***/
server.setNotPersistedProperty("http://example.org/comment");
/*** Set the URI identifying all server constraints ***/
server.setConstrainedByURI("http://example.org/ldp-report.html");
/*** Create LDP RDF Source ***/
CoAPLDPRDFSource src = server.createRDFSource("alice");
src.setRDFTitle("My first CoAP RDFSource");
/*** Create LDP RDF Source with Data Handler ***/
CoAPLDPRDFSource cpu = server.createRDFSource("cpu");
cpu.setDataHandler(new CPUHandler());
/*** Create LDP Non-RDF Source ***/
CoAPLDPNonRDFSource nr = server.createNonRDFSource("hello", MediaTypeRegistry.TEXT_PLAIN);
nr.setData(("Hello World!").getBytes());
/*** Create LDP Basic Container ***/
CoAPLDPBasicContainer bc = server.createBasicContainer("sensors");
bc.setRDFTitle("LDP Basic sensors container");
bc.setRDFDescription("This container will contain data of sensors.");
/*** Add LDP-RS to the LDP-BC ***/
CoAPLDPRDFSource cpu = bc.createRDFSource("cpu");
cpu.setDataHandler(new CPUHandler());
/*** Add LDP-RS with an additional rdf:type (SSN_XG.SensorOutput) to the LDP-BC ***/
CoAPLDPRDFSource memory = bc.createRDFSource("memory", SSN_XG.SensorOutput.toString());
memory.setDataHandler(new MemoryHandler());
/************************************
* Create LDP Direct Container
*
* Usage of createDirectContainer
* server.createDirectContainer(String ldp_dc_name, String member_res_name, String member_res_type, String membershipRelation, String isMemberOfRelation)
*
************************************/
CoAPLDPDirectContainer dc = server.createDirectContainer("obs-dc", "tempSensor", SSN_XG.SensingDevice.toString(), SSN_XG.observes.toString(), null);
dc.setRDFTitle("Product description of LDP Demo product which is also an LDP-DC");
dc.getMemberResource().setRDFTitle("LDP-DC Member Resource");
/*** LDP-DC also accept POST with Non-RDF Resource (TEXT_PLAIN) ***/
dc.setAcceptPostType(MediaTypeRegistry.TEXT_PLAIN);
/*** Add LDP-RS to the LDP-DC ***/
CoAPLDPRDFSource resDC = dc.createRDFSource("obs1", SSN_XG.Observation.toString());
resDC.setRDFTitle("Single observation.");
/************************************
* Create LDP Indirect Container
*
* server.createIndirectContainer(String ldp_ic_name, String member_res_name, String member_res_type, String membershipRelation,
* String insertedContentRelation)
*
************************************/
CoAPLDPIndirectContainer ic = server.createIndirectContainer("obs-ic", "system", SSN_XG.System.toString(), SSN_XG.hasSubSystem.toString(),
SSN_XG.attachedSystem.toString());
ic.setRDFTitle("LDP-CoAP Indirect Container");
ic.getMemberResource().setRDFTitle("LDP-IC Member Resource");
/*** Add LDP-RS with Derived URI to the LDP-IC ***/
CoAPLDPRDFSource subSystem = ic.createRDFSourceWithDerivedURI("sub-system", SSN_XG.SensorOutput.toString(), BASE_URI + "/sensors/extra/output/out1");
subSystem.setRDFTitle("LDP-IC Resource");
/*** Create a new class extending basic LDPDataHandler ***/
public class ExtendedDataHandler extends LDPDataHandler {
/*** Ovveride the method handleData() and insert here all operations useful to update data within the RDF dataset ***/
@Override
protected void handleData() {
double value = example.readData(); //numeric value to store (e.g., retrieved from a sensor class)
mng.updateRDFLiteralStatement(mng.getBaseURI() + resource, SSN_XG.hasValue.toString(), value);
mng.updateRDFLiteralStatement(mng.getBaseURI() + resource, DCTERMS.CREATED.toString(), new Date());
}
}