remove unused code, bugfix const
This commit is contained in:
parent
ef5b9474fd
commit
080eadc79b
|
@ -1,4 +1,4 @@
|
||||||
all: er-example-server er-example-client
|
all: er-example-server
|
||||||
# Use this target explicitly if requried: er-plugtest-server
|
# Use this target explicitly if requried: er-plugtest-server
|
||||||
|
|
||||||
CONTIKI=../../..
|
CONTIKI=../../..
|
||||||
|
|
|
@ -48,19 +48,13 @@
|
||||||
#define REST_RES_DS1820 1
|
#define REST_RES_DS1820 1
|
||||||
#define REST_RES_DHT11 1
|
#define REST_RES_DHT11 1
|
||||||
#define REST_RES_TEMPERATURE 1
|
#define REST_RES_TEMPERATURE 1
|
||||||
#define REST_RES_HELLO 0
|
|
||||||
#define REST_RES_MIRROR 0 /* causes largest code size */
|
|
||||||
#define REST_RES_CHUNKS 0
|
#define REST_RES_CHUNKS 0
|
||||||
#define REST_RES_SEPARATE 0
|
#define REST_RES_SEPARATE 0
|
||||||
#define REST_RES_PUSHING 0
|
#define REST_RES_PUSHING 0
|
||||||
#define REST_RES_EVENT 0
|
#define REST_RES_EVENT 0
|
||||||
#define REST_RES_SUB 0
|
|
||||||
#define REST_RES_LEDS 0
|
#define REST_RES_LEDS 0
|
||||||
#define REST_RES_TOGGLE 0
|
#define REST_RES_TOGGLE 0
|
||||||
#define REST_RES_LIGHT 0
|
|
||||||
#define REST_RES_BATTERY 1
|
#define REST_RES_BATTERY 1
|
||||||
#define REST_RES_RADIO 0
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE)
|
#if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE)
|
||||||
|
@ -87,9 +81,6 @@ uint8_t dht11_temp=0, dht11_hum=0;
|
||||||
#if defined (PLATFORM_HAS_LEDS)
|
#if defined (PLATFORM_HAS_LEDS)
|
||||||
#include "dev/leds.h"
|
#include "dev/leds.h"
|
||||||
#endif
|
#endif
|
||||||
#if defined (PLATFORM_HAS_LIGHT)
|
|
||||||
#include "dev/light-sensor.h"
|
|
||||||
#endif
|
|
||||||
#if defined (PLATFORM_HAS_TEMPERATURE)
|
#if defined (PLATFORM_HAS_TEMPERATURE)
|
||||||
#include "dev/temperature-sensor.h"
|
#include "dev/temperature-sensor.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -99,9 +90,6 @@ uint8_t dht11_temp=0, dht11_hum=0;
|
||||||
#if defined (PLATFORM_HAS_SHT11)
|
#if defined (PLATFORM_HAS_SHT11)
|
||||||
#include "dev/sht11-sensor.h"
|
#include "dev/sht11-sensor.h"
|
||||||
#endif
|
#endif
|
||||||
#if defined (PLATFORM_HAS_RADIO)
|
|
||||||
#include "dev/radio-sensor.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* For CoAP-specific example: not required for normal RESTful Web service. */
|
/* For CoAP-specific example: not required for normal RESTful Web service. */
|
||||||
|
@ -125,9 +113,6 @@ uint8_t dht11_temp=0, dht11_hum=0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "dev/key.c" // todo: move platform /dev
|
|
||||||
#include "dev/led.c"
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
#if REST_RES_INFO
|
#if REST_RES_INFO
|
||||||
|
@ -164,59 +149,9 @@ info_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// mybutton
|
|
||||||
/*A simple actuator example. read the key button status*/
|
|
||||||
//RESOURCE(button, METHOD_GET | METHOD_PUT , "sensors/button", "title=\"Button\";rt=\"button\"");
|
|
||||||
RESOURCE(button, METHOD_GET | METHOD_PUT , "sensors/button", "title=\"Button\";rt=\"button\"");
|
|
||||||
void
|
|
||||||
button_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
|
||||||
{
|
|
||||||
static char bname[17]="button1";
|
|
||||||
int success = 1;
|
|
||||||
|
|
||||||
char temp[100];
|
|
||||||
int index = 0;
|
|
||||||
int length = 0; /* |<-------->| */
|
|
||||||
const char *name = NULL;
|
|
||||||
size_t len = 0;
|
|
||||||
|
|
||||||
switch(REST.get_method_type(request)){
|
|
||||||
case METHOD_GET:
|
|
||||||
// jSON Format
|
|
||||||
index += sprintf(temp + index,"{\n \"name\" : \"%s\",\n",bname);
|
|
||||||
if(is_button())
|
|
||||||
index += sprintf(temp + index," \"state\" : \"on\"\n");
|
|
||||||
else
|
|
||||||
index += sprintf(temp + index," \"state\" : \"off\"\n");
|
|
||||||
index += sprintf(temp + index,"}\n");
|
|
||||||
|
|
||||||
length = strlen(temp);
|
|
||||||
memcpy(buffer, temp,length );
|
|
||||||
|
|
||||||
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
|
|
||||||
REST.set_response_payload(response, buffer, length);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case METHOD_PUT:
|
|
||||||
|
|
||||||
if (success && (len=REST.get_post_variable(request, "name", &name))) {
|
|
||||||
PRINTF("name %s\n", name);
|
|
||||||
memcpy(bname, name,len);
|
|
||||||
bname[len]=0;
|
|
||||||
} else {
|
|
||||||
success = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
success = 0;
|
|
||||||
}
|
|
||||||
if (!success) {
|
|
||||||
REST.set_response_status(response, REST.status.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*A simple actuator example, post variable mode, relay is activated or deactivated*/
|
/*A simple actuator example, post variable mode, relay is activated or deactivated*/
|
||||||
RESOURCE(led1, METHOD_GET | METHOD_PUT , "aktors/led1", "title=\"Led1\";rt=\"led\"");
|
RESOURCE(led1, METHOD_GET | METHOD_PUT , "actors/led1", "title=\"Led1\";rt=\"led\"");
|
||||||
void
|
void
|
||||||
led1_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
led1_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||||
{
|
{
|
||||||
|
@ -291,16 +226,15 @@ ds1820_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
|
||||||
|
|
||||||
char message[100];
|
char message[100];
|
||||||
int length = 0; /* |<-------->| */
|
int length = 0; /* |<-------->| */
|
||||||
int ret=0;
|
|
||||||
int grad=0;
|
int grad=0;
|
||||||
int kgrad=0;
|
int kgrad=0;
|
||||||
// ret=ds1820_temp();
|
|
||||||
if(ds1820_ok[0] & 0x01){
|
if(ds1820_ok[0] & 0x01){
|
||||||
kgrad=5;
|
kgrad=5;
|
||||||
}
|
}
|
||||||
grad = (int)((ds1820_ok[1] << 8) | (ds1820_ok[0])) >> 1;
|
grad = (int)((ds1820_ok[1] << 8) | (ds1820_ok[0])) >> 1;
|
||||||
|
|
||||||
uint16_t *accept = NULL;
|
const uint16_t *accept = NULL;
|
||||||
int num = REST.get_header_accept(request, &accept);
|
int num = REST.get_header_accept(request, &accept);
|
||||||
|
|
||||||
if ((num==0) || (num && accept[0]==REST.type.TEXT_PLAIN))
|
if ((num==0) || (num && accept[0]==REST.type.TEXT_PLAIN))
|
||||||
|
@ -339,11 +273,8 @@ dht11_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred
|
||||||
{
|
{
|
||||||
char message[100];
|
char message[100];
|
||||||
int length = 0; /* |<-------->| */
|
int length = 0; /* |<-------->| */
|
||||||
int ret=0;
|
|
||||||
// dht11_temp=DHT_Read_Data(DHT_Temp);
|
|
||||||
// dht11_hum=DHT_Read_Data(DHT_RH);
|
|
||||||
|
|
||||||
uint16_t *accept = NULL;
|
const uint16_t *accept = NULL;
|
||||||
int num = REST.get_header_accept(request, &accept);
|
int num = REST.get_header_accept(request, &accept);
|
||||||
|
|
||||||
if ((num==0) || (num && accept[0]==REST.type.TEXT_PLAIN))
|
if ((num==0) || (num && accept[0]==REST.type.TEXT_PLAIN))
|
||||||
|
@ -374,194 +305,6 @@ dht11_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred
|
||||||
}
|
}
|
||||||
#endif //REST_RES_DHT11
|
#endif //REST_RES_DHT11
|
||||||
|
|
||||||
#if REST_RES_HELLO
|
|
||||||
/*
|
|
||||||
* Resources are defined by the RESOURCE macro.
|
|
||||||
* Signature: resource name, the RESTful methods it handles, and its URI path (omitting the leading slash).
|
|
||||||
*/
|
|
||||||
RESOURCE(helloworld, METHOD_GET, "hello", "title=\"Hello world: ?len=0..\";rt=\"Text\"");
|
|
||||||
|
|
||||||
/*
|
|
||||||
* A handler function named [resource name]_handler must be implemented for each RESOURCE.
|
|
||||||
* A buffer for the response payload is provided through the buffer pointer. Simple resources can ignore
|
|
||||||
* preferred_size and offset, but must respect the REST_MAX_CHUNK_SIZE limit for the buffer.
|
|
||||||
* If a smaller block size is requested for CoAP, the REST framework automatically splits the data.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
helloworld_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
|
||||||
{
|
|
||||||
const char *len = NULL;
|
|
||||||
/* Some data that has the length up to REST_MAX_CHUNK_SIZE. For more, see the chunk resource. */
|
|
||||||
char const * const message = "Hello World! ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxy";
|
|
||||||
int length = 12; /* |<-------->| */
|
|
||||||
|
|
||||||
/* The query string can be retrieved by rest_get_query() or parsed for its key-value pairs. */
|
|
||||||
if (REST.get_query_variable(request, "len", &len)) {
|
|
||||||
length = atoi(len);
|
|
||||||
if (length<0) length = 0;
|
|
||||||
if (length>REST_MAX_CHUNK_SIZE) length = REST_MAX_CHUNK_SIZE;
|
|
||||||
memcpy(buffer, message, length);
|
|
||||||
} else {
|
|
||||||
memcpy(buffer, message, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN); /* text/plain is the default, hence this option could be omitted. */
|
|
||||||
REST.set_header_etag(response, (uint8_t *) &length, 1);
|
|
||||||
REST.set_response_payload(response, buffer, length);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
#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. */
|
|
||||||
RESOURCE(mirror, METHOD_GET | METHOD_POST | METHOD_PUT | METHOD_DELETE, "debug/mirror", "title=\"Returns your decoded message\";rt=\"Debug\"");
|
|
||||||
|
|
||||||
void
|
|
||||||
mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
|
||||||
{
|
|
||||||
/* The ETag and Token is copied to the header. */
|
|
||||||
uint8_t opaque[] = {0x0A, 0xBC, 0xDE};
|
|
||||||
|
|
||||||
/* Strings are not copied, so use static string buffers or strings in .text memory (char *str = "string in .text";). */
|
|
||||||
static char location[] = {'/','f','/','a','?','k','&','e', 0};
|
|
||||||
|
|
||||||
/* Getter for the header option Content-Type. If the option is not set, text/plain is returned by default. */
|
|
||||||
unsigned int content_type = REST.get_header_content_type(request);
|
|
||||||
|
|
||||||
/* The other getters copy the value (or string/array pointer) to the given pointers and return 1 for success or the length of strings/arrays. */
|
|
||||||
uint32_t max_age = 0;
|
|
||||||
const char *str = NULL;
|
|
||||||
uint32_t observe = 0;
|
|
||||||
const uint8_t *bytes = NULL;
|
|
||||||
uint32_t block_num = 0;
|
|
||||||
uint8_t block_more = 0;
|
|
||||||
uint16_t block_size = 0;
|
|
||||||
const char *query = "";
|
|
||||||
int len = 0;
|
|
||||||
|
|
||||||
/* Mirror the received header options in the response payload. Unsupported getters (e.g., rest_get_header_observe() with HTTP) will return 0. */
|
|
||||||
|
|
||||||
int strpos = 0;
|
|
||||||
/* snprintf() counts the terminating '\0' to the size parameter.
|
|
||||||
* The additional byte is taken care of by allocating REST_MAX_CHUNK_SIZE+1 bytes in the REST framework.
|
|
||||||
* Add +1 to fill the complete buffer. */
|
|
||||||
strpos += snprintf((char *)buffer, REST_MAX_CHUNK_SIZE+1, "CT %u\n", content_type);
|
|
||||||
|
|
||||||
/* Some getters such as for ETag or Location are omitted, as these options should not appear in a request.
|
|
||||||
* Max-Age might appear in HTTP requests or used for special purposes in CoAP. */
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && REST.get_header_max_age(request, &max_age))
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "MA %lu\n", max_age);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && (len = REST.get_header_host(request, &str)))
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "UH %.*s\n", len, str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* CoAP-specific example: actions not required for normal RESTful Web service. */
|
|
||||||
#if WITH_COAP > 1
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && coap_get_header_observe(request, &observe))
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "Ob %lu\n", observe);
|
|
||||||
}
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && (len = coap_get_header_token(request, &bytes)))
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "To 0x");
|
|
||||||
int index = 0;
|
|
||||||
for (index = 0; index<len; ++index) {
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "%02X", bytes[index]);
|
|
||||||
}
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "\n");
|
|
||||||
}
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && (len = coap_get_header_etag(request, &bytes)))
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "ET 0x");
|
|
||||||
int index = 0;
|
|
||||||
for (index = 0; index<len; ++index) {
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "%02X", bytes[index]);
|
|
||||||
}
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "\n");
|
|
||||||
}
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && (len = coap_get_header_uri_path(request, &str)))
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "UP ");
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "%.*s\n", len, str);
|
|
||||||
}
|
|
||||||
#if WITH_COAP == 3
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && (len = coap_get_header_location(request, &str)))
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "Lo %.*s\n", len, str);
|
|
||||||
}
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && coap_get_header_block(request, &block_num, &block_more, &block_size, NULL)) /* This getter allows NULL pointers to get only a subset of the block parameters. */
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "Bl %lu%s (%u)\n", block_num, block_more ? "+" : "", block_size);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && (len = coap_get_header_location_path(request, &str)))
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "LP %.*s\n", len, str);
|
|
||||||
}
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && (len = coap_get_header_location_query(request, &str)))
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "LQ %.*s\n", len, str);
|
|
||||||
}
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && coap_get_header_block2(request, &block_num, &block_more, &block_size, NULL)) /* This getter allows NULL pointers to get only a subset of the block parameters. */
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "B2 %lu%s (%u)\n", block_num, block_more ? "+" : "", block_size);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Critical Block1 option is currently rejected by engine.
|
|
||||||
*
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && coap_get_header_block1(request, &block_num, &block_more, &block_size, NULL))
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "B1 %lu%s (%u)\n", block_num, block_more ? "+" : "", block_size);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
#endif /* CoAP > 03 */
|
|
||||||
#endif /* CoAP-specific example */
|
|
||||||
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && (len = REST.get_query(request, &query)))
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "Qu %.*s\n", len, query);
|
|
||||||
}
|
|
||||||
if (strpos<=REST_MAX_CHUNK_SIZE && (len = REST.get_request_payload(request, &bytes)))
|
|
||||||
{
|
|
||||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "%.*s", len, bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strpos >= REST_MAX_CHUNK_SIZE)
|
|
||||||
{
|
|
||||||
buffer[REST_MAX_CHUNK_SIZE-1] = 0xBB; /* '»' to indicate truncation */
|
|
||||||
}
|
|
||||||
|
|
||||||
REST.set_response_payload(response, buffer, strpos);
|
|
||||||
|
|
||||||
PRINTF("/mirror options received: %s\n", buffer);
|
|
||||||
|
|
||||||
/* Set dummy header options for response. Like getters, some setters are not implemented for HTTP and have no effect. */
|
|
||||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
|
||||||
REST.set_header_max_age(response, 10); /* For HTTP, browsers will not re-request the page for 10 seconds. CoAP action depends on the client. */
|
|
||||||
REST.set_header_etag(response, opaque, 2);
|
|
||||||
REST.set_header_location(response, location); /* Initial slash is omitted by framework */
|
|
||||||
|
|
||||||
/* CoAP-specific example: actions not required for normal RESTful Web service. */
|
|
||||||
#if WITH_COAP > 1
|
|
||||||
coap_set_header_uri_host(response, "tiki");
|
|
||||||
coap_set_header_observe(response, 10);
|
|
||||||
#if WITH_COAP == 3
|
|
||||||
coap_set_header_block(response, 42, 0, 64); /* The block option might be overwritten by the framework when blockwise transfer is requested. */
|
|
||||||
#else
|
|
||||||
coap_set_header_proxy_uri(response, "ftp://x");
|
|
||||||
coap_set_header_block2(response, 42, 0, 64); /* The block option might be overwritten by the framework when blockwise transfer is requested. */
|
|
||||||
coap_set_header_block1(response, 23, 0, 16);
|
|
||||||
coap_set_header_accept(response, TEXT_PLAIN);
|
|
||||||
coap_set_header_if_none_match(response);
|
|
||||||
#endif /* CoAP > 03 */
|
|
||||||
#endif /* CoAP-specific example */
|
|
||||||
}
|
|
||||||
#endif /* REST_RES_MIRROR */
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
#if REST_RES_CHUNKS
|
#if REST_RES_CHUNKS
|
||||||
/*
|
/*
|
||||||
|
@ -800,35 +543,6 @@ event_event_handler(resource_t *r)
|
||||||
}
|
}
|
||||||
#endif /* PLATFORM_HAS_BUTTON */
|
#endif /* PLATFORM_HAS_BUTTON */
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
#if REST_RES_SUB
|
|
||||||
/*
|
|
||||||
* Example for a resource that also handles all its sub-resources.
|
|
||||||
* Use REST.get_url() to multiplex the handling of the request depending on the Uri-Path.
|
|
||||||
*/
|
|
||||||
RESOURCE(sub, METHOD_GET | HAS_SUB_RESOURCES, "test/path", "title=\"Sub-resource demo\"");
|
|
||||||
|
|
||||||
void
|
|
||||||
sub_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
|
||||||
{
|
|
||||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
|
||||||
|
|
||||||
const char *uri_path = NULL;
|
|
||||||
int len = REST.get_url(request, &uri_path);
|
|
||||||
int base_len = strlen(resource_sub.url);
|
|
||||||
|
|
||||||
if (len==base_len)
|
|
||||||
{
|
|
||||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "Request any sub-resource of /%s", resource_sub.url);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, ".%s", uri_path+base_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
#if defined (PLATFORM_HAS_LEDS)
|
#if defined (PLATFORM_HAS_LEDS)
|
||||||
|
@ -894,48 +608,6 @@ toggle_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
|
||||||
#endif
|
#endif
|
||||||
#endif /* PLATFORM_HAS_LEDS */
|
#endif /* PLATFORM_HAS_LEDS */
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
#if REST_RES_LIGHT && defined (PLATFORM_HAS_LIGHT)
|
|
||||||
/* 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\"");
|
|
||||||
void
|
|
||||||
light_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
|
||||||
{
|
|
||||||
uint16_t light_photosynthetic = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
|
|
||||||
uint16_t light_solar = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);
|
|
||||||
|
|
||||||
const uint16_t *accept = NULL;
|
|
||||||
int num = REST.get_header_accept(request, &accept);
|
|
||||||
|
|
||||||
if ((num==0) || (num && accept[0]==REST.type.TEXT_PLAIN))
|
|
||||||
{
|
|
||||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
|
||||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%u;%u", light_photosynthetic, light_solar);
|
|
||||||
|
|
||||||
REST.set_response_payload(response, (uint8_t *)buffer, strlen((char *)buffer));
|
|
||||||
}
|
|
||||||
else if (num && (accept[0]==REST.type.APPLICATION_XML))
|
|
||||||
{
|
|
||||||
REST.set_header_content_type(response, REST.type.APPLICATION_XML);
|
|
||||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "<light photosynthetic=\"%u\" solar=\"%u\"/>", light_photosynthetic, light_solar);
|
|
||||||
|
|
||||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
|
||||||
}
|
|
||||||
else if (num && (accept[0]==REST.type.APPLICATION_JSON))
|
|
||||||
{
|
|
||||||
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
|
|
||||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'light':{'photosynthetic':%u,'solar':%u}}", light_photosynthetic, light_solar);
|
|
||||||
|
|
||||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
REST.set_response_status(response, REST.status.UNSUPPORTED_MADIA_TYPE);
|
|
||||||
const char *msg = "Supporting content-types text/plain, application/xml, and application/json";
|
|
||||||
REST.set_response_payload(response, msg, strlen(msg));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* PLATFORM_HAS_LIGHT */
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
#if REST_RES_TEMPERATURE && defined (PLATFORM_HAS_TEMPERATURE)
|
#if REST_RES_TEMPERATURE && defined (PLATFORM_HAS_TEMPERATURE)
|
||||||
|
@ -1007,71 +679,9 @@ battery_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||||
}
|
}
|
||||||
#endif /* PLATFORM_HAS_BATTERY */
|
#endif /* PLATFORM_HAS_BATTERY */
|
||||||
|
|
||||||
|
|
||||||
#if defined (PLATFORM_HAS_RADIO) && REST_RES_RADIO
|
|
||||||
/* A simple getter example. Returns the reading of the rssi/lqi from radio sensor */
|
|
||||||
RESOURCE(radio, METHOD_GET, "sensor/radio", "title=\"RADIO: ?p=lqi|rssi\";rt=\"RadioSensor\"");
|
|
||||||
|
|
||||||
void
|
|
||||||
radio_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
|
||||||
{
|
|
||||||
size_t len = 0;
|
|
||||||
const char *p = NULL;
|
|
||||||
uint8_t param = 0;
|
|
||||||
int success = 1;
|
|
||||||
|
|
||||||
const uint16_t *accept = NULL;
|
|
||||||
int num = REST.get_header_accept(request, &accept);
|
|
||||||
|
|
||||||
if ((len=REST.get_query_variable(request, "p", &p))) {
|
|
||||||
PRINTF("p %.*s\n", len, p);
|
|
||||||
if (strncmp(p, "lqi", len)==0) {
|
|
||||||
param = RADIO_SENSOR_LAST_VALUE;
|
|
||||||
} else if(strncmp(p,"rssi", len)==0) {
|
|
||||||
param = RADIO_SENSOR_LAST_PACKET;
|
|
||||||
} else {
|
|
||||||
success = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
success = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
if ((num==0) || (num && accept[0]==REST.type.TEXT_PLAIN))
|
|
||||||
{
|
|
||||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
|
||||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", radio_sensor.value(param));
|
|
||||||
|
|
||||||
REST.set_response_payload(response, (uint8_t *)buffer, strlen((char *)buffer));
|
|
||||||
}
|
|
||||||
else if (num && (accept[0]==REST.type.APPLICATION_JSON))
|
|
||||||
{
|
|
||||||
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
|
|
||||||
|
|
||||||
if (param == RADIO_SENSOR_LAST_VALUE) {
|
|
||||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'lqi':%d}", radio_sensor.value(param));
|
|
||||||
} else if (param == RADIO_SENSOR_LAST_PACKET) {
|
|
||||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'rssi':%d}", radio_sensor.value(param));
|
|
||||||
}
|
|
||||||
|
|
||||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
REST.set_response_status(response, REST.status.UNSUPPORTED_MADIA_TYPE);
|
|
||||||
const char *msg = "Supporting content-types text/plain and application/json";
|
|
||||||
REST.set_response_payload(response, msg, strlen(msg));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
REST.set_response_status(response, REST.status.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
void
|
||||||
hw_init()
|
hw_init()
|
||||||
{
|
{
|
||||||
key_init();
|
|
||||||
led1_off();
|
led1_off();
|
||||||
#if REST_RES_DS1820
|
#if REST_RES_DS1820
|
||||||
ds1820_temp();
|
ds1820_temp();
|
||||||
|
@ -1096,8 +706,6 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
||||||
|
|
||||||
PROCESS_BEGIN();
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PRINTF("Starting Erbium Example Server\n");
|
PRINTF("Starting Erbium Example Server\n");
|
||||||
|
|
||||||
#ifdef RF_CHANNEL
|
#ifdef RF_CHANNEL
|
||||||
|
@ -1125,7 +733,6 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
||||||
rest_init_engine();
|
rest_init_engine();
|
||||||
|
|
||||||
/* Activate the application-specific resources. */
|
/* Activate the application-specific resources. */
|
||||||
rest_activate_resource(&resource_button);
|
|
||||||
rest_activate_resource(&resource_led1);
|
rest_activate_resource(&resource_led1);
|
||||||
/* Activate the application-specific resources. */
|
/* Activate the application-specific resources. */
|
||||||
#if REST_RES_DS1820
|
#if REST_RES_DS1820
|
||||||
|
@ -1137,12 +744,6 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
||||||
#if REST_RES_INFO
|
#if REST_RES_INFO
|
||||||
rest_activate_resource(&resource_info);
|
rest_activate_resource(&resource_info);
|
||||||
#endif
|
#endif
|
||||||
#if REST_RES_HELLO
|
|
||||||
rest_activate_resource(&resource_helloworld);
|
|
||||||
#endif
|
|
||||||
#if REST_RES_MIRROR
|
|
||||||
rest_activate_resource(&resource_mirror);
|
|
||||||
#endif
|
|
||||||
#if REST_RES_CHUNKS
|
#if REST_RES_CHUNKS
|
||||||
rest_activate_resource(&resource_chunks);
|
rest_activate_resource(&resource_chunks);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1159,9 +760,6 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
||||||
#if defined (PLATFORM_HAS_BUTTON) && (REST_RES_EVENT || (REST_RES_SEPARATE && WITH_COAP > 3))
|
#if defined (PLATFORM_HAS_BUTTON) && (REST_RES_EVENT || (REST_RES_SEPARATE && WITH_COAP > 3))
|
||||||
SENSORS_ACTIVATE(button_sensor);
|
SENSORS_ACTIVATE(button_sensor);
|
||||||
#endif
|
#endif
|
||||||
#if REST_RES_SUB
|
|
||||||
rest_activate_resource(&resource_sub);
|
|
||||||
#endif
|
|
||||||
#if defined (PLATFORM_HAS_LEDS)
|
#if defined (PLATFORM_HAS_LEDS)
|
||||||
#if REST_RES_LEDS
|
#if REST_RES_LEDS
|
||||||
rest_activate_resource(&resource_leds);
|
rest_activate_resource(&resource_leds);
|
||||||
|
@ -1170,10 +768,6 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
||||||
rest_activate_resource(&resource_toggle);
|
rest_activate_resource(&resource_toggle);
|
||||||
#endif
|
#endif
|
||||||
#endif /* PLATFORM_HAS_LEDS */
|
#endif /* PLATFORM_HAS_LEDS */
|
||||||
#if defined (PLATFORM_HAS_LIGHT) && REST_RES_LIGHT
|
|
||||||
SENSORS_ACTIVATE(light_sensor);
|
|
||||||
rest_activate_resource(&resource_light);
|
|
||||||
#endif
|
|
||||||
#if defined (PLATFORM_HAS_TEMPERATURE) && REST_RES_TEMPERATURE
|
#if defined (PLATFORM_HAS_TEMPERATURE) && REST_RES_TEMPERATURE
|
||||||
SENSORS_ACTIVATE(temperature_sensor);
|
SENSORS_ACTIVATE(temperature_sensor);
|
||||||
rest_activate_resource(&resource_temperature);
|
rest_activate_resource(&resource_temperature);
|
||||||
|
@ -1182,10 +776,6 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
||||||
SENSORS_ACTIVATE(battery_sensor);
|
SENSORS_ACTIVATE(battery_sensor);
|
||||||
rest_activate_resource(&resource_battery);
|
rest_activate_resource(&resource_battery);
|
||||||
#endif
|
#endif
|
||||||
#if defined (PLATFORM_HAS_RADIO) && REST_RES_RADIO
|
|
||||||
SENSORS_ACTIVATE(radio_sensor);
|
|
||||||
rest_activate_resource(&resource_radio);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define application-specific events here. */
|
/* Define application-specific events here. */
|
||||||
etimer_set(&ds_periodic_timer, MESURE_INTERVAL);
|
etimer_set(&ds_periodic_timer, MESURE_INTERVAL);
|
||||||
|
|
|
@ -34,12 +34,10 @@
|
||||||
|
|
||||||
//#define PLATFORM_HAS_LEDS 1
|
//#define PLATFORM_HAS_LEDS 1
|
||||||
//#define PLATFORM_HAS_BUTTON 1
|
//#define PLATFORM_HAS_BUTTON 1
|
||||||
//#define PLATFORM_HAS_LIGHT 1
|
|
||||||
#define PLATFORM_HAS_TEMPERATURE 1
|
#define PLATFORM_HAS_TEMPERATURE 1
|
||||||
#define PLATFORM_HAS_BATTERY 1
|
#define PLATFORM_HAS_BATTERY 1
|
||||||
//#define PLATFORM_HAS_SHT11 1
|
#define PLATFORM_HAS_SHT11 1
|
||||||
|
//#define SICSLOWPAN_CONF_FRAG 1
|
||||||
#define SICSLOWPAN_CONF_FRAG 1
|
|
||||||
|
|
||||||
/* Disabling RDC for demo purposes. Core updates often require more memory. */
|
/* Disabling RDC for demo purposes. Core updates often require more memory. */
|
||||||
/* For projects, optimize memory and enable RDC again. */
|
/* For projects, optimize memory and enable RDC again. */
|
||||||
|
|
Loading…
Reference in a new issue