... | ... | @@ -24,10 +24,10 @@ The following points will be covered by this tutorial: |
|
|
|
|
|
## 2. Introduction of jCoAP
|
|
|
- WS4D-jCoAP: Java implementation of CoAP
|
|
|
-- http://ws4d.org/
|
|
|
-- https://gitlab.amd.e-technik.uni-rostock.de/ws4d/jcoap
|
|
|
- http://ws4d.org/
|
|
|
- https://gitlab.amd.e-technik.uni-rostock.de/ws4d/jcoap
|
|
|
|
|
|
• Task 1 – Sequence Diagram
|
|
|
### Task 1 – Sequence Diagram
|
|
|
|
|
|
Server Side
|
|
|
|
... | ... | @@ -46,18 +46,18 @@ Client Side |
|
|
-CoapClient (interface):describes interfaces that must be supported by a client
|
|
|
|
|
|
* ToDo on server side:
|
|
|
1. Create a new resource class TemperatureResource
|
|
|
2. Instantiate a new ResourceServer
|
|
|
3. Instantiate a new TemperatureResource
|
|
|
4. Add the TemperatureResource to the ResourceServer
|
|
|
5. Run the ResourceServer
|
|
|
1. Create a new resource class TemperatureResource
|
|
|
2. Instantiate a new ResourceServer
|
|
|
3. Instantiate a new TemperatureResource
|
|
|
4. Add the TemperatureResource to the ResourceServer
|
|
|
5. Run the ResourceServer
|
|
|
|
|
|
* ToDo on client side:
|
|
|
1. Establish a connection to the Server using the ChannelManager
|
|
|
2. Create a CoapRequest & add some Options
|
|
|
3. Send the CoapRequest
|
|
|
4. Wait for CoapResponse
|
|
|
5. Print the CoapResponse on the console
|
|
|
1. Establish a connection to the Server using the ChannelManager
|
|
|
2. Create a CoapRequest & add some Options
|
|
|
3. Send the CoapRequest
|
|
|
4. Wait for CoapResponse
|
|
|
5. Print the CoapResponse on the console
|
|
|
|
|
|
|
|
|
## 3. Import of prepared project into Eclipse
|
... | ... | @@ -87,30 +87,30 @@ Client Side |
|
|
5. Run the ResourceServer
|
|
|
|
|
|
1. Create a new resource class TemperatureResource (TemperatureResource.java):
|
|
|
* We could have used the predefined BasicCoapResource
|
|
|
* BasicCoapResource is a resource that just keeps a static `byte[ ]` that is:
|
|
|
** returned on GET requests
|
|
|
** replaced by the payload on PUT requests
|
|
|
** appended with the payload on POST requests
|
|
|
** deleted on DELETE requests
|
|
|
** We do not want a static `byte[ ]`
|
|
|
* Instead we want a random number to be returned on a GET
|
|
|
* PUT, POST and DELETE are not used
|
|
|
* ->So we implemented TemperatureResource wich extends BasicCoapResource with:
|
|
|
** A constructor
|
|
|
*** To initialize the resource
|
|
|
*** Disallow POST, PUT and DELETE
|
|
|
** 2 get() Methods
|
|
|
*** Get a list of accepted media types [& query parameters]
|
|
|
*** Returns a `byte[ ]` together with its media type
|
|
|
** And the `getResourceType()` method
|
|
|
*** Wich returns a description string of the resource
|
|
|
* We could have used the predefined BasicCoapResource
|
|
|
* BasicCoapResource is a resource that just keeps a static `byte[ ]` that is:
|
|
|
* returned on GET requests
|
|
|
* replaced by the payload on PUT requests
|
|
|
* appended with the payload on POST requests
|
|
|
* deleted on DELETE requests
|
|
|
* We do not want a static `byte[ ]`
|
|
|
* Instead we want a random number to be returned on a GET
|
|
|
* PUT, POST and DELETE are not used
|
|
|
* ->So we implemented TemperatureResource wich extends BasicCoapResource with:
|
|
|
* A constructor
|
|
|
* To initialize the resource
|
|
|
* Disallow POST, PUT and DELETE
|
|
|
* 2 get() Methods
|
|
|
* Get a list of accepted media types [& query parameters]
|
|
|
* 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
|
|
|
`CoapResourceServer resourceServer = new CoapResourceServer();`
|
|
|
* 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
|
|
|
`CoapResource resource = new CoapResource();`
|
|
|
* Resources are created like normal objects and added to the server
|
|
|
`CoapResource resource = new CoapResource();`
|
|
|
|
|
|
* Use the „Tasks“ view of Eclipse to find the right places
|
|
|
* Solve only FIXME 1-3 as described by the following instructions - ignore other FIXMEs or TODOs
|
... | ... | |