... | @@ -39,7 +39,7 @@ Client Side |
... | @@ -39,7 +39,7 @@ Client Side |
|
**TemperatureResource:** individual resource, inherits from BasicCoapResource
|
|
**TemperatureResource:** individual resource, inherits from BasicCoapResource
|
|
**BasicCoapResource:** already implemented resource with basic functionality, implements CoapResource (interface)
|
|
**BasicCoapResource:** already implemented resource with basic functionality, implements CoapResource (interface)
|
|
**CoapResource (interface):** describes interfaces that must be supported by each resource.
|
|
**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
|
|
**CoapServer (interface):** describes interfaces that must be supported by a resource server
|
|
**ChannelManager:** manages channels
|
|
**ChannelManager:** manages channels
|
|
**Channel:** one channel represents a connection to one client
|
|
**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 |
... | @@ -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:
|
|
* ->So we implemented TemperatureResource wich extends BasicCoapResource with:
|
|
* A constructor to initialize the resource and disallow POST, PUT and DELETE requests
|
|
* A constructor to initialize the resource and disallow POST, PUT and DELETE requests
|
|
* Two get() Methods:
|
|
* Two get() Methods:
|
|
* Get a list of accepted media types [& query parameters]
|
|
* Get a list of accepted media types [& query parameters] which returns a `byte[ ]` together with its media type
|
|
* Returns a `byte[ ]` together with its media type
|
|
|
|
* And the `getResourceType()` method
|
|
* And the `getResourceType()` method
|
|
* Wich returns a description string of the resource
|
|
* Wich returns a description string of the resource
|
|
|
|
|
|
#### 2. Instantiate a new ResourceServer (Server.java, FIXME 1):
|
|
#### 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();`
|
|
`CoapResourceServer resourceServer = new CoapResourceServer();`
|
|
|
|
|
|
#### 3. Instantiate a new TemperatureResource (Server.java, FIXME 2):
|
|
#### 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();`
|
|
`CoapResource resource = new CoapResource();`
|
|
|
|
|
|
#### 4. Add the TemperatureResource to the ResourceServer (Server.java, FIXME 3):
|
|
#### 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);`
|
|
`resourceServer.createResource(resource);`
|
|
|
|
|
|
#### 5. Run the ResourceServer (Server.java):
|
|
#### 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 |
... | @@ -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);`
|
|
`clientChannel = channelManager.connect(CoapClient client,InetAddress serverIP, int serverPort);`
|
|
|
|
|
|
#### 2. Create a CoapRequest & add some Options (Client.java, FIXME 6-8):
|
|
#### 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;`
|
|
`Boolean reliable = false;`
|
|
`CoapRequestCode reqCode = CoapRequestCode.GET;`
|
|
`CoapRequestCode reqCode = CoapRequestCode.GET;`
|
|
`CoapRequest request = clientChannel.createRequest(reliable,reqCode);`
|
|
`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 |
... | @@ -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):
|
|
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
|
|
28 <= Temperature -> high
|
|
high -> 28 <= Temperature
|
|
25 <= Temperature < 28 -> medium
|
|
medium -> 25 <= Temperature < 28
|
|
21 <= Temperature < 25 -> low
|
|
low -> 21 <= Temperature < 25
|
|
Temperature < 21 -> off
|
|
off ->Temperature < 21
|
|
`request.setPayload(“medium”.getBytes());`
|
|
`request.setPayload(“medium”.getBytes());`
|
|
`clientChannel.sendMessage(request);`
|
|
`clientChannel.sendMessage(request);`
|
|
|
|
|