Hi,
Thank you for your quick response. It's not likely I am trying to create a CoAP gateway. What I intend to do is to enable CoAP communication between my device client and Eclipse Kura (this will act as my gateway). However, because currently Kura doesn't support CoAP, I want to use Californium to do it. Therefore I am playing around with Californium to understand it before I can start implement Californium into Kura.
About your suggestion, yes, I did what you mentioned in the code below (for the CoAP server on the device client):
public static class HelloResource extends CoapResource {
public HelloResource() {
super("Ultrasonic");
setObservable(true);
}
@Override
public void handleGET(CoapExchange exchange) {
exchange.respond("Replace with something else to take the data sent to this CoAP server in handlePUT");
}
@Override
public void handlePUT(CoapExchange exchange) {
String payload = exchange.getRequestText();
System.out.println(payload + " cm");
try {
exchange.respond(CHANGED, payload);
changed();
} catch (Exception e) {
e.printStackTrace();
exchange.respond(BAD_REQUEST, "Invalid String");
}
}
}
When I use Observe on Copper. it can recognize the change trigger of resources, but what it receives/output on the screen is the text I put in the handleGET in the code above. Copper can recognize each time the data of my ultrasonic is changed on the CoAP server, and ouput the line "Replace with something else" instead of the real data for each change trigger. So my question is that what do I need to put inside the exchange.respond() of the handleGET (on the CoAP server) , so the handleGET can take the data/payload sent to the CoAP server (by PUT method of the CoAP client on device client) in the handlePUT.