Updated file references and README.

This commit is contained in:
Matthias Kovatsch 2012-05-13 17:15:57 +02:00
parent 0038acfa87
commit 3dea97e247
6 changed files with 72 additions and 57 deletions

View file

@ -1,5 +1,5 @@
all: rest-server-example coap-client-example all: er-example-server er-example-client
# Use this target explicitly if requried: plugtest-server # Use this target explicitly if requried: er-plugtest-server
CONTIKI=../.. CONTIKI=../..
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"

View file

@ -1,35 +1,38 @@
This is the new example for the Erbium REST Engine A Quick Introduction to the Erbium (Er) REST Engine
================================================== ===================================================
EXAMPLE FILES EXAMPLE FILES
------------- -------------
rest-server-example.c: A RESTful server example showing how to use the REST layer to develop server-side applications (at the moment only CoAP is implemented for the REST Engine). er-example-server.c: A RESTful server example showing how to use the REST layer to develop server-side applications (at the moment only CoAP is implemented for the REST Engine).
coap-client-example.c: A CoAP client that polls the /toggle resource every 10 seconds and cycles through 4 resources on button press (target address is hard-coded). er-example-client.c: A CoAP client that polls the /actuators/toggle resource every 10 seconds and cycles through 4 resources on button press (target address is hard-coded).
er-plugtest-server.c: The server used for draft compliance testing at ETSI IoT CoAP Plugtest in Paris, France, March 2012 (configured for minimal-net).
PRELIMINARIES PRELIMINARIES
------------- -------------
a) Make sure rpl-border-router has the same stack and fits into mote memory: - Make sure rpl-border-router has the same stack and fits into mote memory:
Disable RDC in border-router project-conf.h You can disable RDC in border-router project-conf.h (not really required as BR keeps radio turned on).
#undef NETSTACK_CONF_RDC #undef NETSTACK_CONF_RDC
#define NETSTACK_CONF_RDC nullrdc_driver #define NETSTACK_CONF_RDC nullrdc_driver
b) For convenience, define the Cooja addresses in /etc/hosts - For convenience, define the Cooja addresses in /etc/hosts
aaaa::0212:7401:0001:0101 cooja1 aaaa::0212:7401:0001:0101 cooja1
aaaa::0212:7402:0002:0202 cooja2 aaaa::0212:7402:0002:0202 cooja2
... ...
c) Get the Copper CoAP browser from https://addons.mozilla.org/en-US/firefox/addon/copper-270430/ - Get the Copper (Cu) CoAP user-agent from https://addons.mozilla.org/en-US/firefox/addon/copper-270430/
d) Optional: Save your target as default target - Optional: Save your target as default target
$ make TARGET=sky savetarget $ make TARGET=sky savetarget
COOJA HOWTO COOJA HOWTO
----------- -----------
Server only: Server only:
1) $ make TARGET=cooja rest-server-example.csc 1) $ make TARGET=cooja server-only.csc
2) Open new terminal 2) Open new terminal
3) $ make connect-router-cooja 3) $ make connect-router-cooja
4) Start Copper and discover resources at coap://cooja2:5683/ 4) Start Copper and discover resources at coap://cooja2:5683/
- Choose "Click button on Sky 2" from the context menu of mote 2 (server) after requesting /test/separate
- Do the same when observing /test/event
With client: With client:
1) $ make TARGET=cooja coap-client-server-example.csc 1) $ make TARGET=cooja server-client.csc
2) Open new terminal 2) Open new terminal
3) $ make connect-router-cooja 3) $ make connect-router-cooja
4) Wait until red LED toggles on mote 2 (server) 4) Wait until red LED toggles on mote 2 (server)
@ -39,7 +42,7 @@ TMOTES HOWTO
------------ ------------
Server: Server:
1) Connect two Tmote Skys (check with $ make TARGET=sky sky-motelist) 1) Connect two Tmote Skys (check with $ make TARGET=sky sky-motelist)
2) $ make TARGET=sky rest-server-example.upload MOTE=2 2) $ make TARGET=sky er-example-server.upload MOTE=2
3) $ make TARGET=sky login MOTE=2 3) $ make TARGET=sky login MOTE=2
4) Press reset button, get address, abort with Ctrl+C: 4) Press reset button, get address, abort with Ctrl+C:
Line: "Tentative link-local IPv6 address fe80:0000:0000:0000:____:____:____:____" Line: "Tentative link-local IPv6 address fe80:0000:0000:0000:____:____:____:____"
@ -50,27 +53,27 @@ Server:
8) Start Copper and discover resources at coap://[aaaa::____:____:____:____]:5683/ 8) Start Copper and discover resources at coap://[aaaa::____:____:____:____]:5683/
Add a client: Add a client:
1) Change the hard-coded server address in coap-client-example.c to aaaa::____:____:____:____ 1) Change the hard-coded server address in er-example-client.c to aaaa::____:____:____:____
2) Connect a third Tmote Sky 2) Connect a third Tmote Sky
3) $ make TARGET=sky coap-client-example.upload MOTE=3 3) $ make TARGET=sky er-example-client.upload MOTE=3
DETAILS DETAILS
------- -------
The Erbium CoAP currently implements draft 08 (name "er-coap-07" stems from last technical draft changes). Erbium currently implements draft 08 (name "er-coap-07" stems from last technical draft changes).
Central features are commented in rest-server-example.c. Central features are commented in er-example-server.c.
In general, apps/er-coap-07 supports: In general, apps/er-coap-07 supports:
* All draft 08 header options * All draft 08 header options
* CON Retransmissions (note COAP_MAX_OPEN_TRANSACTIONS) * CON Retransmissions (note COAP_MAX_OPEN_TRANSACTIONS)
* Blockwise Transfers (note REST_MAX_CHUNK_SIZE) * Blockwise Transfers (note REST_MAX_CHUNK_SIZE, see er-plugtest-server.c for Block1 uploads)
* Separate Responses (see rest_set_pre_handler() and coap_separate_handler()) * Separate Responses (no rest_set_pre_handler() required anymore, note coap_separate_accept(), _reject(), and _resume())
* Resource discovery * Resource Discovery
* Observing Resources (see EVENT_ and PRERIODIC_RESOURCE, note COAP_MAX_OBSERVERS) * Observing Resources (see EVENT_ and PRERIODIC_RESOURCE, note COAP_MAX_OBSERVERS)
REST IMPLEMENTATIONS REST IMPLEMENTATIONS
-------------------- --------------------
The Makefile uses WITH_COAP to configure different implementations for the Erbium REST Engine. The Makefile uses WITH_COAP to configure different implementations for the Erbium (Er) REST Engine.
* WITH_COAP=7 uses Erbium CoAP 07 apps/er-coap-07/. * WITH_COAP=7 uses Erbium CoAP 08 apps/er-coap-07/.
The default port for coap-07 is 5683. The default port for coap-07/-08 is 5683.
* WITH_COAP=3 uses Erbium CoAP 03 apps/er-coap-03/. * WITH_COAP=3 uses Erbium CoAP 03 apps/er-coap-03/.
The default port for coap-03 is 61616. The default port for coap-03 is 61616.
er-coap-03 produces some warnings, as it not fully maintained anymore. er-coap-03 produces some warnings, as it not fully maintained anymore.
@ -78,6 +81,6 @@ The Makefile uses WITH_COAP to configure different implementations for the Erbiu
TODOs TODOs
----- -----
* Blockwise uploads (for POST/PUT payload) * Observe client
* Multiple If-Match ETags * Multiple If-Match ETags
* (Message deduplication) * (Message deduplication)

