CoAP: Various minor updates in CoAP example

This commit is contained in:
Niclas Finne 2017-11-07 18:27:09 +01:00
parent 4a82bda543
commit b117a8bba8
9 changed files with 43 additions and 92 deletions

View File

@ -13,20 +13,8 @@ MODULES_REL += ./resources
# Include the CoAP implementation
MODULES += os/net/app-layer/coap
# optional rules to get assembly
#CUSTOM_RULE_C_TO_OBJECTDIR_O = 1
#CUSTOM_RULE_S_TO_OBJECTDIR_O = 1
include $(CONTIKI)/Makefile.include
# optional rules to get assembly
#$(OBJECTDIR)/%.o: asmdir/%.S
# $(CC) $(CFLAGS) -MMD -c $< -o $@
# @$(FINALIZE_DEPENDENCY)
#
#asmdir/%.S: %.c
# $(CC) $(CFLAGS) -MMD -S $< -o $@
# border router rules
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
@ -37,8 +25,8 @@ connect-router: $(CONTIKI)/tools/tunslip6
connect-router-cooja: $(CONTIKI)/tools/tunslip6
sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 -p 60001 fd00::1/64
connect-router-native: $(CONTIKI)/examples/native-border-router/border-router.native
sudo $(CONTIKI)/examples/native-border-router/border-router.native -a 127.0.0.1 -p 60001 fd00::1/64
connect-router-native: $(CONTIKI)/examples/rpl-border-router/border-router.native
sudo $(CONTIKI)/examples/rpl-border-router/border-router.native -a 127.0.0.1 -p 60001 fd00::1/64
connect-minimal:
sudo ip address add fdfd::1/64 dev tap0
connect-native:
sudo ip address add fdfd::1/64 dev tun0

View File

