bjoern.butzin created page: home authored by Björn Butzin's avatar Björn Butzin
...@@ -186,26 +186,27 @@ Client ...@@ -186,26 +186,27 @@ Client
Temperature < 21 -> off Temperature < 21 -> off
1. Use the eventing mechanism CoAP-Observe (Server.java, TODO 10): 1. Use the eventing mechanism CoAP-Observe (Server.java, TODO 10):
Mark the TemperatureResource as observable * Mark the TemperatureResource as observable
`resource.setObservable(true);` `resource.setObservable(true);`
2. Let server notify clients every 5 s about changed TemperatureResource (Server.java, TODO 11): 2. Let server notify clients every 5 s about changed TemperatureResource (Server.java, TODO 11):
* indicate a change for resource every 5 seconds * indicate a change for resource every 5 seconds
`while (true) {` `while (true) {`
try {Thread.sleep(5000);}` ` try {Thread.sleep(5000);}`
catch (InterruptedException e) {/*do nothing*/}` ` catch (InterruptedException e) {/*do nothing*/}`
resource.changed();` ` resource.changed();`
}` `}`
* Use the „Tasks“ view of Eclipse to find the right places * Use the „Tasks“ view of Eclipse to find the right places
* Solve only TODO 10-15 as described by the following instructions - ignore other TODOs or FIXMEs * Solve only TODO 10-15 as described by the following instructions - ignore other TODOs or FIXMEs
3. Implement an Air Conditioner Resource with the path “/ACControl”, that can be set to “high”, 3. Implement an Air Conditioner Resource with the path “/ACControl”, that can be set to “high”,
“medium”, “low” or “off” (Client.java & Server.java, TODO 12-15): “medium”, “low” or “off” (Client.java & Server.java, TODO 12-15):
* Change exitAfterResponse to false (Client.java, TODO 12) * Change exitAfterResponse to false (Client.java, TODO 12)
* Add the observe-option to your CoAP-GET request (Client.java, TODO 13) * Add the observe-option to your CoAP-GET request (Client.java, TODO 13)
`request.setObserveOption(0);` `request.setObserveOption(0);`
* add a BasicCoapResource to the ResourceServer (Server.java, TODO 14) * add a BasicCoapResource to the ResourceServer (Server.java, TODO 14)
resourceServer.createResource( newBasicCoapResource(“/ACControl”,”off”,CoapMediaType.text_plain)); resourceServer.createResource( newBasicCoapResource(“/ACControl”,”off”,CoapMediaType.text_plain));
* send PUT request (Client.java, TODO 15) * send PUT request (Client.java, TODO 15)
`CoapRequest request = clientChannel.createRequest(true, CoapRequestCode.PUT);` `CoapRequest request = clientChannel.createRequest(true, CoapRequestCode.PUT);`
`request.setUriPath(“/ACControl”);` `request.setUriPath(“/ACControl”);`
`request.setContentType(CoapMediaType.text_plain);` `request.setContentType(CoapMediaType.text_plain);`
... ...
......