Hi,
I am trying out californium with my scenario. Currently, I have implemented a californium client which takes the values from my ultrasonic sensor on a raspberry Pi and send them to my californium server every 2 seconds. Now I want to use Copper to observe to that resource for the changed values. However, so far I don't know how to make handleGET respond to take the value sent to the server through handlePUT, because as I notice the observe method will subscribe to the resource and use GET to receive the changed values.
Here is the code on my server side:
public static class HelloResource extends CoapResource {
public HelloResource() {
super("Ultrasonic");
setObservable(true);
}
@Override
public void handleGET(CoapExchange exchange) {
exchange.respond("Replace to make Copper see the changed values");
}
@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");
}
}
}
Could someone provide any help ? Thank you in advance.