contiki/examples/rest-example
2010-11-24 10:10:48 +00:00
..
coap-client-example.c Added a coap client and running coap-client-server COOJA simulation. Made README more detailed. 2010-11-24 10:10:48 +00:00
coap-client-server-example.csc Added a coap client and running coap-client-server COOJA simulation. Made README more detailed. 2010-11-24 10:10:48 +00:00
Makefile Added a coap client and running coap-client-server COOJA simulation. Made README more detailed. 2010-11-24 10:10:48 +00:00
project-conf.h Changed name of web-conf.h to project-conf.h 2010-10-28 13:11:08 +00:00
README Added a coap client and running coap-client-server COOJA simulation. Made README more detailed. 2010-11-24 10:10:48 +00:00
rest-server-example.c Added a coap client and running coap-client-server COOJA simulation. Made README more detailed. 2010-11-24 10:10:48 +00:00
rest-server-example.csc Added a coap client and running coap-client-server COOJA simulation. Made README more detailed. 2010-11-24 10:10:48 +00:00

Open a terminal and go to "examples/rest-example/" directory.

MAIN EXAMPLE:
rest-server-example.c : A RESTful server example showing how to use the REST layer to develop server-side applications (possible to run it over either COAP or HTTP)
To use COAP as the underlying application protocol, one should define WITH_COAP = 1 in rest-example/Makefile. Otherwise, HTTP is used.
Look at the source code to see which resources are available. (check the RESOURCE macros in the code).


To run REST examples in COOJA under Linux
--------------------------------------------

Accessing the server from outside:
Start COOJA and load the simulation "rest-server-example.csc" by the following command.
> make TARGET=cooja rest-server-example.csc
After loading the cooja file, in another terminal connect to the COOJA simulation using tunslip6:
>make connect-router-cooja
Now you need to use a COAP or HTTP client to interact with the COOJA nodes running REST code.
In this setting, two servers are available:
IP addresses are aaaa::0212:7402:0002:0202 and aaaa::0212:7403:0003:0303. COAP uses 61616, whereas HTTP uses 8080 port.

HTTP Examples
You can use curl as an http client to interact with the COOJA motes running REST code.
>curl -H "User-Agent: curl" aaaa::0212:7402:0002:0202:8080/helloworld #get helloworld plain text
>curl -H "User-Agent: curl" aaaa::0212:7402:0002:0202:8080/led?color=green -d mode=off -i #turn off the green led
>curl -H "User-Agent: curl" aaaa::0212:7402:0002:0202:8080/.well-known/core -i
>curl -X POST -H "User-Agent: curl" aaaa::0212:7402:0002:0202:8080/helloworld #method not allowed


Accessing the server inside the sensor network:
(Note: Provided only for COAP implementation)
Start COOJA and load the simulation "coap-client-server-example.csc" by the following command.
> make TARGET=cooja coap-client-server-example.csc
coap-client-server-example.csc : Runs rest-server-example as the server (over COAP) (IP:aaaa::0212:7401:0001:0101) in one node and coap-client-example as the client (IP: aaaa::0212:7402:0002:0202) in another node. 
Client periodically accesses resources of server and prints the payload.


To run REST server on real nodes under Linux
--------------------------------------------

1. Program the nodes with the rest-server-example
> make TARGET=sky rest-server-example.upload

2. Disconnect the nodes and program one node with the RPL border router
> (cd ../ipv6/rpl-border-router && make TARGET=sky border-router.upload)

3. Connect to the border router using tunslip6:
> make connect-router

4. Reconnect the motes, reboot them and note their IP addresses.

5. Remaining parts are the same with the COOJA example. (i.e. if it is a COAP Server, it is available at <NODE_IP_ADDR>:61616)