Added more details to README and small printing modification in client example.

This commit is contained in:
doganyazar 2010-11-24 10:56:53 +00:00
parent 726f927c40
commit d14e8996ab
2 changed files with 9 additions and 6 deletions

View File

@ -4,6 +4,8 @@ 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).
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.)
To run REST examples in COOJA under Linux
@ -12,11 +14,11 @@ 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:
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
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.
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.
HTTP Examples
You can use curl as an http client to interact with the COOJA motes running REST code.
@ -30,7 +32,8 @@ 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.
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.
Client periodically accesses resources of server and prints the payload.

View File

@ -9,7 +9,7 @@
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
#define PRINT6ADDR(addr) PRINTF("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",(lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3],(lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)