2010-11-29 12:55:35 +00:00
Open a terminal and go to "<CONTIKI_HOME>/examples/rest-example/" directory.
2010-10-28 12:42:07 +00:00
2010-11-24 10:10:48 +00:00
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.
2010-11-24 10:56:53 +00:00
Look at the source code to see which resources are available. (check the RESOURCE macros in the code).
Each resource has a handler function which is called by the REST layer to serve the request.
(i.e. "helloworld" resource has a handler function named "helloworld_handler" which is called when a web service request is received for "helloworld" resource.)
2010-10-28 12:42:07 +00:00
2010-11-24 10:10:48 +00:00
To run REST examples in COOJA under Linux
--------------------------------------------
2010-10-28 12:42:07 +00:00
2010-11-24 10:10:48 +00:00
Accessing the server from outside:
2010-11-30 13:22:26 +00:00
1. Start COOJA and load the simulation "rest-server-example.csc" by the following command.
make TARGET=cooja rest-server-example.csc
2010-11-29 12:55:35 +00:00
2010-11-30 13:22:26 +00:00
2. After loading the COOJA file, open another another terminal pointing to the same directory and connect to the COOJA simulation using tunslip6:
make connect-router-cooja
3. You need to use a COAP or HTTP client to interact with the COOJA nodes running REST code.
2010-11-24 10:10:48 +00:00
In this setting, two servers are available:
2010-11-24 10:56:53 +00:00
IP addresses are aaaa::0212:7402:0002:0202 and aaaa::0212:7403:0003:0303. COAP uses 61616, whereas HTTP uses 8080 port in default configuration.
2010-11-29 12:55:35 +00:00
First, ping the COOJA nodes to test the connectivity.
2010-11-30 13:22:26 +00:00
ping6 aaaa::0212:7402:0002:0202
ping6 aaaa::0212:7403:0003:0303
2010-10-28 12:42:07 +00:00
HTTP Examples
You can use curl as an http client to interact with the COOJA motes running REST code.
2010-11-30 13:22:26 +00:00
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
2010-11-24 10:10:48 +00:00
2010-11-29 12:55:35 +00:00
COAP Examples
You should run a COAP client on your computer. You can use the URLs and methods provided above in HTTP examples to test the COAP Server.
2010-11-24 10:10:48 +00:00
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.
2010-11-30 13:22:26 +00:00
make TARGET=cooja coap-client-server-example.csc
2010-11-24 10:56:53 +00:00
coap-client-server-example.csc : Runs rest-server-example.c as the server (over COAP) (IP:aaaa::0212:7401:0001:0101)
in one node and coap-client-example.c as the client (IP: aaaa::0212:7402:0002:0202) in another node.
2010-11-24 10:10:48 +00:00
Client periodically accesses resources of server and prints the payload.
2010-11-29 12:55:35 +00:00
Note: If the generated binary is bigger than the MOTE code size, then you will get a "region text is full" error.
Right now, REST+HTTP example uses (Contiki + ContikiMAC + uIPv6 + RPL + HTTP Server + REST Layer) which does not fit in Tmote Sky memory.
To save same code space and make the example fit, you can define static routes rather than using RPL or use nullrdc rather than ContikiMAC.
2010-11-24 10:10:48 +00:00
To run REST server on real nodes under Linux
--------------------------------------------
1. Program the nodes with the rest-server-example
2010-11-30 13:22:26 +00:00
make TARGET=sky rest-server-example.upload
2010-11-24 10:10:48 +00:00
2. Disconnect the nodes and program one node with the RPL border router
2010-11-30 13:22:26 +00:00
(cd ../ipv6/rpl-border-router && make TARGET=sky border-router.upload)
2010-11-24 10:10:48 +00:00
3. Connect to the border router using tunslip6:
2010-11-30 13:22:26 +00:00
make connect-router
2010-11-24 10:10:48 +00:00
4. Reconnect the motes, reboot them and note their IP addresses.
2010-10-28 12:42:07 +00:00
2010-11-29 12:55:35 +00:00
5. Test the connectivity by pinging them.
2010-11-30 13:22:26 +00:00
ping6 <IPv6 Address of the MOTE>
2010-11-29 12:55:35 +00:00
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)
2010-11-30 13:22:26 +00:00
To Do
*Better option handling needed - ex: critical options are not differentiated for now. Need to add support for some such as Tokens. Also, C/E difference should be added.
2010-11-29 12:55:35 +00:00
*Reilable message sending is missing. i.e. client example should resend request in case ACK does not arrive. Same for server pushing (in case of subscriptions)
*Add Block transfer example
*Add Subscription example
*Add an Android/Java COAP Client to Contikiprojects to be able to interact with Contiki.
*COAP-specific Method Codes