... | ... | @@ -186,26 +186,27 @@ Client |
|
|
Temperature < 21 -> off
|
|
|
|
|
|
1. Use the eventing mechanism CoAP-Observe (Server.java, TODO 10):
|
|
|
• Mark the TemperatureResource as observable
|
|
|
* Mark the TemperatureResource as observable
|
|
|
`resource.setObservable(true);`
|
|
|
2. Let server notify clients every 5 s about changed TemperatureResource (Server.java, TODO 11):
|
|
|
* indicate a change for resource every 5 seconds
|
|
|
`while (true) {`
|
|
|
try {Thread.sleep(5000);}`
|
|
|
catch (InterruptedException e) {/*do nothing*/}`
|
|
|
resource.changed();`
|
|
|
}`
|
|
|
* indicate a change for resource every 5 seconds
|
|
|
`while (true) {`
|
|
|
` try {Thread.sleep(5000);}`
|
|
|
` catch (InterruptedException e) {/*do nothing*/}`
|
|
|
` resource.changed();`
|
|
|
`}`
|
|
|
|
|
|
* 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
|
|
|
|
|
|
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):
|
|
|
* Change exitAfterResponse to false (Client.java, TODO 12)
|
|
|
* Add the observe-option to your CoAP-GET request (Client.java, TODO 13)
|
|
|
* Change exitAfterResponse to false (Client.java, TODO 12)
|
|
|
* Add the observe-option to your CoAP-GET request (Client.java, TODO 13)
|
|
|
`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));
|
|
|
* send PUT request (Client.java, TODO 15)
|
|
|
* send PUT request (Client.java, TODO 15)
|
|
|
`CoapRequest request = clientChannel.createRequest(true, CoapRequestCode.PUT);`
|
|
|
`request.setUriPath(“/ACControl”);`
|
|
|
`request.setContentType(CoapMediaType.text_plain);`
|
... | ... | |