er-rest-dtls: add rest dtls examples
This commit is contained in:
parent
fcc4f6d39f
commit
e24f500e57
25
examples/er-rest-dtls/Makefile
Normal file
25
examples/er-rest-dtls/Makefile
Normal file
|
@ -0,0 +1,25 @@
|
|||
all: er-example-server er-example-client
|
||||
|
||||
CONTIKI=../..
|
||||
|
||||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
|
||||
WITH_DTLS_COAP ?= 1
|
||||
|
||||
# automatically build RESTful resources
|
||||
ER_EXAMPLE = $(CONTIKI)/examples/er-rest-example
|
||||
REST_RESOURCES_DIR = $(ER_EXAMPLE)/resources
|
||||
REST_RESOURCES_FILES += res-push.c
|
||||
REST_RESOURCES_FILES += res-hello.c
|
||||
PROJECTDIRS += $(REST_RESOURCES_DIR)
|
||||
PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES)
|
||||
|
||||
# linker optimizations
|
||||
SMALL=1
|
||||
|
||||
# REST Engine shall use Erbium CoAP implementation
|
||||
APPS += er-coap
|
||||
APPS += rest-engine
|
||||
|
||||
CONTIKI_WITH_IPV6 = 1
|
||||
include $(CONTIKI)/Makefile.include
|
111
examples/er-rest-dtls/er-example-client.c
Normal file
111
examples/er-rest-dtls/er-example-client.c
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Erbium (Er) CoAP client example.
|
||||
* \author
|
||||
* Matthias Kovatsch <kovatsch@inf.ethz.ch>
|
||||
* Gaëtan Harter <gaetan.harter@inria.fr>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "er-coap-engine.h"
|
||||
|
||||
#define DEBUG 0
|
||||
#include "uip-debug.h"
|
||||
|
||||
#ifndef ER_COAP_SERVER_ADDR
|
||||
/* cooja2 */
|
||||
#define ER_COAP_SERVER_ADDR "fe80::0212:7402:0002:0x0202"
|
||||
#endif /* ER_COAP_SERVER_ADDR */
|
||||
|
||||
#define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT)
|
||||
|
||||
#define TOGGLE_INTERVAL 10
|
||||
|
||||
PROCESS(er_example_client, "Erbium Example Client");
|
||||
AUTOSTART_PROCESSES(&er_example_client);
|
||||
|
||||
|
||||
/* This function is will be passed to COAP_BLOCKING_REQUEST() to handle responses. */
|
||||
void
|
||||
client_chunk_handler(void *response)
|
||||
{
|
||||
const uint8_t *chunk;
|
||||
|
||||
int len = coap_get_payload(response, &chunk);
|
||||
|
||||
printf("|%.*s", len, (char *)chunk);
|
||||
}
|
||||
PROCESS_THREAD(er_example_client, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
static struct etimer et;
|
||||
static coap_packet_t request[1]; /* This way the packet can be treated as pointer as usual. */
|
||||
static uip_ipaddr_t server_ipaddr;
|
||||
|
||||
uiplib_ipaddrconv(ER_COAP_SERVER_ADDR, &server_ipaddr);
|
||||
|
||||
/* receives all CoAP messages */
|
||||
coap_init_engine();
|
||||
|
||||
etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND);
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
|
||||
if(etimer_expired(&et)) {
|
||||
printf("--Toggle timer--\n");
|
||||
|
||||
/* prepare request, TID is set by COAP_BLOCKING_REQUEST() */
|
||||
coap_init_message(request, COAP_TYPE_CON, COAP_GET, 0);
|
||||
coap_set_header_uri_path(request, "test/hello");
|
||||
|
||||
PRINT6ADDR(&server_ipaddr);
|
||||
PRINTF(" : %u\n", UIP_HTONS(REMOTE_PORT));
|
||||
|
||||
COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request,
|
||||
client_chunk_handler);
|
||||
|
||||
printf("\n--Done--\n");
|
||||
|
||||
etimer_reset(&et);
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
98
examples/er-rest-dtls/er-example-server.c
Normal file
98
examples/er-rest-dtls/er-example-server.c
Normal file
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Erbium (Er) REST Engine example.
|
||||
* \author
|
||||
* Matthias Kovatsch <kovatsch@inf.ethz.ch>
|
||||
* Gaëtan Harter <gaetan.harter@inria.fr>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "rest-engine.h"
|
||||
|
||||
#define DEBUG 0
|
||||
#include "uip-debug.h"
|
||||
|
||||
/*
|
||||
* Resources to be activated need to be imported through the extern keyword.
|
||||
* The build system automatically compiles the resources in the corresponding sub-directory.
|
||||
*/
|
||||
extern resource_t
|
||||
res_hello,
|
||||
res_push;
|
||||
|
||||
PROCESS(er_example_server, "Erbium Example Server");
|
||||
AUTOSTART_PROCESSES(&er_example_server);
|
||||
|
||||
PROCESS_THREAD(er_example_server, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
PROCESS_PAUSE();
|
||||
|
||||
PRINTF("Starting Erbium Example Server\n");
|
||||
|
||||
#ifdef RF_CHANNEL
|
||||
PRINTF("RF channel: %u\n", RF_CHANNEL);
|
||||
#endif
|
||||
#ifdef IEEE802154_PANID
|
||||
PRINTF("PAN ID: 0x%04X\n", IEEE802154_PANID);
|
||||
#endif
|
||||
|
||||
PRINTF("uIP buffer: %u\n", UIP_BUFSIZE);
|
||||
PRINTF("LL header: %u\n", UIP_LLH_LEN);
|
||||
PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN);
|
||||
PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE);
|
||||
|
||||
/* Initialize the REST engine. */
|
||||
rest_init_engine();
|
||||
|
||||
/*
|
||||
* Bind the resources to their Uri-Path.
|
||||
* WARNING: Activating twice only means alternate path, not two instances!
|
||||
* All static variables are the same for each URI path.
|
||||
*/
|
||||
rest_activate_resource(&res_hello, "test/hello");
|
||||
rest_activate_resource(&res_push, "test/push");
|
||||
|
||||
/* Define application-specific events here. */
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
} /* while (1) */
|
||||
|
||||
PROCESS_END();
|
||||
}
|
77
examples/er-rest-dtls/project-conf.h
Normal file
77
examples/er-rest-dtls/project-conf.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Erbium (Er) example project configuration.
|
||||
* \author
|
||||
* Matthias Kovatsch <kovatsch@inf.ethz.ch>
|
||||
*/
|
||||
|
||||
#ifndef __PROJECT_ERBIUM_CONF_H__
|
||||
#define __PROJECT_ERBIUM_CONF_H__
|
||||
|
||||
/* Custom channel and PAN ID configuration for your project. */
|
||||
|
||||
/* IP buffer size must match all other hops, in particular the border router. */
|
||||
#define UIP_CONF_BUFFER_SIZE 1500
|
||||
|
||||
/* Increase rpl-border-router IP-buffer when using more than 64. */
|
||||
#undef REST_MAX_CHUNK_SIZE
|
||||
#define REST_MAX_CHUNK_SIZE 48
|
||||
|
||||
/* Estimate your header size, especially when using Proxy-Uri. */
|
||||
/*
|
||||
#undef COAP_MAX_HEADER_SIZE
|
||||
#define COAP_MAX_HEADER_SIZE 70
|
||||
*/
|
||||
|
||||
/* Multiplies with chunk size, be aware of memory constraints. */
|
||||
#undef COAP_MAX_OPEN_TRANSACTIONS
|
||||
#define COAP_MAX_OPEN_TRANSACTIONS 4
|
||||
|
||||
/* Must be <= open transactions, default is COAP_MAX_OPEN_TRANSACTIONS-1. */
|
||||
/*
|
||||
#undef COAP_MAX_OBSERVERS
|
||||
#define COAP_MAX_OBSERVERS 2
|
||||
*/
|
||||
|
||||
/* Filtering .well-known/core per query can be disabled to save space. */
|
||||
#undef COAP_LINK_FORMAT_FILTERING
|
||||
#define COAP_LINK_FORMAT_FILTERING 0
|
||||
#undef COAP_PROXY_OPTION_PROCESSING
|
||||
#define COAP_PROXY_OPTION_PROCESSING 0
|
||||
|
||||
|
||||
/* Enable client-side support for COAP observe */
|
||||
#define COAP_OBSERVE_CLIENT 1
|
||||
|
||||
#endif /* __PROJECT_ERBIUM_CONF_H__ */
|
Loading…
Reference in a new issue