View file

@ -31,7 +31,7 @@
/** /**
* \file * \file
* CoAP client example * Erbium (Er) CoAP client example
* \author * \author
* Matthias Kovatsch <kovatsch@inf.ethz.ch> * Matthias Kovatsch <kovatsch@inf.ethz.ch>
*/ */

View file

@ -31,7 +31,7 @@
/** /**
* \file * \file
* Example for the CoAP REST Engine * Erbium (Er) REST Engine example (with CoAP-specific code)
* \author * \author
* Matthias Kovatsch <kovatsch@inf.ethz.ch> * Matthias Kovatsch <kovatsch@inf.ethz.ch>
*/ */
@ -88,7 +88,7 @@
#elif WITH_COAP == 7 #elif WITH_COAP == 7
#include "er-coap-07.h" #include "er-coap-07.h"
#else #else
#warning "REST example without CoAP" #warning "Erbium example without CoAP-specifc functionality"
#endif /* CoAP-specific example */ #endif /* CoAP-specific example */
#define DEBUG 0 #define DEBUG 0
@ -102,7 +102,7 @@
#define PRINTLLADDR(addr) #define PRINTLLADDR(addr)
#endif #endif
/******************************************************************************/
#if REST_RES_HELLO #if REST_RES_HELLO
/* /*
* Resources are defined by the RESOURCE macro. * Resources are defined by the RESOURCE macro.
@ -140,6 +140,7 @@ helloworld_handler(void* request, void* response, uint8_t *buffer, uint16_t pref
} }
#endif #endif
/******************************************************************************/
#if REST_RES_MIRROR #if REST_RES_MIRROR
/* This resource mirrors the incoming request. It shows how to access the options and how to set them for the response. */ /* This resource mirrors the incoming request. It shows how to access the options and how to set them for the response. */
RESOURCE(mirror, METHOD_GET | METHOD_POST | METHOD_PUT | METHOD_DELETE, "debug/mirror", "title=\"Returns your decoded message\";rt=\"Debug\""); RESOURCE(mirror, METHOD_GET | METHOD_POST | METHOD_PUT | METHOD_DELETE, "debug/mirror", "title=\"Returns your decoded message\";rt=\"Debug\"");
@ -290,6 +291,7 @@ mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
} }
#endif /* REST_RES_MIRROR */ #endif /* REST_RES_MIRROR */
/******************************************************************************/
#if REST_RES_CHUNKS #if REST_RES_CHUNKS
/* /*
* For data larger than REST_MAX_CHUNK_SIZE (e.g., stored in flash) resources must be aware of the buffer limitation * For data larger than REST_MAX_CHUNK_SIZE (e.g., stored in flash) resources must be aware of the buffer limitation
@ -298,7 +300,7 @@ mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
* These chunk-wise resources must set the offset value to its new position or -1 of the end is reached. * These chunk-wise resources must set the offset value to its new position or -1 of the end is reached.
* (The offset for CoAP's blockwise transfer can go up to 2'147'481'600 = ~2047 M for block size 2048 (reduced to 1024 in observe-03.) * (The offset for CoAP's blockwise transfer can go up to 2'147'481'600 = ~2047 M for block size 2048 (reduced to 1024 in observe-03.)
*/ */
RESOURCE(chunks, METHOD_GET, "debug/chunks", "title=\"Blockwise demo\";rt=\"Data\""); RESOURCE(chunks, METHOD_GET, "test/chunks", "title=\"Blockwise demo\";rt=\"Data\"");
#define CHUNKS_TOTAL 2050 #define CHUNKS_TOTAL 2050
@ -349,7 +351,8 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
} }
#endif #endif
#if defined (PLATFORM_HAS_BUTTON) && REST_RES_SEPARATE && WITH_COAP > 3 /******************************************************************************/
#if REST_RES_SEPARATE && defined (PLATFORM_HAS_BUTTON) && WITH_COAP > 3
/* Required to manually (=not by the engine) handle the response transaction. */ /* Required to manually (=not by the engine) handle the response transaction. */
#include "er-coap-07-separate.h" #include "er-coap-07-separate.h"
#include "er-coap-07-transactions.h" #include "er-coap-07-transactions.h"
@ -359,7 +362,7 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
* The pre-handler takes care of the empty ACK and updates the MID and message type for CON requests. * The pre-handler takes care of the empty ACK and updates the MID and message type for CON requests.
* The resource handler must store all information that required to finalize the response later. * The resource handler must store all information that required to finalize the response later.
*/ */
RESOURCE(separate, METHOD_GET, "debug/separate", "title=\"Separate demo\""); RESOURCE(separate, METHOD_GET, "test/separate", "title=\"Separate demo\"");
/* A structure to store the required information */ /* A structure to store the required information */
typedef struct application_separate_store { typedef struct application_separate_store {
@ -439,13 +442,14 @@ separate_finalize_handler()
} }
#endif #endif
/******************************************************************************/
#if REST_RES_PUSHING #if REST_RES_PUSHING
/* /*
* Example for a periodic resource. * Example for a periodic resource.
* It takes an additional period parameter, which defines the interval to call [name]_periodic_handler(). * It takes an additional period parameter, which defines the interval to call [name]_periodic_handler().
* A default post_handler takes care of subscriptions by managing a list of subscribers to notify. * A default post_handler takes care of subscriptions by managing a list of subscribers to notify.
*/ */
PERIODIC_RESOURCE(pushing, METHOD_GET, "debug/push", "title=\"Periodic demo\";obs", 5*CLOCK_SECOND); PERIODIC_RESOURCE(pushing, METHOD_GET, "test/push", "title=\"Periodic demo\";obs", 5*CLOCK_SECOND);
void void
pushing_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) pushing_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
@ -483,7 +487,8 @@ pushing_periodic_handler(resource_t *r)
} }
#endif #endif
#if defined (PLATFORM_HAS_BUTTON) && REST_RES_EVENT /******************************************************************************/
#if REST_RES_EVENT && defined (PLATFORM_HAS_BUTTON)
/* /*
* Example for an event resource. * Example for an event resource.
* Additionally takes a period parameter that defines the interval to call [name]_periodic_handler(). * Additionally takes a period parameter that defines the interval to call [name]_periodic_handler().
@ -524,7 +529,9 @@ event_event_handler(resource_t *r)
} }
#endif /* PLATFORM_HAS_BUTTON */ #endif /* PLATFORM_HAS_BUTTON */
/******************************************************************************/
#if defined (PLATFORM_HAS_LEDS) #if defined (PLATFORM_HAS_LEDS)
/******************************************************************************/
#if REST_RES_LEDS #if REST_RES_LEDS
/*A simple actuator example, depending on the color query parameter and post variable mode, corresponding led is activated or deactivated*/ /*A simple actuator example, depending on the color query parameter and post variable mode, corresponding led is activated or deactivated*/
RESOURCE(leds, METHOD_POST | METHOD_PUT , "actuators/leds", "title=\"LEDs: ?color=r|g|b, POST/PUT mode=on|off\";rt=\"Control\""); RESOURCE(leds, METHOD_POST | METHOD_PUT , "actuators/leds", "title=\"LEDs: ?color=r|g|b, POST/PUT mode=on|off\";rt=\"Control\"");
@ -574,6 +581,7 @@ leds_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_
} }
#endif #endif
/******************************************************************************/
#if REST_RES_TOGGLE #if REST_RES_TOGGLE
/* A simple actuator example. Toggles the red led */ /* A simple actuator example. Toggles the red led */
RESOURCE(toggle, METHOD_GET | METHOD_PUT | METHOD_POST, "actuators/toggle", "title=\"Red LED\";rt=\"Control\""); RESOURCE(toggle, METHOD_GET | METHOD_PUT | METHOD_POST, "actuators/toggle", "title=\"Red LED\";rt=\"Control\"");
@ -585,7 +593,8 @@ toggle_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
#endif #endif
#endif /* PLATFORM_HAS_LEDS */ #endif /* PLATFORM_HAS_LEDS */
#if defined (PLATFORM_HAS_LIGHT) && REST_RES_LIGHT /******************************************************************************/
#if REST_RES_LIGHT && defined (PLATFORM_HAS_LIGHT)
/* A simple getter example. Returns the reading from light sensor with a simple etag */ /* A simple getter example. Returns the reading from light sensor with a simple etag */
RESOURCE(light, METHOD_GET, "sensors/light", "title=\"Photosynthetic and solar light (supports JSON)\";rt=\"LightSensor\""); RESOURCE(light, METHOD_GET, "sensors/light", "title=\"Photosynthetic and solar light (supports JSON)\";rt=\"LightSensor\"");
void void
@ -627,7 +636,8 @@ light_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred
} }
#endif /* PLATFORM_HAS_LIGHT */ #endif /* PLATFORM_HAS_LIGHT */
#if defined (PLATFORM_HAS_BATTERY) && REST_RES_BATTERY /******************************************************************************/
#if REST_RES_BATTERY && defined (PLATFORM_HAS_BATTERY)
/* A simple getter example. Returns the reading from light sensor with a simple etag */ /* A simple getter example. Returns the reading from light sensor with a simple etag */
RESOURCE(battery, METHOD_GET, "sensors/battery", "title=\"Battery status\";rt=\"Battery\""); RESOURCE(battery, METHOD_GET, "sensors/battery", "title=\"Battery status\";rt=\"Battery\"");
void void
@ -661,14 +671,16 @@ battery_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
} }
#endif /* PLATFORM_HAS_BATTERY */ #endif /* PLATFORM_HAS_BATTERY */
PROCESS(rest_server_example, "Rest Server Example");
PROCESS(rest_server_example, "Erbium Example Server");
AUTOSTART_PROCESSES(&rest_server_example); AUTOSTART_PROCESSES(&rest_server_example);
PROCESS_THREAD(rest_server_example, ev, data) PROCESS_THREAD(rest_server_example, ev, data)
{ {
PROCESS_BEGIN(); PROCESS_BEGIN();
PRINTF("Rest Example\n"); PRINTF("Starting Erbium Example Server\n");
#ifdef RF_CHANNEL #ifdef RF_CHANNEL
PRINTF("RF channel: %u\n", RF_CHANNEL); PRINTF("RF channel: %u\n", RF_CHANNEL);
@ -683,7 +695,7 @@ PROCESS_THREAD(rest_server_example, ev, data)
PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE);
/* if static routes are used rather than RPL */ /* if static routes are used rather than RPL */
#if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) #if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE)
set_global_address(); set_global_address();
configure_routing(); configure_routing();
#endif #endif

View file

@ -45,11 +45,11 @@
</motetype> </motetype>
<motetype> <motetype>
se.sics.cooja.mspmote.SkyMoteType se.sics.cooja.mspmote.SkyMoteType
<identifier>skyweb</identifier> <identifier>server</identifier>
<description>CoAP Server</description> <description>Erbium Server</description>
<source EXPORT="discard">[CONTIKI_DIR]/examples/er-rest-example/rest-server-example.c</source> <source EXPORT="discard">[CONTIKI_DIR]/examples/er-rest-example/er-example-server.c</source>
<commands EXPORT="discard">make rest-server-example.sky TARGET=sky</commands> <commands EXPORT="discard">make er-example-server.sky TARGET=sky</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/er-rest-example/rest-server-example.sky</firmware> <firmware EXPORT="copy">[CONTIKI_DIR]/examples/er-rest-example/er-example-server.sky</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface> <moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface> <moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface> <moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
@ -68,11 +68,11 @@
</motetype> </motetype>
<motetype> <motetype>
se.sics.cooja.mspmote.SkyMoteType se.sics.cooja.mspmote.SkyMoteType
<identifier>sky1</identifier> <identifier>client</identifier>
<description>CoAP Client</description> <description>Erbium Client</description>
<source EXPORT="discard">[CONTIKI_DIR]/examples/er-rest-example/coap-client-example.c</source> <source EXPORT="discard">[CONTIKI_DIR]/examples/er-rest-example/er-example-client.c</source>
<commands EXPORT="discard">make coap-client-example.sky TARGET=sky</commands> <commands EXPORT="discard">make er-example-client.sky TARGET=sky</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/er-rest-example/coap-client-example.sky</firmware> <firmware EXPORT="copy">[CONTIKI_DIR]/examples/er-rest-example/er-example-client.sky</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface> <moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface> <moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface> <moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
@ -115,7 +115,7 @@
se.sics.cooja.mspmote.interfaces.MspMoteID se.sics.cooja.mspmote.interfaces.MspMoteID
<id>2</id> <id>2</id>
</interface_config> </interface_config>
<motetype_identifier>skyweb</motetype_identifier> <motetype_identifier>server</motetype_identifier>
</mote> </mote>
<mote> <mote>
<breakpoints /> <breakpoints />
@ -129,7 +129,7 @@
se.sics.cooja.mspmote.interfaces.MspMoteID se.sics.cooja.mspmote.interfaces.MspMoteID
<id>3</id> <id>3</id>
</interface_config> </interface_config>
<motetype_identifier>sky1</motetype_identifier> <motetype_identifier>client</motetype_identifier>
</mote> </mote>
</simulation> </simulation>
<plugin> <plugin>

View file

@ -45,11 +45,11 @@
</motetype> </motetype>
<motetype> <motetype>
se.sics.cooja.mspmote.SkyMoteType se.sics.cooja.mspmote.SkyMoteType
<identifier>skyweb</identifier> <identifier>server</identifier>
<description>Rest</description> <description>Erbium Server</description>
<source EXPORT="discard">[CONTIKI_DIR]/examples/er-rest-example/rest-server-example.c</source> <source EXPORT="discard">[CONTIKI_DIR]/examples/er-rest-example/er-example-server.c</source>
<commands EXPORT="discard">make rest-server-example.sky TARGET=sky</commands> <commands EXPORT="discard">make er-example-server.sky TARGET=sky</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/er-rest-example/rest-server-example.sky</firmware> <firmware EXPORT="copy">[CONTIKI_DIR]/examples/er-rest-example/er-example-server.sky</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface> <moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface> <moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface> <moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
@ -92,7 +92,7 @@
se.sics.cooja.mspmote.interfaces.MspMoteID se.sics.cooja.mspmote.interfaces.MspMoteID
<id>2</id> <id>2</id>
</interface_config> </interface_config>
<motetype_identifier>skyweb</motetype_identifier> <motetype_identifier>server</motetype_identifier>
</mote> </mote>
</simulation> </simulation>
<plugin> <plugin>