bjoern.butzin created page: home authored by Björn Butzin's avatar Björn Butzin
......@@ -39,7 +39,7 @@ Client Side
**TemperatureResource:** individual resource, inherits from BasicCoapResource
**BasicCoapResource:** already implemented resource with basic functionality, implements CoapResource (interface)
**CoapResource (interface):** describes interfaces that must be supported by each resource.
**CoapResourceServer:** manages a list of resources, enables access of these resources from outside, implements CoapServer (interface), uses ChannelManager for connection management.
**CoapResourceServer:** manages a list of resources, enables access of these resources from outside, implements CoapServer (interface)
**CoapServer (interface):** describes interfaces that must be supported by a resource server
**ChannelManager:** manages channels
**Channel:** one channel represents a connection to one client
......@@ -106,21 +106,20 @@ You can find the required files in our repository at [file](ws4d/jcoap/tree/mast
* ->So we implemented TemperatureResource wich extends BasicCoapResource with:
* A constructor to initialize the resource and disallow POST, PUT and DELETE requests
* Two get() Methods:
* Get a list of accepted media types [& query parameters]
* Returns a `byte[ ]` together with its media type
* Get a list of accepted media types [& query parameters] which returns a `byte[ ]` together with its media type
* And the `getResourceType()` method
* Wich returns a description string of the resource
#### 2. Instantiate a new ResourceServer (Server.java, FIXME 1):
* Need a CoapResourceServer to maintain resources
* Need a CoapResourceServer to maintain resources
`CoapResourceServer resourceServer = new CoapResourceServer();`
#### 3. Instantiate a new TemperatureResource (Server.java, FIXME 2):
* Resources are created like normal objects and added to the server
* Resources are created like normal objects and added to the server
`CoapResource resource = new CoapResource();`
#### 4. Add the TemperatureResource to the ResourceServer (Server.java, FIXME 3):
* Resources are created like normal objects and added to the server
* Resources are created like normal objects and added to the server
`resourceServer.createResource(resource);`
#### 5. Run the ResourceServer (Server.java):
......@@ -150,7 +149,7 @@ You can find the required files in our repository at [file](ws4d/jcoap/tree/mast
`clientChannel = channelManager.connect(CoapClient client,InetAddress serverIP, int serverPort);`
#### 2. Create a CoapRequest & add some Options (Client.java, FIXME 6-8):
* A channel represents a single connection and is used to create and send requests
* A channel represents a single connection and is used to create and send requests
`Boolean reliable = false;`
`CoapRequestCode reqCode = CoapRequestCode.GET;`
`CoapRequest request = clientChannel.createRequest(reliable,reqCode);`
......@@ -192,17 +191,17 @@ 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):
* 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));`
* send PUT request (Client.java, TODO 15)
`CoapRequest request = clientChannel.createRequest(true, CoapRequestCode.PUT);`
`request.setUriPath(“/ACControl”);`
`request.setContentType(CoapMediaType.text_plain);`
Depending on the received temperature, set the payload to high, medium, low or off
28 <= Temperature -> high
25 <= Temperature < 28 -> medium
21 <= Temperature < 25 -> low
Temperature < 21 -> off
high -> 28 <= Temperature
medium -> 25 <= Temperature < 28
low -> 21 <= Temperature < 25
off ->Temperature < 21
`request.setPayload(“medium”.getBytes());`
`clientChannel.sendMessage(request);`