@ -1,26 +1,23 @@
A Quick Introduction to the Erbium (Er) REST Engine
A Quick Introduction to the Erbium (Er) CoAP Engine
===================================================
EXAMPLE FILES
-------------
- coap-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-example-server.c: A CoAP server example showing how to use the CoAP
layer to develop server-side applications.
- coap-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).
- plugtest-server.c: The server used for draft compliance testing at ETSI
IoT CoAP Plugtests. Erbium (Er) participated in Paris, France, March 2012 and
Sophia-Antipolis, France, November 2012 (configured for minimal-net).
Sophia-Antipolis, France, November 2012 (configured for native).
PRELIMINARIES
-------------
- Make sure rpl-border-router has the same stack and fits into mote memory:
You can disable RDC in border-router project-conf.h (not really required as BR keeps radio turned on).
#define NETSTACK_CONF_RDC nullrdc_driver
- Alternatively, you can use the native-border-router together with the slip-radio.
- Make sure rpl-border-router has the same network stack and fits into mote memory.
- Alternatively, you can use the native rpl-border-router together with the slip-radio.
- For convenience, define the Cooja addresses in /etc/hosts
fd00::0212:7401:0001:0101 cooja1
fd00::0212:7402:0002:0202 cooja2
@ -58,8 +55,8 @@ Open new terminal
- Choose "Click button on Sky 3" from the context menu of mote 3 (client) and
watch serial output
TMOTES HOWTO
------------
TMOTE SKY HOWTO
---------------
###Server:
@ -90,20 +87,20 @@ TMOTES HOWTO
make TARGET=sky coap-example-client.upload MOTE=3
MINIMAL-NET HOWTO
-----------------
NATIVE HOWTO
------------
With the target minimal-net you can test your CoAP applications without
With the target native you can test your CoAP applications without
constraints, i.e., with large buffers, debug output, memory protection, etc.
The plugtest-server is thought for the minimal-net platform, as it requires
The plugtest-server is thought for the native platform, as it requires
an 1280-byte IP buffer and 1024-byte blocks.
make TARGET=minimal-net plugtest-server
sudo ./plugtest-server.minimal-net
make TARGET=native plugtest-server
sudo ./plugtest-server.native
Open new terminal
make connect-minimal
make connect-native
- Start Copper and discover resources at coap://[fdfd::ff:fe00:10]:5683/
- You can enable the ETSI Plugtest menu in Copper's preferences
@ -130,7 +127,7 @@ in coap-example-server.c. In general, coap supports:
- All draft-18 header options
- CON Retransmissions (note COAP_MAX_OPEN_TRANSACTIONS)
- Blockwise Transfers (note REST_MAX_CHUNK_SIZE, see plugtest-server.c for
- Blockwise Transfers (note COAP_MAX_CHUNK_SIZE, see plugtest-server.c for
Block1 uploads)
- Separate Responses (no rest_set_pre_handler() required anymore, note
coap_separate_accept(), _reject(), and _resume())

View File

@ -45,17 +45,8 @@
#include "coap-blocking-api.h"
#include "dev/button-sensor.h"
#define DEBUG 0
#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]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_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(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
#define DEBUG DEBUG_NONE
#include "net/ipv6/uip-debug.h"
/* FIXME: This server address is hard-coded for Cooja and link-local for unconnected border router. */
#define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0xfe80, 0, 0, 0, 0x0212, 0x7402, 0x0002, 0x0202) /* cooja2 */

View File

@ -49,19 +49,8 @@
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINTFLN(format, ...) printf(format "\n", ##__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:" \
"%02x%02x:%02x%02x:%02x%02x:%02x%02x]", \
((uint8_t *)addr)[0], ((uint8_t *)addr)[1], \
((uint8_t *)addr)[2], ((uint8_t *)addr)[3], \
((uint8_t *)addr)[4], ((uint8_t *)addr)[5], \
((uint8_t *)addr)[6], ((uint8_t *)addr)[7], \
((uint8_t *)addr)[8], ((uint8_t *)addr)[9], \
((uint8_t *)addr)[10], ((uint8_t *)addr)[11], \
((uint8_t *)addr)[12], ((uint8_t *)addr)[13], \
((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTFLN(...)
#endif

View File

@ -51,12 +51,8 @@
#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]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_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(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/*
@ -143,24 +139,24 @@ PROCESS_THREAD(er_example_server, ev, data)
coap_activate_resource(&res_toggle, "actuators/toggle");
#endif
#if PLATFORM_HAS_LIGHT
coap_activate_resource(&res_light, "sensors/light");
SENSORS_ACTIVATE(light_sensor);
coap_activate_resource(&res_light, "sensors/light");
SENSORS_ACTIVATE(light_sensor);
#endif
#if PLATFORM_HAS_BATTERY
coap_activate_resource(&res_battery, "sensors/battery");
SENSORS_ACTIVATE(battery_sensor);
coap_activate_resource(&res_battery, "sensors/battery");
SENSORS_ACTIVATE(battery_sensor);
#endif
#if PLATFORM_HAS_TEMPERATURE
coap_activate_resource(&res_temperature, "sensors/temperature");
SENSORS_ACTIVATE(temperature_sensor);
coap_activate_resource(&res_temperature, "sensors/temperature");
SENSORS_ACTIVATE(temperature_sensor);
#endif
/*
#if PLATFORM_HAS_RADIO
coap_activate_resource(&res_radio, "sensors/radio");
#endif
#if PLATFORM_HAS_SHT11
coap_activate_resource(&res_sht11, "sensors/sht11");
SENSORS_ACTIVATE(sht11_sensor);
coap_activate_resource(&res_sht11, "sensors/sht11");
SENSORS_ACTIVATE(sht11_sensor);
#endif
*/

View File

@ -47,12 +47,8 @@
#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]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_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(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/* double expansion */

View File

@ -36,35 +36,27 @@
* Matthias Kovatsch <kovatsch@inf.ethz.ch>
*/
#ifndef __PROJECT_ERBIUM_CONF_H__
#define __PROJECT_ERBIUM_CONF_H__
#ifndef PROJECT_ERBIUM_CONF_H_
#define PROJECT_ERBIUM_CONF_H_
/* Custom channel and PAN ID configuration for your project. */
/*
#define RF_CHANNEL 26
#define IEEE802154_CONF_PANID 0xABCD
*/
/* #define RF_CHANNEL 26 */
/* #define IEEE802154_CONF_PANID 0xABCD */
/* IP buffer size must match all other hops, in particular the border router. */
/*
#define UIP_CONF_BUFFER_SIZE 256
*/
/* #define UIP_CONF_BUFFER_SIZE 256 */
/* Increase rpl-border-router IP-buffer when using more than 64. */
#define REST_MAX_CHUNK_SIZE 48
#define COAP_MAX_CHUNK_SIZE 48
/* Estimate your header size, especially when using Proxy-Uri. */
/*
#define COAP_MAX_HEADER_SIZE 70
*/
/* #define COAP_MAX_HEADER_SIZE 70 */
/* Multiplies with chunk size, be aware of memory constraints. */
#define COAP_MAX_OPEN_TRANSACTIONS 4
/* Must be <= open transactions, default is COAP_MAX_OPEN_TRANSACTIONS-1. */
/*
#define COAP_MAX_OBSERVERS 2
*/
/* #define COAP_MAX_OBSERVERS 2 */
/* Filtering .well-known/core per query can be disabled to save space. */
#define COAP_LINK_FORMAT_FILTERING 0
@ -74,5 +66,6 @@
#define RPL_CONF_WITH_DAO_ACK 0
/* Enable client-side support for COAP observe */
#define COAP_OBSERVE_CLIENT 1
#endif /* __PROJECT_ERBIUM_CONF_H__ */
#define COAP_OBSERVE_CLIENT 1
#endif /* PROJECT_ERBIUM_CONF_H_ */

View File

@ -43,7 +43,7 @@
#include <stdio.h>
#include <string.h>
#include "coap-engine.h"
//#include "dev/light-sensor.h"
#include "dev/light-sensor.h"
static void res_get_handler(coap_packet_t *request, coap_packet_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);

View File

@ -43,6 +43,7 @@
#if PLATFORM_HAS_SHT11
#include <stdio.h>
#include <string.h>
#include "coap-engine.h"
#include "dev/sht11/sht11-sensor.h"