bjoern.butzin created page: home authored by Björn Butzin's avatar Björn Butzin
...@@ -144,7 +144,7 @@ You can find the required files in our repository at [file](ws4d/jcoap/tree/mast ...@@ -144,7 +144,7 @@ You can find the required files in our repository at [file](ws4d/jcoap/tree/mast
#### 1. Establish a connection to the Server using the ChannelManager (Client.java, FIXME 4-5): #### 1. Establish a connection to the Server using the ChannelManager (Client.java, FIXME 4-5):
* A client must implement CoapClient interface * A client must implement CoapClient interface
`public class Client implements CoapClient {...}` `public class Client implements CoapClient {...}`
* A CoapChannelManager is used to manage different connections and to establish a connection to a server * A CoapChannelManager is used to manage different connections and to establish a connection to a server
`channelManager = BasicCoapChannelManager.getInstance();` `channelManager = BasicCoapChannelManager.getInstance();`
`clientChannel = channelManager.connect(CoapClient client,InetAddress serverIP, int serverPort);` `clientChannel = channelManager.connect(CoapClient client,InetAddress serverIP, int serverPort);`
...@@ -191,17 +191,18 @@ You can find the required files in our repository at [file](ws4d/jcoap/tree/mast ...@@ -191,17 +191,18 @@ You can find the required files in our repository at [file](ws4d/jcoap/tree/mast
`}` `}`
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): 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) * 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 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) `resourceServer.createResource(newBasicCoapResource(“/ACControl”,”off”,CoapMediaType.text_plain));` * 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);` `CoapRequest request = clientChannel.createRequest(true, CoapRequestCode.PUT);`
`request.setUriPath(“/ACControl”);` `request.setUriPath(“/ACControl”);`
`request.setContentType(CoapMediaType.text_plain);` `request.setContentType(CoapMediaType.text_plain);`
Depending on the received temperature, set the payload to high, medium, low or off Depending on the received temperature, set the payload to high, medium, low or off
high -> 28 <= Temperature high -> 28 <= Temperature
medium -> 25 <= Temperature < 28 medium -> 25 <= Temperature < 28
low -> 21 <= Temperature < 25 low -> 21 <= Temperature < 25
off ->Temperature < 21 off -> Temperature < 21
`request.setPayload(“medium”.getBytes());` `request.setPayload(“medium”.getBytes());`
`clientChannel.sendMessage(request);` `clientChannel.sendMessage(request);`