Merge branch 'develop' into contrib/rtimer-config

This commit is contained in:
Simon Duquennoy 2018-05-11 21:10:33 +02:00 committed by GitHub
commit 5ef74e9cfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
204 changed files with 2138 additions and 1143 deletions

View File

@ -49,6 +49,8 @@ CFLAGS += -DCONTIKI_BOARD_$(TARGET_BOARD_UPPERCASE)=1
CFLAGS += -DCONTIKI_BOARD_STRING=\"$(BOARD)\"
endif
LDFLAGS = -Wl,--fatal-warnings
MODULES += os os/sys os/dev os/lib os/services
# Automatically include project-conf.h if found
@ -165,14 +167,12 @@ MAKE_NET ?= MAKE_NET_IPV6
ifeq ($(MAKE_NET),MAKE_NET_NULLNET)
CFLAGS += -DNETSTACK_CONF_WITH_NULLNET=1
MODULES += os/net/nullnet
endif
ifeq ($(MAKE_NET),MAKE_NET_IPV6)
CFLAGS += -DNETSTACK_CONF_WITH_IPV6=1
MODULES += os/net/ipv6
else
CFLAGS += -DNETSTACK_CONF_WITH_NULLNET=1
MODULES += os/net/nullnet
endif
ifeq ($(MAKE_NET),MAKE_NET_OTHER)
@ -298,14 +298,15 @@ CONTIKI_NG_PROJECT_MAP = $(addsuffix -$(TARGET).map, $(basename $@))
.PHONY: clean distclean usage help targets boards savetarget savedefines viewconf
clean:
-rm -f *.d *.e *.o $(CONTIKI_NG_TARGET_LIB) $(CLEAN)
-rm -rf $(OBJECTDIR)
-rm -f $(addsuffix -$(TARGET).map, $(CONTIKI_PROJECT))
-rm -f $(addsuffix .$(TARGET), $(CONTIKI_PROJECT))
-$(Q)rm -f *.d *.e *.o $(CONTIKI_NG_TARGET_LIB) $(CLEAN)
-$(Q)rm -rf $(OBJECTDIR)
-$(Q)rm -f $(addsuffix -$(TARGET).map, $(CONTIKI_PROJECT))
-$(Q)rm -f $(addsuffix .$(TARGET), $(CONTIKI_PROJECT))
@echo Target $(TARGET) cleaned
distclean:
@for TARG in `ls $(CONTIKI)/arch/platform $(TARGETDIRS)`; do \
echo make $$TARG clean; \
echo Running: make TARGET=$$TARG clean; \
make TARGET=$$TARG clean; \
done
@ -397,7 +398,7 @@ usage:
@echo "Miscellaneous targets:"
@echo " targets Prints list of supported platforms"
@echo " boards Prints a list of supported boards for TARGET"
@echo " savegtarget Saves TARGET and BOARD for future invocations of make"
@echo " savetarget Saves TARGET and BOARD for future invocations of make"
@echo " savedefines Saves DEFINES for future invocations of make"
@echo " clean Removes all compiled files for TARGET"
@echo " distclean Removes all compiled files for all TARGETs"

View File

@ -1,7 +1,7 @@
# Contiki-NG: The OS for Next Generation IoT Devices
[![Build Status](https://travis-ci.org/contiki-ng/contiki-ng.svg?branch=master)](https://travis-ci.org/contiki-ng/contiki-ng/branches)
[![License](https://img.shields.io/badge/License-3--Clause%20BSD-brightgreen.svg)](https://github.com/contiki-ng/contiki-ng/blob/master/LICENSE.md)
[![license](https://img.shields.io/badge/license-3--clause%20bsd-brightgreen.svg)](https://github.com/contiki-ng/contiki-ng/blob/master/LICENSE.md)
[![Latest release](https://img.shields.io/github/release/contiki-ng/contiki-ng.svg)](https://github.com/contiki-ng/contiki-ng/releases/latest)
[![GitHub Release Date](https://img.shields.io/github/release-date/contiki-ng/contiki-ng.svg)](https://github.com/contiki-ng/contiki-ng/releases/latest)
[![Last commit](https://img.shields.io/github/last-commit/contiki-ng/contiki-ng.svg)](https://github.com/contiki-ng/contiki-ng/commit/HEAD)

View File

@ -93,10 +93,10 @@ ifeq ($(HOST_OS),Windows)
SERIALDUMP ?= $(CONTIKI)/tools/sky/serialdump-windows
else
ifeq ($(HOST_OS),Darwin)
SERIALDUMP ?= $(CONTIKI)/tools/sky/serialdump-macos
SERIALDUMP ?= rlwrap $(CONTIKI)/tools/sky/serialdump-macos
else
# Else assume Linux
SERIALDUMP ?= $(CONTIKI)/tools/sky/serialdump-linux
SERIALDUMP ?= rlwrap $(CONTIKI)/tools/sky/serialdump-linux
endif
endif

View File

@ -78,9 +78,17 @@
#define IEEE802154_CONF_DEFAULT_CHANNEL 0
#endif /* IEEE802154_CONF_DEFAULT_CHANNEL */
#ifndef CSMA_CONF_ACK_WAIT_TIME
#define CSMA_CONF_ACK_WAIT_TIME (RTIMER_SECOND / 400)
#endif /* CSMA_CONF_ACK_WAIT_TIME */
#ifndef CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME
#define CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME (RTIMER_SECOND / 1000)
#endif /* CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME */
#ifndef CSMA_CONF_SEND_SOFT_ACK
#define CSMA_CONF_SEND_SOFT_ACK 1
#endif /* CSMA_CONF_SEND_SOFT_ACK */
#else /* CC13XX_CONF_PROP_MODE */
#ifndef NETSTACK_CONF_RADIO
@ -190,7 +198,7 @@
* @{
*/
#ifndef ROM_BOOTLOADER_ENABLE
#define ROM_BOOTLOADER_ENABLE 0
#define ROM_BOOTLOADER_ENABLE 1
#endif
/** @} */
/*---------------------------------------------------------------------------*/

View File

@ -63,6 +63,7 @@
#define DOT_15_4G_FREQUENCY_BAND_950 11 /* 950958 (Japan) - 950 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_1427 12 /* 14271518 (US and Canada, non-contiguous) - 1427 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_2450 13 /* 24002483.5 2450 MHz band */
#define DOT_15_4G_FREQUENCY_BAND_CUSTOM 14 /* For use with custom frequency band settings */
/*---------------------------------------------------------------------------*/
/* Default band selection to band 4 - 863MHz */
#ifdef DOT_15_4G_CONF_FREQUENCY_BAND_ID
@ -77,6 +78,18 @@
* bands we only support operating mode #1 (Table 134).
*
* DOT_15_4G_CHAN0_FREQUENCY is specified here in KHz
*
* Custom bands and configuration can be used with DOT_15_4G_FREQUENCY_BAND_CUSTOM.
*
* Example of custom setup for the 868Mhz sub-band in Europe with 11 channels,
* center frequency at 868.050MHz and channel spacing at 100KHz.
* These should be put in project-config.h or similar.
*
* #define DOT_15_4G_FREQUENCY_BAND_ID DOT_15_4G_FREQUENCY_BAND_CUSTOM
* #define DOT_15_4G_CHAN0_FREQUENCY 868050
* #define DOT_15_4G_CHANNEL_SPACING 100
* #define DOT_15_4G_CHANNEL_MAX 11
* #define PROP_MODE_CONF_LO_DIVIDER 0x05
*/
#if DOT_15_4G_FREQUENCY_BAND_ID==DOT_15_4G_FREQUENCY_BAND_470
#define DOT_15_4G_CHANNEL_MAX 198
@ -116,6 +129,22 @@
#define DOT_15_4G_CHAN0_FREQUENCY 951000
#define PROP_MODE_CONF_LO_DIVIDER 0x05
#elif DOT_15_4G_FREQUENCY_BAND_ID==DOT_15_4G_FREQUENCY_BAND_CUSTOM
#ifndef DOT_15_4G_CHANNEL_MAX
#error DOT_15_4G_CHANNEL_MAX must be manually set when using custom frequency band
#endif
#ifndef DOT_15_4G_CHANNEL_SPACING
#error DOT_15_4G_CHANNEL_SPACING must be manually set when using custom frequency band
#endif
#ifndef DOT_15_4G_CHAN0_FREQUENCY
#error DOT_15_4G_CHAN0_FREQUENCY must be manually set when using custom frequency band
#endif
#ifndef PROP_MODE_CONF_LO_DIVIDER
#error PROP_MODE_CONF_LO_DIVIDER must be manually set when using custom frequency band
#endif
#else
#error The selected frequency band is not supported
#endif

View File

@ -1,6 +1,7 @@
CONTIKI_CPU_DIRS = . net dev
CONTIKI_SOURCEFILES += rtimer-arch.c watchdog.c eeprom.c
CONTIKI_SOURCEFILES += rtimer-arch.c watchdog.c eeprom.c int-master.c
CONTIKI_SOURCEFILES += gpio-hal-arch.c
### Compiler definitions
CC ?= gcc

View File

@ -0,0 +1,216 @@
/*
* Copyright (c) 2018, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "dev/gpio-hal.h"
#include "sys/log.h"
#include <stdint.h>
/*---------------------------------------------------------------------------*/
/* Log configuration */
#define LOG_MODULE "GPIO arch"
#define LOG_LEVEL LOG_LEVEL_NONE
/*---------------------------------------------------------------------------*/
static gpio_hal_pin_cfg_t pin_cfg[GPIO_HAL_PIN_COUNT];
static uint8_t pin_state[GPIO_HAL_PIN_COUNT];
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_interrupt_enable(gpio_hal_pin_t pin)
{
if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin);
return;
}
LOG_DBG("Pin %u: Enabled interrupt\n", pin);
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_interrupt_disable(gpio_hal_pin_t pin)
{
if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin);
return;
}
LOG_DBG("Pin %u: Disabled interrupt\n", pin);
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
{
if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin);
return;
}
pin_cfg[pin] = cfg;
LOG_DBG("Pin %u: Set config=0x%02x\n", pin, pin_cfg[pin]);
}
/*---------------------------------------------------------------------------*/
gpio_hal_pin_cfg_t
gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin)
{
if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin);
return 0;
}
LOG_DBG("Pin %u: Config=0x%02x\n", pin, pin_cfg[pin]);
return pin_cfg[pin];
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_pin_set_input(gpio_hal_pin_t pin)
{
if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin);
return;
}
LOG_DBG("Pin %u: Set input\n", pin);
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_pin_set_output(gpio_hal_pin_t pin)
{
if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin);
return;
}
LOG_DBG("Pin %u: Set output\n", pin);
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_set_pin(gpio_hal_pin_t pin)
{
if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin);
return;
}
pin_state[pin] = 1;
LOG_DBG("Pin %u: Set\n", pin);
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_clear_pin(gpio_hal_pin_t pin)
{
if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin);
return;
}
pin_state[pin] = 0;
LOG_DBG("Pin %u: Clear\n", pin);
}
/*---------------------------------------------------------------------------*/
uint8_t
gpio_hal_arch_read_pin(gpio_hal_pin_t pin)
{
if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin);
return 0;
}
LOG_DBG("Pin %u: Read=%u\n", pin, pin_state[pin]);
return pin_state[pin];
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_write_pin(gpio_hal_pin_t pin, uint8_t value)
{
if(pin >= GPIO_HAL_PIN_COUNT) {
LOG_ERR("Pin %u out of bounds\n", pin);
return;
}
pin_state[pin] = value;
LOG_DBG("Pin %u: Write=%u\n", pin, pin_state[pin]);
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_set_pins(gpio_hal_pin_mask_t pins)
{
gpio_hal_pin_t pin;
for(pin = 0; pin < GPIO_HAL_PIN_COUNT; pin++) {
if(pins & (1 << pin)) {
pin_state[pin] = 1;
}
}
LOG_DBG("Set pins 0x%08" PRIx32 "\n", pins);
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_clear_pins(gpio_hal_pin_mask_t pins)
{
gpio_hal_pin_t pin;
for(pin = 0; pin < GPIO_HAL_PIN_COUNT; pin++) {
if(pins & (1 << pin)) {
pin_state[pin] = 0;
}
}
LOG_DBG("Clear pins 0x%08" PRIx32 "\n", pins);
}
/*---------------------------------------------------------------------------*/
gpio_hal_pin_mask_t
gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins)
{
gpio_hal_pin_t pin;
gpio_hal_pin_mask_t state = 0;
for(pin = 0; pin < GPIO_HAL_PIN_COUNT; pin++) {
state |= (pin_state[pin] << pin);
}
LOG_DBG("Read pins 0x%08" PRIx32 "\n", state);
return state;
}
/*---------------------------------------------------------------------------*/
void
gpio_hal_arch_write_pins(gpio_hal_pin_mask_t pins, gpio_hal_pin_mask_t value)
{
gpio_hal_pin_t pin;
for(pin = 0; pin < GPIO_HAL_PIN_COUNT; pin++) {
if(pins & (1 << pin)) {
pin_state[pin] = (value & (1 << pin)) == 0 ? 0 : 1;
}
}
LOG_DBG("Write pins 0x%08" PRIx32 "->0x%08" PRIx32 "\n", pins, value);
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2018, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "sys/int-master.h"
#include <stdbool.h>
/*---------------------------------------------------------------------------*/
#define DISABLED 0
#define ENABLED 1
/*---------------------------------------------------------------------------*/
static int_master_status_t stat = DISABLED;
/*---------------------------------------------------------------------------*/
void
int_master_enable(void)
{
stat = ENABLED;
}
/*---------------------------------------------------------------------------*/
int_master_status_t
int_master_read_and_disable(void)
{
int_master_status_t rv = stat;
stat = DISABLED;
return rv;
}
/*---------------------------------------------------------------------------*/
void
int_master_status_set(int_master_status_t status)
{
stat = status;
}
/*---------------------------------------------------------------------------*/
bool
int_master_is_enabled(void)
{
return stat == DISABLED ? false : true;
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2018, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
#ifndef NATIVE_DEF_H_
#define NATIVE_DEF_H_
/*---------------------------------------------------------------------------*/
#define GPIO_HAL_CONF_ARCH_SW_TOGGLE 1
/*---------------------------------------------------------------------------*/
#endif /* NATIVE_DEF_H_ */
/*---------------------------------------------------------------------------*/

View File

@ -114,12 +114,14 @@ static spi_device_t flash_spi_configuration_default = {
* Get spi configuration, return default configuration if NULL
*/
static spi_device_t *
get_spi_conf(spi_device_t *conf) {
get_spi_conf(spi_device_t *conf)
{
if(conf == NULL) {
return &flash_spi_configuration_default;
}
return conf;
}/*---------------------------------------------------------------------------*/
}
/*---------------------------------------------------------------------------*/
/**
* Clear external flash CSN line
*/

View File

@ -37,3 +37,17 @@ else
sort -g | head -1))
$(PYTHON) $(BSL) $(BSL_FLAGS) $(BSL_ADDRESS_ARG) $<
endif
ifeq ($(HOST_OS),Darwin)
RENODE = mono /Applications/Renode.app/Contents/MacOS/bin/Renode.exe
else
RENODE = renode
endif
SCRIPT ?= $(notdir $(CURDIR)).resc
.PHONY: renode
renode: all
$(RENODE) $(SCRIPT)

View File

@ -57,5 +57,3 @@ const leds_t leds_arch_leds[] = {
#endif
};
/*---------------------------------------------------------------------------*/

View File

@ -180,12 +180,12 @@ else
ifeq ($(HOST_OS),Darwin)
USBDEVPREFIX=
USBDEVBASENAME=/dev/tty.usbserial-
SERIALDUMP ?= $(CONTIKI)/tools/jn516x/serialdump-macos
SERIALDUMP ?= rlwrap $(CONTIKI)/tools/jn516x/serialdump-macos
else
# Else we assume Linux
USBDEVPREFIX=
USBDEVBASENAME=/dev/ttyUSB
SERIALDUMP ?= $(CONTIKI)/tools/jn516x/serialdump-linux
SERIALDUMP ?= rlwrap $(CONTIKI)/tools/jn516x/serialdump-linux
endif
endif

View File

@ -6,8 +6,8 @@ endif
CONTIKI_TARGET_DIRS = . dev
CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o}
CONTIKI_TARGET_SOURCEFILES += platform.c clock.c xmem.c leds-arch.c
CONTIKI_TARGET_SOURCEFILES += cfs-posix.c cfs-posix-dir.c
CONTIKI_TARGET_SOURCEFILES += platform.c clock.c xmem.c
CONTIKI_TARGET_SOURCEFILES += cfs-posix.c cfs-posix-dir.c buttons.c
ifeq ($(HOST_OS),Windows)
CONTIKI_TARGET_SOURCEFILES += wpcap-drv.c wpcap.c

View File

@ -37,7 +37,9 @@
#ifdef PROJECT_CONF_PATH
#include PROJECT_CONF_PATH
#endif /* PROJECT_CONF_PATH */
/*---------------------------------------------------------------------------*/
#include "native-def.h"
/*---------------------------------------------------------------------------*/
#include <inttypes.h>
#ifndef WIN32_LEAN_AND_MEAN
#include <sys/select.h>
@ -60,8 +62,6 @@ int select_set_callback(int fd, const struct select_callback *callback);
typedef unsigned int uip_stats_t;
#define LEDS_CONF_LEGACY_API 1
#ifndef UIP_CONF_BYTE_ORDER
#define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN
#endif
@ -91,6 +91,8 @@ typedef unsigned long clock_time_t;
#define LOG_CONF_ENABLED 1
#define PLATFORM_SUPPORTS_BUTTON_HAL 1
/* Not part of C99 but actually present */
int strcasecmp(const char*, const char*);

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2018, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "dev/button-hal.h"
#include <stdint.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
button_hal_button_t *button_hal_buttons[] = { NULL };
const uint8_t button_hal_button_count = 0;
/*---------------------------------------------------------------------------*/

View File

@ -56,6 +56,9 @@
#include "net/netstack.h"
#include "dev/serial-line.h"
#include "dev/button-hal.h"
#include "dev/gpio-hal.h"
#include "dev/leds.h"
#include "net/ipv6/uip.h"
#include "net/ipv6/uip-debug.h"
@ -251,6 +254,9 @@ platform_process_args(int argc, char**argv)
void
platform_init_stage_one()
{
gpio_hal_init();
button_hal_init();
leds_init();
return;
}
/*---------------------------------------------------------------------------*/

View File

@ -54,5 +54,3 @@ const leds_t leds_arch_leds[] = {
},
};
/*---------------------------------------------------------------------------*/

View File

@ -54,7 +54,7 @@ else
ifeq ($(HOST_OS),Darwin)
ifndef MOTELIST
USBDEVPREFIX=
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-macos
SERIALDUMP = rlwrap $(CONTIKI)/tools/sky/serialdump-macos
MOTELIST = $(CONTIKI)/tools/sky/motelist-macos
TMOTE_BSL_FILE = tmote-bsl-linux
TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)),1,0)
@ -75,7 +75,7 @@ else
# Else we assume Linux
ifndef MOTELIST
USBDEVPREFIX=
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux
SERIALDUMP = rlwrap $(CONTIKI)/tools/sky/serialdump-linux
MOTELIST = $(CONTIKI)/tools/sky/motelist-linux
TMOTE_BSL_FILE = tmote-bsl-linux
TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)),1,0)

View File

@ -43,20 +43,22 @@
#include "contiki-conf.h"
#include "dev/xmem.h"
/*** MX25R8035F Memory Organization
The memory is organized as:
8Mbit = 1048576 bytes (8 bits each)
256 sectors (32 Kbits, 4096 bytes each)
4096 pages (256 bytes each).
Each page can be individually programmed (bits are programmed from 1 to 0). The device is
sector or bulk erasable (bits are erased from 0 to 1) but not page erasable
/*
* MX25R8035F Memory Organization
* The memory is organized as:
* 8Mbit = 1048576 bytes (8 bits each)
* 256 sectors (32 Kbits, 4096 bytes each)
* 4096 pages (256 bytes each).
* Each page can be individually programmed (bits are programmed from 1 to 0).
* The device is sector or bulk erasable (bits are erased from 0 to 1) but not
* page erasable
*/
#define COFFEE_XMEM_TOTAL_SIZE_KB 1024UL //Total size of the External Flash Memory in the Z1
#define COFFEE_XMEM_TOTAL_SIZE_KB 1024UL /* Total size of the External Flash Memory in the Z1 */
/* Coffee configuration parameters. */
#define COFFEE_SECTOR_SIZE 4096UL
#define COFFEE_PAGE_SIZE 256UL
#define COFFEE_START 0UL //COFFEE_SECTOR_SIZE
#define COFFEE_START 0UL /* COFFEE_SECTOR_SIZE */
#define COFFEE_SIZE (COFFEE_XMEM_TOTAL_SIZE_KB * 1024UL - COFFEE_START)
#define COFFEE_NAME_LENGTH 16
#define COFFEE_MAX_OPEN_FILES 6
@ -67,11 +69,6 @@ sector or bulk erasable (bits are erased from 0 to 1) but not page erasable
#define COFFEE_MICRO_LOGS 1
/* Flash operations. */
#define COFFEE_WRITE(buf, size, offset) \
xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset))

View File

@ -49,21 +49,17 @@
#define XMEM_BUFF_LENGHT 128
#if 0
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...) do {} while(0)
#endif
void
xmem_init(void)
{
ext_flash_open(NULL);
}
int
xmem_pread(void *_p, int size, unsigned long addr)
{
@ -87,14 +83,13 @@ xmem_pread(void *_p, int size, unsigned long addr)
ext_flash_close(NULL);
if(rv)
if(rv) {
return size;
}
PRINTF("Could not read flash memory!\n");
return -1;
}
int
xmem_pwrite(const void *_buf, int size, unsigned long addr)
{
@ -128,8 +123,6 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr)
return size;
}
int
xmem_erase(long size, unsigned long addr)
{
@ -137,7 +130,6 @@ xmem_erase(long size, unsigned long addr)
rv = ext_flash_open(NULL);
if(!rv) {
PRINTF("Could not open flash to save config\n");
ext_flash_close(NULL);
@ -160,8 +152,9 @@ xmem_erase(long size, unsigned long addr)
watchdog_periodic();
if(rv)
if(rv) {
return size;
}
PRINTF("Could not erase flash memory\n");
return -1;

View File

@ -41,5 +41,3 @@ const leds_t leds_arch_leds[] = {
{ .pin = BOARD_IOID_LED_2, .negative_logic = false },
};
/*---------------------------------------------------------------------------*/

View File

@ -39,5 +39,3 @@ const leds_t leds_arch_leds[] = {
{ .pin = BOARD_IOID_LED_1, .negative_logic = false },
};
/*---------------------------------------------------------------------------*/

View File

@ -40,5 +40,3 @@ const leds_t leds_arch_leds[] = {
{ .pin = BOARD_IOID_LED_2, .negative_logic = false },
};
/*---------------------------------------------------------------------------*/

View File

@ -42,5 +42,3 @@ const leds_t leds_arch_leds[] = {
{ .pin = BOARD_IOID_LED_4, .negative_logic = false },
};
/*---------------------------------------------------------------------------*/

View File

@ -56,11 +56,11 @@ ifeq ($(HOST_OS),Darwin)
USBDEVPREFIX=
MOTELIST := $(CONTIKI)/tools/zolertia/motelist-zolertia-macos
MOTES := $(shell $(MOTELIST) -c 2>&- | cut -f 2 -d ,)
SERIALDUMP := $(CONTIKI)/tools/sky/serialdump-macos
SERIALDUMP := rlwrap $(CONTIKI)/tools/sky/serialdump-macos
else
### If we are not running under Mac, we assume Linux
USBDEVPREFIX=
SERIALDUMP := $(CONTIKI)/tools/sky/serialdump-linux
SERIALDUMP := rlwrap $(CONTIKI)/tools/sky/serialdump-linux
MOTELIST := $(CONTIKI)/tools/zolertia/motelist-zolertia
MOTES := $(shell $(MOTELIST) -b $(MOTELIST_ZOLERTIA) -c 2>&- | cut -f 2 -d , | \
perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);')

View File

@ -72,7 +72,7 @@ dht22_read(void)
{
uint8_t i;
uint8_t j = 0;
uint8_t last_state;
uint8_t last_state = 0xFF;
uint8_t counter = 0;
uint8_t checksum = 0;
@ -95,7 +95,6 @@ dht22_read(void)
* if the line is high between 70-74us the bit sent will be "1" (one).
*/
GPIO_SET_INPUT(DHT22_PORT_BASE, DHT22_PIN_MASK);
last_state = GPIO_READ_PIN(DHT22_PORT_BASE, DHT22_PIN_MASK);
for(i = 0; i < DHT22_MAX_TIMMING; i++) {
counter = 0;
@ -208,8 +207,8 @@ value(int type)
}
}
/*---------------------------------------------------------------------------*/
int
dht22_read_all(int *temperature, int *humidity)
int16_t
dht22_read_all(int16_t *temperature, int16_t *humidity)
{
if((temperature == NULL) || (humidity == NULL)) {
PRINTF("DHT22: Invalid arguments\n");

View File

@ -90,7 +90,7 @@
#define DHT22_COUNT 8 /**< Minimum ticks to detect a "1" bit */
#define DHT22_MAX_TIMMING 85 /**< Maximum ticks in a single operation */
#define DHT22_READING_DELAY 1 /**< 1 us */
#define DHT22_READY_TIME 20 /**< 40 us */
#define DHT22_READY_TIME 40 /**< 40 us */
#define DHT22_START_TIME (RTIMER_SECOND / 50) /**< 20 ms */
#define DHT22_AWAKE_TIME (RTIMER_SECOND / 4) /**< 250 ms */
/** @} */
@ -99,7 +99,7 @@
* \name DHT22 auxiliary functions
* @{
*/
int dht22_read_all(int *temperature, int *humidity);
int16_t dht22_read_all(int16_t *temperature, int16_t *humidity);
/** @} */
/* -------------------------------------------------------------------------- */
#define DHT22_SENSOR "DHT22 sensor"

View File

@ -50,5 +50,3 @@ const leds_t leds_arch_leds[] = {
},
};
/*---------------------------------------------------------------------------*/

View File

@ -28,8 +28,8 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PROJECT_CONF_H_
#define _PROJECT_CONF_H_
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
#define UIP_CONF_ND6_SEND_RA 0
@ -39,4 +39,4 @@
#define LOG_CONF_LEVEL_6TOP LOG_LEVEL_DBG
#endif /* _PROJECT_CONF_H_ */
#endif /* PROJECT_CONF_H_ */

View File

@ -32,8 +32,8 @@
* \author Simon Duquennoy <simonduq@sics.se>
*/
#ifndef __PROJECT_CONF_H__
#define __PROJECT_CONF_H__
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
/* Set to enable TSCH security */
#ifndef WITH_SECURITY
@ -115,4 +115,4 @@
#define LOG_CONF_LEVEL_6TOP LOG_LEVEL_DBG
#define TSCH_LOG_CONF_PER_SLOT 1
#endif /* __PROJECT_CONF_H__ */
#endif /* PROJECT_CONF_H_ */

View File

@ -32,8 +32,8 @@
* \author Simon Duquennoy <simonduq@sics.se>
*/
#ifndef __PROJECT_CONF_H__
#define __PROJECT_CONF_H__
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
/* Set to enable TSCH security */
#ifndef WITH_SECURITY
@ -78,4 +78,4 @@
#define LOG_CONF_LEVEL_FRAMER LOG_LEVEL_DBG
#define TSCH_LOG_CONF_PER_SLOT 1
#endif /* __PROJECT_CONF_H__ */
#endif /* PROJECT_CONF_H_ */

View File

@ -28,8 +28,8 @@
*
*/
#ifndef __PROJECT_CONF_H__
#define __PROJECT_CONF_H__
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
/* Set to enable TSCH security */
#ifndef WITH_SECURITY
@ -103,4 +103,4 @@
#endif /* CONTIKI_TARGET_CC2538DK || CONTIKI_TARGET_ZOUL \
|| CONTIKI_TARGET_OPENMOTE_CC2538 */
#endif /* __PROJECT_CONF_H__ */
#endif /* PROJECT_CONF_H_ */

View File

@ -1,38 +0,0 @@
CONTIKI_PROJECT = coap-example-server coap-example-client
# use target "plugtest-server" explicitly when required
all: $(CONTIKI_PROJECT)
CONTIKI=../..
# Do not try to build on Sky because of code size limitation
PLATFORMS_EXCLUDE = sky
# build RESTful resources
include $(CONTIKI)/Makefile.identify-target
ifeq ($(TARGET),native)
MODULES_REL += ./resources-plugtest
endif
MODULES_REL += ./resources
MODULES_REL += $(TARGET)
# Include the CoAP implementation
MODULES += os/net/app-layer/coap
include $(CONTIKI)/Makefile.include
# border router rules
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
connect-router: $(CONTIKI)/tools/tunslip6
sudo $(CONTIKI)/tools/tunslip6 fd00::1/64
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/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-native:
sudo ip address add fdfd::1/64 dev tun0

View File

@ -1,83 +1,9 @@
A Quick Introduction to the Erbium (Er) CoAP Engine
===================================================
# CoAP examples: client, server, and plugtest server
EXAMPLE FILES
-------------
* coap-example-server: A CoAP server example showing how to use the CoAP layer to develop server-side applications.
* coap-example-client: 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).
* coap-plugtest-server: 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 native).
- 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 native).
PRELIMINARIES
-------------
- Get the Copper (Cu) CoAP user-agent from
[https://addons.mozilla.org/en-US/firefox/addon/copper-270430](https://addons.mozilla.org/en-US/firefox/addon/copper-270430)
TMOTE SKY HOWTO
---------------
The CoAP example no longer fits in the limited ROM of the Tmote Sky.
Please use a platform with larger ROM instead.
NATIVE HOWTO
------------
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 native platform, as it requires
an 1280-byte IP buffer and 1024-byte blocks.
make TARGET=native plugtest-server
sudo ./plugtest-server.native
Open new terminal
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
Under Windows/Cygwin, WPCAP might need a patch in
<cygwin>\usr\include\w32api\in6addr.h:
21,23c21
< #ifdef __INSIDE_CYGWIN__
< uint32_t __s6_addr32[4];
< #endif
---
> u_int __s6_addr32[4];
36d33
< #ifdef __INSIDE_CYGWIN__
39d35
< #endif
DETAILS
-------
Erbium implements the Proposed Standard of CoAP. Central features are commented
in coap-example-server.c. In general, coap supports:
- All draft-18 header options
- CON Retransmissions (note COAP_MAX_OPEN_TRANSACTIONS)
- 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())
- Resource Discovery
- Observing Resources (see EVENT_ and PERIODIC_RESOURCE, note
COAP_MAX_OBSERVERS)
TODOs
-----
- Dedicated Observe buffers
- Optimize message struct variable access (directly access struct without copying)
- Observe client
- Multiple If-Match ETags
- (Message deduplication)
The examples can run either on a real device or as native.
In the latter case, just start the executable with enough permissions (e.g. sudo), and you will then be able to reach the node via tun.
A tutorial for setting up the CoAP server example and querying it is provided on the wiki.

View File

@ -0,0 +1,12 @@
CONTIKI_PROJECT = coap-example-client
# coap-example-observe-client is outdated but will be ported at a later point
all: $(CONTIKI_PROJECT)
# Do not try to build on Sky because of code size limitation
PLATFORMS_EXCLUDE = sky
# Include the CoAP implementation
MODULES += os/net/app-layer/coap
CONTIKI=../../..
include $(CONTIKI)/Makefile.include

View File

@ -51,8 +51,8 @@
/* Log configuration */
#include "coap-log.h"
#define LOG_MODULE "client"
#define LOG_LEVEL LOG_LEVEL_COAP
#define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_APP
/* FIXME: This server address is hard-coded for Cooja and link-local for unconnected border router. */
#define SERVER_EP "coap://[fe80::212:7402:0002:0202]"

View File

@ -47,15 +47,11 @@
#else
#include "dev/button-sensor.h"
#endif
/*----------------------------------------------------------------------------*/
#define DEBUG 0
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINTFLN(format, ...) printf(format "\n", ##__VA_ARGS__)
#else
#define PRINTF(...)
#define PRINTFLN(...)
#endif
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_APP
/*----------------------------------------------------------------------------*/
/* FIXME: This server address is hard-coded for Cooja */
@ -145,8 +141,6 @@ PROCESS_THREAD(er_example_observe_client, ev, data)
/* store server address in server_ipaddr */
SERVER_NODE(server_ipaddr);
/* receives all CoAP messages */
coap_init_engine();
/* init timer and button (if available) */
etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND);
#if PLATFORM_HAS_BUTTON

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science.
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -27,34 +27,21 @@
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* A brief description of what this file is.
* Erbium (Er) example project configuration.
* \author
* Adam Dunkels <adam@sics.se>
* Matthias Kovatsch <kovatsch@inf.ethz.ch>
*/
#include "dev/leds.h"
static leds_mask_t leds;
/*---------------------------------------------------------------------------*/
void
leds_arch_init(void)
{
leds = 0;
}
/*---------------------------------------------------------------------------*/
leds_mask_t
leds_arch_get(void)
{
return leds;
}
/*---------------------------------------------------------------------------*/
void
leds_arch_set(leds_mask_t l)
{
leds = l;
}
/*---------------------------------------------------------------------------*/
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
#define LOG_LEVEL_APP LOG_LEVEL_DBG
/* Enable client-side support for COAP observe */
#define COAP_OBSERVE_CLIENT 1
#endif /* PROJECT_CONF_H_ */

View File

@ -0,0 +1,14 @@
CONTIKI_PROJECT = coap-example-server
all: $(CONTIKI_PROJECT)
# Do not try to build on Sky because of code size limitation
PLATFORMS_EXCLUDE = sky
# Include the CoAP implementation
MODULES += os/net/app-layer/coap
# Include CoAP resources
MODULES_REL += ./resources
CONTIKI=../../..
include $(CONTIKI)/Makefile.include

View File

@ -48,14 +48,10 @@
#include "dev/button-sensor.h"
#endif
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_APP
/*
* Resources to be activated need to be imported through the extern keyword.
* The build system automatically compiles the resources in the corresponding sub-directory.
@ -84,17 +80,6 @@ extern coap_resource_t res_battery;
#include "dev/temperature-sensor.h"
extern coap_resource_t res_temperature;
#endif
/*
extern coap_resource_t res_battery;
#endif
#if PLATFORM_HAS_RADIO
extern coap_resource_t res_radio;
#endif
#if PLATFORM_HAS_SHT11
#include "dev/sht11/sht11-sensor.h"
extern coap_resource_t res_sht11;
#endif
*/
PROCESS(er_example_server, "Erbium Example Server");
AUTOSTART_PROCESSES(&er_example_server);
@ -105,12 +90,7 @@ PROCESS_THREAD(er_example_server, ev, data)
PROCESS_PAUSE();
PRINTF("Starting Erbium Example Server\n");
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("CoAP max chunk: %u\n", COAP_MAX_CHUNK_SIZE);
LOG_INFO("Starting Erbium Example Server\n");
/*
* Bind the resources to their Uri-Path.
@ -143,15 +123,6 @@ PROCESS_THREAD(er_example_server, ev, data)
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);
#endif
*/
/* Define application-specific events here. */
while(1) {
@ -162,7 +133,7 @@ PROCESS_THREAD(er_example_server, ev, data)
#else
if(ev == sensors_event && data == &button_sensor) {
#endif
PRINTF("*******BUTTON*******\n");
LOG_DBG("*******BUTTON*******\n");
/* Call the event_handler for this application-specific event. */
res_event.trigger();

View File

@ -36,33 +36,9 @@
* Matthias Kovatsch <kovatsch@inf.ethz.ch>
*/
#ifndef PROJECT_ERBIUM_CONF_H_
#define PROJECT_ERBIUM_CONF_H_
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
/* IP buffer size must match all other hops, in particular the border router. */
/* #define UIP_CONF_BUFFER_SIZE 256 */
#define LOG_LEVEL_APP LOG_LEVEL_DBG
/* Increase rpl-border-router IP-buffer when using more than 64. */
#define COAP_MAX_CHUNK_SIZE 48
/* Estimate your header size, especially when using Proxy-Uri. */
/* #define COAP_MAX_HEADER_SIZE 70 */
/* Multiplies with chunk size, be aware of memory constraints. */
#ifndef COAP_MAX_OPEN_TRANSACTIONS
#define COAP_MAX_OPEN_TRANSACTIONS 4
#endif /* COAP_MAX_OPEN_TRANSACTIONS */
/* Must be <= open transactions, default is COAP_MAX_OPEN_TRANSACTIONS-1. */
/* #define COAP_MAX_OBSERVERS 2 */
/* Filtering .well-known/core per query can be disabled to save space. */
#define COAP_LINK_FORMAT_FILTERING 0
#define COAP_PROXY_OPTION_PROCESSING 0
/* Enable client-side support for COAP observe */
#ifndef COAP_OBSERVE_CLIENT
#define COAP_OBSERVE_CLIENT 1
#endif /* COAP_OBSERVE_CLIENT */
#endif /* PROJECT_ERBIUM_CONF_H_ */
#endif /* PROJECT_CONF_H_ */

View File

@ -41,17 +41,10 @@
#include "coap-engine.h"
#include "coap.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
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_APP
static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_event_handler(void);
@ -94,7 +87,7 @@ res_event_handler(void)
/* Usually a condition is defined under with subscribers are notified, e.g., event was above a threshold. */
if(1) {
PRINTF("TICK %u for /%s\n", event_counter, res_event.url);
LOG_DBG("TICK %u for /%s\n", (unsigned)event_counter, res_event.url);
/* Notify the registered observers which will trigger the res_get_handler to create the response. */
coap_notify_observers(&res_event);

View File

@ -75,7 +75,9 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
memcpy(buffer, message, length);
} else {
memcpy(buffer, message, length);
} coap_set_header_content_format(response, TEXT_PLAIN); /* text/plain is the default, hence this option could be omitted. */
}
coap_set_header_content_format(response, TEXT_PLAIN); /* text/plain is the default, hence this option could be omitted. */
coap_set_header_etag(response, (uint8_t *)&length, 1);
coap_set_payload(response, buffer, length);
}

View File

@ -44,17 +44,10 @@
#if PLATFORM_HAS_LEDS || LEDS_COUNT
#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
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_APP
static void res_post_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -76,7 +69,7 @@ res_post_put_handler(coap_message_t *request, coap_message_t *response, uint8_t
int success = 1;
if((len = coap_get_query_variable(request, "color", &color))) {
PRINTF("color %.*s\n", len, color);
LOG_DBG("color %.*s\n", (int)len, color);
if(strncmp(color, "r", len) == 0) {
led = LEDS_RED;
@ -90,7 +83,7 @@ res_post_put_handler(coap_message_t *request, coap_message_t *response, uint8_t
} else {
success = 0;
} if(success && (len = coap_get_post_variable(request, "mode", &mode))) {
PRINTF("mode %s\n", mode);
LOG_DBG("mode %s\n", mode);
if(strncmp(mode, "on", len) == 0) {
leds_on(led);

View File

@ -41,17 +41,10 @@
#include "coap-engine.h"
#include "coap.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
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_APP
static void res_any_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -158,7 +151,7 @@ res_any_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
}
coap_set_payload(response, buffer, strpos);
PRINTF("/mirror options received: %s\n", buffer);
LOG_DBG("/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. */
coap_set_header_content_format(response, TEXT_PLAIN);

View File

@ -0,0 +1,14 @@
CONTIKI_PROJECT = coap-plugtest-server
all: $(CONTIKI_PROJECT)
# Only intended for native
PLATFORMS_ONLY = native
# Include the CoAP implementation
MODULES += os/net/app-layer/coap
# Include CoAP resources
MODULES_REL += ./resources
CONTIKI=../../..
include $(CONTIKI)/Makefile.include

View File

@ -45,7 +45,11 @@
#include "coap-transactions.h"
#include "coap-separate.h"
#include "coap-engine.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
/*
* Resources to be activated need to be imported through the extern keyword.
@ -80,12 +84,7 @@ PROCESS_THREAD(plugtest_server, ev, data)
{
PROCESS_BEGIN();
PRINTF("ETSI IoT CoAP Plugtests Server\n");
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);
LOG_INFO("ETSI IoT CoAP Plugtests Server\n");
/* Activate the application-specific resources. */
coap_activate_resource(&res_plugtest_test, "test");

View File

@ -36,20 +36,10 @@
* Matthias Kovatsch <kovatsch@inf.ethz.ch>
*/
#ifndef PLUGTEST_H_
#define PLUGTEST_H_
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
#if !defined(CONTIKI_TARGET_NATIVE)
#warning "Should only be compiled for native!"
#endif
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
#define LOG_LEVEL_PLUGTEST LOG_LEVEL_DBG
/* double expansion */
#define TO_STRING2(x) # x
@ -59,4 +49,4 @@
#define MAX_PLUGFEST_BODY 2048
#define CHUNKS_TOTAL 2012
#endif /* PLUGTEST_H_ */
#endif /* PROJECT_CONF_H_ */

View File

@ -0,0 +1,171 @@
/*
* 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
* Example resource
* \author
* Matthias Kovatsch <kovatsch@inf.ethz.ch>
*/
#include <stdio.h>
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_any_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
/* This resource mirrors the incoming request. It shows how to access the options and how to set them for the response. */
RESOURCE(res_mirror,
"title=\"Returns your decoded message\";rt=\"Debug\"",
res_any_handler,
res_any_handler,
res_any_handler,
res_any_handler);
static void
res_any_handler(coap_message_t *request, coap_message_t *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 };
/* No default my be assumed for the Content-Format. (Unsigned -1 means all bits set.) */
unsigned int content_format = -1;
/* 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 longint = 0;
const char *str = NULL;
const uint8_t *bytes = NULL;
uint32_t block_num = 0;
uint8_t block_more = 0;
uint16_t block_size = 0;
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, as the payload does not need a terminating '\0'. */
if(coap_get_header_content_format(request, &content_format)) {
strpos += snprintf((char *)buffer, REST_MAX_CHUNK_SIZE + 1, "CF %u\n", content_format);
}
if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_accept(request, &content_format))) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "Ac %u\n", content_format);
/* 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 && coap_get_header_max_age(request, &longint)) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "MA %lu\n", (unsigned long) longint);
/* For HTTP this is the Length option, for CoAP it is the Size option. */
}
if(strpos <= REST_MAX_CHUNK_SIZE && coap_get_header_size1(request, &longint)) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "SZ %lu\n", (unsigned long) longint);
}
if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_uri_host(request, &str))) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "UH %.*s\n", len, str);
}
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 %.*s\n", len, str);
}
if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_uri_query(request, &str))) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "UQ %.*s\n", len, str);
/* Undefined request options for debugging: actions not required for normal RESTful Web service. */
}
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);
/* CoAP-specific example: actions not required for normal RESTful Web service. */
}
coap_message_t *const coap_pkt = (coap_message_t *)request;
if(strpos <= REST_MAX_CHUNK_SIZE && coap_pkt->token_len > 0) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "To 0x");
int index = 0;
for(index = 0; index < coap_pkt->token_len; ++index) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "%02X", coap_pkt->token[index]);
}
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "\n");
}
if(strpos <= REST_MAX_CHUNK_SIZE && coap_is_option(coap_pkt, COAP_OPTION_OBSERVE)) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "Ob %lu\n", (unsigned long) coap_pkt->observe);
}
if(strpos <= REST_MAX_CHUNK_SIZE && coap_is_option(coap_pkt, COAP_OPTION_ETAG)) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "ET 0x");
int index = 0;
for(index = 0; index < coap_pkt->etag_len; ++index) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "%02X", coap_pkt->etag[index]);
}
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "\n");
}
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", (unsigned long) block_num, block_more ? "+" : "", block_size);
}
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", (unsigned long) block_num, block_more ? "+" : "", block_size);
}
if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_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 */
}
coap_set_payload(response, buffer, strpos);
LOG_DBG("/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. */
coap_set_header_content_format(response, TEXT_PLAIN);
coap_set_header_max_age(response, 17); /* For HTTP, browsers will not re-request the page for 17 seconds. */
coap_set_header_etag(response, opaque, 2);
coap_set_header_location_path(response, location); /* Initial slash is omitted by framework */
coap_set_header_size1(response, strpos); /* For HTTP, browsers will not re-request the page for 10 s. CoAP action depends on the client. */
/* CoAP-specific example: actions not required for normal RESTful Web service. */
coap_set_header_uri_host(response, "tiki");
coap_set_header_observe(response, 10);
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);
}

View File

@ -39,7 +39,11 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -56,7 +60,7 @@ static uint8_t create1_exists = 0;
static void
res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
PRINTF("/create1 PUT");
LOG_DBG("/create1 PUT");
if(coap_get_header_if_none_match(request)) {
if(!create1_exists) {
@ -73,7 +77,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
static void
res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
PRINTF("/create1 DELETE ");
LOG_DBG("/create1 DELETE ");
coap_set_status_code(response, DELETED_2_02);
create1_exists = 0;

View File

@ -39,7 +39,11 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -53,7 +57,7 @@ RESOURCE(res_plugtest_create2,
static void
res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
PRINTF("/create2 ");
LOG_DBG("/create2 ");
coap_set_status_code(response, CREATED_2_01);
coap_set_header_location_path(response, "/location1/location2/location3");

View File

@ -39,7 +39,11 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -56,7 +60,7 @@ static uint8_t create3_exists = 0;
static void
res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
PRINTF("/create3 PUT ");
LOG_DBG("/create3 PUT ");
if(coap_get_header_if_none_match(request)) {
if(!create3_exists) {
@ -73,7 +77,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
static void
res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
PRINTF("/create3 DELETE ");
LOG_DBG("/create3 DELETE ");
coap_set_status_code(response, DELETED_2_02);
create3_exists = 0;

View File

@ -39,7 +39,11 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);

View File

@ -41,7 +41,11 @@
#include "sys/cc.h"
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);

View File

@ -40,7 +40,11 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);

View File

@ -39,7 +39,11 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);

View File

@ -39,7 +39,11 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -53,11 +57,9 @@ RESOURCE(res_plugtest_locquery,
static void
res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
#if DEBUG
coap_message_t *const coap_req = (coap_message_t *)request;
#endif
PRINTF(
LOG_DBG(
"/location-query POST (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
coap_set_status_code(response, CREATED_2_01);

View File

@ -41,7 +41,11 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -57,7 +61,7 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
{
coap_message_t *const coap_req = (coap_message_t *)request;
PRINTF("/seg1/seg2/seg3 GET ");
LOG_DBG("/seg1/seg2/seg3 GET ");
/* Code 2.05 CONTENT is default. */
coap_set_header_content_format(response, TEXT_PLAIN);
coap_set_payload(
@ -66,5 +70,5 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD,
"Type: %u\nCode: %u\nMID: %u", coap_req->type, coap_req->code, coap_req->mid));
PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
LOG_DBG_("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
}

View File

@ -40,7 +40,11 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -59,7 +63,7 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
unsigned int accept = -1;
coap_get_header_accept(request, &accept);
PRINTF("/multi-format GET (%s %u) ", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
LOG_DBG("/multi-format GET (%s %u) ", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
if(accept == -1 || accept == TEXT_PLAIN) {
coap_set_header_content_format(response, TEXT_PLAIN);
@ -69,7 +73,7 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD,
"Type: %u\nCode: %u\nMID: %u%s", coap_req->type, coap_req->code,
coap_req->mid, accept != -1 ? "\nAccept: 0" : ""));
PRINTF("PLAIN\n");
LOG_DBG_("PLAIN\n");
} else if(accept == APPLICATION_XML) {
coap_set_header_content_format(response, APPLICATION_XML);
coap_set_payload(
@ -78,11 +82,11 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD,
"<status type=\"%u\" code=\"%u\" mid=\"%u\" accept=\"%u\"/>",
coap_req->type, coap_req->code, coap_req->mid, accept));
PRINTF("XML\n");
LOG_DBG_("XML\n");
} else {
coap_set_status_code(response, NOT_ACCEPTABLE_4_06);
const char *msg = "Supporting content-types text/plain and application/xml";
coap_set_payload(response, msg, strlen(msg));
PRINTF("ERROR\n");
LOG_DBG_("ERROR\n");
}
}

View File

@ -41,7 +41,11 @@
#include "coap-engine.h"
#include "coap.h"
#include "coap-observe.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -67,7 +71,7 @@ static char obs_status = 0;
static void
obs_purge_list()
{
PRINTF("### SERVER ACTION ### Purging obs list");
LOG_DBG("### SERVER ACTION ### Purging obs list\n");
coap_remove_observer_by_uri(NULL, res_plugtest_obs.url);
}
static void
@ -75,7 +79,7 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
{
/* Keep server log clean from ticking events */
if(request != NULL) {
PRINTF("/obs GET\n");
LOG_DBG("/obs GET\n");
}
coap_set_header_content_format(response, obs_format);
coap_set_header_max_age(response, 5);
@ -98,7 +102,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
coap_get_header_content_format(request, &ct);
PRINTF("/obs PUT\n");
LOG_DBG("/obs PUT\n");
if(ct != obs_format) {
obs_status = 1;
@ -115,7 +119,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
static void
res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
PRINTF("/obs DELETE\n");
LOG_DBG("/obs DELETE\n");
obs_status = 2;
@ -130,14 +134,12 @@ res_periodic_handler()
{
++obs_counter;
/* PRINTF("TICK %u for /%s\n", obs_counter, r->url); */
if(obs_status == 1) {
/* Notify the registered observers with the given message type, observe option, and payload. */
coap_notify_observers(&res_plugtest_obs);
PRINTF("######### sending 5.00\n");
LOG_DBG("######### sending 5.00\n");
obs_purge_list();
} else if(obs_status == 2) {

View File

@ -40,7 +40,11 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);

View File

@ -40,7 +40,11 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -58,11 +62,11 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
int len = 0;
const char *query = NULL;
PRINTF(
LOG_DBG(
"/query GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
if((len = coap_get_header_uri_query(request, &query))) {
PRINTF("Query: %.*s\n", len, query);
LOG_DBG("Query: %.*s\n", len, query);
/* Code 2.05 CONTENT is default. */
}
coap_set_header_content_format(response,

View File

@ -42,7 +42,11 @@
#include "coap.h"
#include "coap-transactions.h"
#include "coap-separate.h"
#include "plugtest.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_resume_handler(void);
@ -72,12 +76,12 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
{
coap_message_t *const coap_req = (coap_message_t *)request;
PRINTF("/separate ");
LOG_DBG("/separate ");
if(separate_active) {
PRINTF("REJECTED ");
LOG_DBG_("REJECTED ");
coap_separate_reject();
} else {
PRINTF("STORED ");
LOG_DBG_("STORED ");
separate_active = 1;
/* Take over and skip response by engine. */
@ -89,17 +93,17 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
coap_req->mid);
}
PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
LOG_DBG_("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
}
static void
res_resume_handler()
{
if(separate_active) {
PRINTF("/separate ");
LOG_DBG("/separate ");
coap_transaction_t *transaction = NULL;
if((transaction = coap_new_transaction(separate_store->request_metadata.mid,
&separate_store->request_metadata.endpoint))) {
PRINTF(
LOG_DBG_(
"RESPONSE (%s %u)\n", separate_store->request_metadata.type == COAP_TYPE_CON ? "CON" : "NON", separate_store->request_metadata.mid);
coap_message_t response[1]; /* This way the message can be treated as pointer as usual. */
@ -127,7 +131,7 @@ res_resume_handler()
separate_active = 0;
} else {
PRINTF("ERROR (transaction)\n");
LOG_DBG_("ERROR (transaction)\n");
}
} /* if (separate_active) */
}

View File

@ -40,9 +40,13 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
#include "random.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -68,7 +72,7 @@ test_update_etag()
}
test_change = 0;
PRINTF("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", test_etag_len, test_etag[0], test_etag[1], test_etag[2], test_etag[3], test_etag[4], test_etag[5], test_etag[6], test_etag[7]);
LOG_DBG("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", test_etag_len, test_etag[0], test_etag[1], test_etag[2], test_etag[3], test_etag[4], test_etag[5], test_etag[6], test_etag[7]);
}
static void
res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
@ -78,17 +82,17 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
if(test_change) {
test_update_etag();
}
PRINTF("/test GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
LOG_DBG("/test GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
if((len = coap_get_header_etag(request, &bytes)) > 0
&& len == test_etag_len
&& memcmp(test_etag, bytes, len) == 0) {
PRINTF("validate ");
LOG_DBG("validate\n");
coap_set_status_code(response, VALID_2_03);
coap_set_header_etag(response, test_etag, test_etag_len);
test_change = 1;
PRINTF("### SERVER ACTION ### Resource will change\n");
LOG_DBG("### SERVER ACTION ### Resource will change\n");
} else {
/* Code 2.05 CONTENT is default. */
coap_set_header_content_format(response, TEXT_PLAIN);
@ -103,32 +107,28 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
static void
res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
#if DEBUG
coap_message_t *const coap_req = (coap_message_t *)request;
PRINTF("/test POST (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
#endif
LOG_DBG("/test POST (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
coap_set_status_code(response, CREATED_2_01);
coap_set_header_location_path(response, "/location1/location2/location3");
}
static void
res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
#if DEBUG
coap_message_t *const coap_req = (coap_message_t *)request;
PRINTF("/test PUT (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
#endif
LOG_DBG("/test PUT (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
if(coap_get_header_if_none_match(request)) {
if(test_none_match_okay) {
coap_set_status_code(response, CREATED_2_01);
test_none_match_okay = 0;
PRINTF("### SERVER ACTION ### If-None-Match will FAIL\n");
LOG_DBG("### SERVER ACTION ### If-None-Match will FAIL\n");
} else {
coap_set_status_code(response, PRECONDITION_FAILED_4_12);
test_none_match_okay = 1;
PRINTF("### SERVER ACTION ### If-None-Match will SUCCEED\n");
LOG_DBG("### SERVER ACTION ### If-None-Match will SUCCEED\n");
}
} else if(((len = coap_get_header_if_match(request, &bytes)) > 0
&& (len == test_etag_len
@ -141,12 +141,12 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
if(len > 0) {
test_change = 1;
PRINTF("### SERVER ACTION ### Resource will change\n");
LOG_DBG("### SERVER ACTION ### Resource will change\n");
}
} else {
PRINTF("Check %u/%u\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
len,
test_etag_len,
LOG_DBG("Check %u/%u\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
(unsigned)len,
(unsigned)test_etag_len,
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
test_etag[0], test_etag[1], test_etag[2], test_etag[3], test_etag[4], test_etag[5], test_etag[6], test_etag[7]);
@ -156,9 +156,7 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
static void
res_delete_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
#if DEBUG
coap_message_t *const coap_req = (coap_message_t *)request;
PRINTF("/test DELETE (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
#endif
LOG_DBG("/test DELETE (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
coap_set_status_code(response, DELETED_2_02);
}

View File

@ -40,9 +40,13 @@
#include <string.h>
#include "coap-engine.h"
#include "coap.h"
#include "plugtest.h"
#include "random.h"
/* Log configuration */
#include "sys/log.h"
#define LOG_MODULE "Plugtest"
#define LOG_LEVEL LOG_LEVEL_PLUGTEST
static void res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -70,7 +74,7 @@ validate_update_etag()
}
validate_change = 0;
PRINTF("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
LOG_DBG("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
validate_etag_len, validate_etag[0], validate_etag[1], validate_etag[2], validate_etag[3], validate_etag[4], validate_etag[5], validate_etag[6], validate_etag[7]);
}
static void
@ -81,17 +85,17 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
if(validate_change) {
validate_update_etag();
}
PRINTF("/validate GET");
PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
LOG_DBG("/validate GET");
LOG_DBG_("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
if((len = coap_get_header_etag(request, &bytes)) > 0
&& len == validate_etag_len && memcmp(validate_etag, bytes, len) == 0) {
PRINTF("validate ");
LOG_DBG("validate\n");
coap_set_status_code(response, VALID_2_03);
coap_set_header_etag(response, validate_etag, validate_etag_len);
validate_change = 1;
PRINTF("### SERVER ACTION ### Resouce will change\n");
LOG_DBG("### SERVER ACTION ### Resouce will change\n");
} else {
/* Code 2.05 CONTENT is default. */
coap_set_header_content_format(response, TEXT_PLAIN);
@ -108,12 +112,10 @@ res_get_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
static void
res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
#if DEBUG
coap_message_t *const coap_req = (coap_message_t *)request;
#endif
PRINTF("/validate PUT ");
PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
LOG_DBG("/validate PUT ");
LOG_DBG_("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
if(((len = coap_get_header_if_match(request, &bytes)) > 0
&& (len == validate_etag_len
@ -126,13 +128,13 @@ res_put_handler(coap_message_t *request, coap_message_t *response, uint8_t *buff
if(len > 0) {
validate_change = 1;
PRINTF("### SERVER ACTION ### Resouce will change\n");
LOG_DBG("### SERVER ACTION ### Resouce will change\n");
}
} else {
PRINTF(
"Check %u/%u\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n [0x%02X%02X%02X%02X%02X%02X%02X%02X] ",
len,
validate_etag_len,
LOG_DBG(
"Check %u/%u\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
(unsigned)len,
(unsigned)validate_etag_len,
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
validate_etag[0], validate_etag[1], validate_etag[2], validate_etag[3], validate_etag[4], validate_etag[5], validate_etag[6], validate_etag[7]);

View File

@ -3,6 +3,6 @@ CONTIKI = ../../..
all: $(CONTIKI_PROJECT)
PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul
PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native
include $(CONTIKI)/Makefile.include

View File

@ -47,10 +47,13 @@ PROCESS_THREAD(button_hal_example, ev, data)
printf("Button HAL example.\n");
printf("Device button count: %u.\n", button_hal_button_count);
if(btn) {
printf("%s on pin %u with ID=0, Logic=%s, Pull=%s\n",
BUTTON_HAL_GET_DESCRIPTION(btn), btn->pin,
btn->negative_logic ? "Negative" : "Positive",
btn->pull == GPIO_HAL_PIN_CFG_PULL_UP ? "Pull Up" : "Pull Down");
}
while(1) {

View File

@ -1,7 +1,7 @@
CONTIKI_PROJECT = gpio-hal-example
CONTIKI = ../../..
PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul
PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native
include $(CONTIKI)/Makefile.identify-target

View File

@ -36,6 +36,7 @@
#include "dev/button-hal.h"
#include <stdio.h>
#include <inttypes.h>
/*---------------------------------------------------------------------------*/
extern gpio_hal_pin_t out_pin1, out_pin2, out_pin3;
extern gpio_hal_pin_t btn_pin;
@ -43,6 +44,13 @@ extern gpio_hal_pin_t btn_pin;
static struct etimer et;
static uint8_t counter;
/*---------------------------------------------------------------------------*/
/* Print gpio_hal_pin_mask_t using the correct format */
#if GPIO_HAL_PIN_COUNT > 32
#define PIN_MASK_FMT PRIx64
#else
#define PIN_MASK_FMT PRIx32
#endif
/*---------------------------------------------------------------------------*/
PROCESS(gpio_hal_example, "GPIO HAL Example");
AUTOSTART_PROCESSES(&gpio_hal_example);
/*---------------------------------------------------------------------------*/
@ -119,7 +127,8 @@ PROCESS_THREAD(gpio_hal_example, ev, data)
}
/* Test read */
printf("%u: Pins are 1-%u, 2=%u, 3=%u, mask=0x%08lx\n", counter & 7,
printf("%u: Pins are 1-%u, 2=%u, 3=%u, mask=0x%08" PIN_MASK_FMT "\n",
counter & 7,
gpio_hal_arch_read_pin(out_pin1),
gpio_hal_arch_read_pin(out_pin2),
gpio_hal_arch_read_pin(out_pin3),

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2018, George Oikonomou - http://www.spd.gr
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "dev/gpio-hal.h"
/*---------------------------------------------------------------------------*/
gpio_hal_pin_t out_pin1 = 0;
gpio_hal_pin_t out_pin2 = 1;
gpio_hal_pin_t out_pin3 = 2;
/*---------------------------------------------------------------------------*/
gpio_hal_pin_t btn_pin = 4;
/*---------------------------------------------------------------------------*/

View File

@ -46,10 +46,21 @@ AUTOSTART_PROCESSES(&hello_world_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
static struct etimer timer;
PROCESS_BEGIN();
/* Setup a periodic timer that expires after 10 seconds. */
etimer_set(&timer, CLOCK_SECOND * 10);
while(1) {
printf("Hello, world\n");
/* Wait for the periodic timer to expire and then restart the timer. */
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
etimer_reset(&timer);
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -1,27 +0,0 @@
CONTIKI_PROJECT = example-ipso-objects
CONTIKI_SOURCEFILES += serial-protocol.c example-ipso-temperature.c
PLATFORMS_EXCLUDE = sky
all: $(CONTIKI_PROJECT)
MODULES += os/net/app-layer/coap
MODULES += os/services/lwm2m
MODULES += os/services/ipso-objects
CONTIKI=../..
include $(CONTIKI)/Makefile.include
# border router rules
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
connect-router: $(CONTIKI)/tools/tunslip6
sudo $(CONTIKI)/tools/tunslip6 aaaa::1/64
connect-router-cooja: $(CONTIKI)/tools/tunslip6
sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 -p 60001 aaaa::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 aaaa::1/64

View File

@ -1,48 +0,0 @@
IPSO Objects Example
============================================
This is an example of how to make use of the IPSO Object and LWM2M
implementation in Contiki.
The LWM2M implementation is based on the Erbium CoAP implementation
and consists of two apps: lwm2m-engine and ipso-objects. The
lwm2m-engine handle the specifics of LWM2M including bootstrapping and
how read/writes of objects and resources are handled. The ipso-objects
contains implementations of some of the IPSO Smart Objects.
The implementation was used during the IPSO Interop in May 2015,
Kista, Sweden, and was successfully tested with other
implementations.
The examples use some of the basic IPSO object for controlling LEDs on
Contiki devices and for reading out temperature.
##Testing IPSO-objects with Leshan
First program a device with the examples/ipso-objects/example-ipso-objects.c
```bash
>make example-ipso-objects.upload TARGET=zoul
>...
```
After that start up a native-border router or other border router on fd00::1/64
or another prefix - NOTE: if you use another prefix you will need to change LWM2M_SERVER_ADDRESS for which the device will register - in project-conf.h:
```
#define LWM2M_SERVER_ADDRESS "fd00::1"
```
Then when everything is setup you can download a Leshan and use that to
test controlling LEDs of the device.
###Starting Leshan
```bash
wget https://hudson.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-standalone.jar
java -jar ./leshan-standalone.jar
```
Browse to leshans device page with http://127.0.0.1:8080 .
When you have started the border-router and also Leshan you should now
start (or reboot) your IPSO Object enabled device. Within 30 seconds
you should be able to see it on the Leshan device page.

View File

@ -1,5 +1,5 @@
CONTIKI_PROJECT = ipv6-hooks
all: $(CONTIKI_PROJECT)
CONTIKI=../..
CONTIKI=../../..
include $(CONTIKI)/Makefile.include

View File

@ -36,9 +36,9 @@
*
*/
#ifndef __PROJECT_CONF_H__
#define __PROJECT_CONF_H__
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
#define STACK_CHECK_CONF_ENABLED 1
#endif /* __PROJECT_CONF_H__ */
#endif /* PROJECT_CONF_H_ */

View File

@ -0,0 +1,14 @@
CONTIKI_PROJECT = example-ipso-objects
CONTIKI_SOURCEFILES += serial-protocol.c example-ipso-temperature.c
PLATFORMS_EXCLUDE = sky
all: $(CONTIKI_PROJECT)
MODULES += os/net/app-layer/coap
MODULES += os/services/lwm2m
MODULES += os/services/ipso-objects
CONTIKI=../..
include $(CONTIKI)/Makefile.include

View File

@ -0,0 +1,10 @@
LWM2M with IPSO Objects Example
============================================
This is an OMA LWM2M example implementing IPSO Objects.
It can connect to a Leshan server out-of-the-box.
Important configuration parameters:
* `LWM2M_SERVER_ADDRESS`: the address of the server to register to (or bootstrap from)
* `REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER`: set to bootstrap via `LWM2M_SERVER_ADDRESS` and then obtain the registration server address
A tutorial for setting up this example is provided on the wiki.

View File

@ -38,20 +38,24 @@
#include "contiki.h"
#include "net/ipv6/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/netstack.h"
#include "net/routing/routing.h"
#include "coap-constants.h"
#include "coap-engine.h"
#include "coap-transport.h"
#include "coap-blocking-api.h"
#include "lwm2m-engine.h"
#include "lwm2m-tlv.h"
#include "dev/serial-line.h"
#include "serial-protocol.h"
#include <stdbool.h>
#define DEBUG DEBUG_PRINT
#include "net/ipv6/uip-debug.h"
#define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT)
#define EVENT_RUN_NOW 0
#define URL_WELL_KNOWN ".well-known/core"
#define URL_DEVICE_MODEL "/3/0/1"
#define URL_DEVICE_FIRMWARE_VERSION "/3/0/3"
@ -63,8 +67,8 @@
#define NODE_HAS_TYPE (1 << 0)
struct node {
uip_ipaddr_t ipaddr;
char type[32];
coap_endpoint_t endpoint;
char type[64];
uint8_t flags;
uint8_t retries;
};
@ -86,13 +90,15 @@ add_node(const uip_ipaddr_t *addr)
{
int i;
for(i = 0; i < node_count; i++) {
if(uip_ipaddr_cmp(&nodes[i].ipaddr, addr)) {
if(uip_ipaddr_cmp(&nodes[i].endpoint.ipaddr, addr)) {
/* Node already added */
return &nodes[i];
}
}
if(node_count < MAX_NODES) {
uip_ipaddr_copy(&nodes[node_count].ipaddr, addr);
memset(&nodes[node_count].endpoint, 0, sizeof(coap_endpoint_t));
uip_ipaddr_copy(&nodes[node_count].endpoint.ipaddr, addr);
nodes[node_count].endpoint.port = REMOTE_PORT;
return &nodes[node_count++];
}
return NULL;
@ -107,13 +113,13 @@ set_value(const uip_ipaddr_t *addr, char *uri, char *value)
printf(" URI: %s Value: %s\n", uri, value);
for(i = 0; i < node_count; i++) {
if(uip_ipaddr_cmp(&nodes[i].ipaddr, addr)) {
if(uip_ipaddr_cmp(&nodes[i].endpoint.ipaddr, addr)) {
/* setup command */
current_target = &nodes[i];
current_request = COAP_PUT;
strncpy(current_uri, uri, sizeof(current_uri) - 1);
strncpy(current_value, value, sizeof(current_value) - 1);
process_poll(&router_process);
process_post(&router_process, EVENT_RUN_NOW, NULL);
break;
}
}
@ -128,13 +134,13 @@ get_value(const uip_ipaddr_t *addr, char *uri)
printf(" URI: %s\n", uri);
for(i = 0; i < node_count; i++) {
if(uip_ipaddr_cmp(&nodes[i].ipaddr, addr)) {
if(uip_ipaddr_cmp(&nodes[i].endpoint.ipaddr, addr)) {
/* setup command */
current_target = &nodes[i];
current_request = COAP_GET;
strncpy(current_uri, uri, sizeof(current_uri) - 1);
current_value[0] = 0;
process_poll(&router_process);
process_post(&router_process, EVENT_RUN_NOW, NULL);
break;
}
}
@ -151,7 +157,7 @@ print_node_list(void)
printf(";");
}
printf("%s,", nodes[i].type);
uip_debug_ipaddr_print(&nodes[i].ipaddr);
uip_debug_ipaddr_print(&nodes[i].endpoint.ipaddr);
}
}
printf("\n");
@ -162,7 +168,7 @@ print_node_list(void)
* handle responses.
*/
static void
client_chunk_handler(void *response)
client_chunk_handler(coap_message_t *response)
{
const uint8_t *chunk;
unsigned int format;
@ -172,7 +178,9 @@ client_chunk_handler(void *response)
/* if(len > 0) { */
/* printf("|%.*s (%d,%d)", len, (char *)chunk, len, format); */
/* } */
if(current_target != NULL && fetching_type) {
if(response->code >= BAD_REQUEST_4_00) {
PRINTF("\nReceived error %u: %.*s\n", response->code, len, (char *)chunk);
} else if(current_target != NULL && fetching_type) {
if(len > sizeof(current_target->type) - 1) {
len = sizeof(current_target->type) - 1;
}
@ -181,7 +189,7 @@ client_chunk_handler(void *response)
current_target->flags |= NODE_HAS_TYPE;
PRINTF("\nNODE ");
PRINT6ADDR(&current_target->ipaddr);
PRINT6ADDR(&current_target->endpoint.ipaddr);
PRINTF(" HAS TYPE %s\n", current_target->type);
} else {
/* otherwise update the current value */
@ -193,7 +201,9 @@ client_chunk_handler(void *response)
/* tlv.type, tlv.length, tlv.id, tlv.value[0]); */
int value = lwm2m_tlv_get_int32(&tlv);
snprintf(current_value, sizeof(current_value), "%d", value);
snprintf(current_value, sizeof(current_value) - 1, "%d", value);
} else {
PRINTF("Failed to parse LWM2M TLV\n");
}
} else {
if(len > sizeof(current_value) - 1) {
@ -205,82 +215,48 @@ client_chunk_handler(void *response)
}
}
/*---------------------------------------------------------------------------*/
static void
setup_network(void)
#if UIP_CONF_IPV6_RPL
static bool
check_rpl_routes(void)
{
uip_ipaddr_t ipaddr;
struct uip_ds6_addr *root_if;
rpl_dag_t *dag;
int i;
uint8_t state;
uip_sr_node_t *link;
uip_ipaddr_t child_ipaddr;
uip_ipaddr_t parent_ipaddr;
#if UIP_CONF_ROUTER
/**
* The choice of server address determines its 6LoWPAN header compression.
* Obviously the choice made here must also be selected in udp-client.c.
*
* For correct Wireshark decoding using a sniffer, add the /64 prefix to the 6LowPAN protocol preferences,
* e.g. set Context 0 to fd00::. At present Wireshark copies Context/128 and then overwrites it.
* (Setting Context 0 to fd00::1111:2222:3333:4444 will report a 16 bit compressed address of fd00::1111:22ff:fe33:xxxx)
* Note Wireshark's IPCMV6 checksum verification depends on the correct uncompressed addresses.
*/
#if 0
/* Mode 1 - 64 bits inline */
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 1);
#elif 1
/* Mode 2 - 16 bits inline */
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0x00ff, 0xfe00, 1);
#else
/* Mode 3 - derived from link local (MAC) address */
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
#endif
/* Our routing links */
for(link = uip_sr_node_head(); link != NULL; link = uip_sr_node_next(link)) {
NETSTACK_ROUTING.get_sr_node_ipaddr(&child_ipaddr, link);
NETSTACK_ROUTING.root_set_prefix(&ipaddr, &ipaddr);
NETSTACK_ROUTING.root_start();
#endif /* UIP_CONF_ROUTER */
if(link->parent == NULL) {
/* Igore the DAG root */
continue;
}
PRINTF("IPv6 addresses: ");
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state;
if(state == ADDR_TENTATIVE || state == ADDR_PREFERRED) {
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
current_target = add_node(&child_ipaddr);
if(current_target == NULL ||
(current_target->flags & NODE_HAS_TYPE) != 0 ||
current_target->retries > 5) {
continue;
}
NETSTACK_ROUTING.get_sr_node_ipaddr(&parent_ipaddr, link->parent);
PRINTF(" ");
PRINT6ADDR(&child_ipaddr);
PRINTF(" -> ");
PRINT6ADDR(&parent_ipaddr);
PRINTF("\n");
/* hack to make address "final" */
if (state == ADDR_TENTATIVE) {
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
}
}
return true;
}
return false;
}
#endif /* UIP_CONF_IPV6_RPL */
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(router_process, ev, data)
#if (UIP_MAX_ROUTES != 0)
static bool
check_routes(void)
{
/* This way the message can be treated as pointer as usual. */
static coap_message_t request[1];
static struct etimer timer;
uip_ds6_route_t *r;
uip_ipaddr_t *nexthop;
int n;
PROCESS_BEGIN();
PROCESS_PAUSE();
setup_network();
while(1) {
etimer_set(&timer, CLOCK_SECOND * 5);
PROCESS_YIELD();
/* Handle serial line input */
if(ev == serial_line_event_message) {
serial_protocol_input((char *) data);
}
if(etimer_expired(&timer)) {
current_target = NULL;
n = 0;
for(r = uip_ds6_route_head(); r != NULL; r = uip_ds6_route_next(r)) {
current_target = add_node(&r->ipaddr);
if(current_target == NULL ||
@ -294,14 +270,47 @@ PROCESS_THREAD(router_process, ev, data)
nexthop = uip_ds6_route_nexthop(r);
if(nexthop != NULL) {
PRINT6ADDR(nexthop);
PRINTF("\n");
} else {
PRINTF("-");
}
PRINTF("\n");
n++;
break;
return true;
}
return false;
}
#endif /* (UIP_MAX_ROUTES != 0) */
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(router_process, ev, data)
{
/* This way the message can be treated as pointer as usual. */
static coap_message_t request[1];
static struct etimer timer;
PROCESS_BEGIN();
/* Initialize DAG root */
NETSTACK_ROUTING.root_start();
while(1) {
etimer_set(&timer, CLOCK_SECOND * 5);
PROCESS_YIELD();
/* Handle serial line input */
if(ev == serial_line_event_message) {
serial_protocol_input((char *) data);
}
if(etimer_expired(&timer)) {
current_target = NULL;
#if UIP_CONF_IPV6_RPL
check_rpl_routes();
#endif /* UIP_CONF_IPV6_RPL */
#if (UIP_MAX_ROUTES != 0)
if(current_target == NULL) {
check_routes();
}
#endif /* (UIP_MAX_ROUTES != 0) */
}
/* This is a node type discovery */
@ -316,15 +325,15 @@ PROCESS_THREAD(router_process, ev, data)
current_target->retries++;
PRINTF("CoAP request to [");
PRINT6ADDR(&current_target->ipaddr);
PRINTF("]:%u (%u tx)\n", UIP_HTONS(REMOTE_PORT),
PRINT6ADDR(&current_target->endpoint.ipaddr);
PRINTF("]:%u (%u tx)\n", UIP_HTONS(current_target->endpoint.port),
current_target->retries);
fetching_type = 1;
COAP_BLOCKING_REQUEST(&current_target->ipaddr, REMOTE_PORT, request,
COAP_BLOCKING_REQUEST(&current_target->endpoint, request,
client_chunk_handler);
fetching_type = 0;
strncpy(current_uri, URL_LIGHT_CONTROL, sizeof(current_uri));
strncpy(current_uri, URL_LIGHT_CONTROL, sizeof(current_uri) - 1);
printf("\n--Done--\n");
}
@ -341,10 +350,11 @@ PROCESS_THREAD(router_process, ev, data)
}
PRINTF("CoAP request to [");
PRINT6ADDR(&current_target->ipaddr);
PRINTF("]:%u %s\n", UIP_HTONS(REMOTE_PORT), current_uri);
PRINT6ADDR(&current_target->endpoint.ipaddr);
PRINTF("]:%u %s\n", UIP_HTONS(current_target->endpoint.port),
current_uri);
COAP_BLOCKING_REQUEST(&current_target->ipaddr, REMOTE_PORT, request,
COAP_BLOCKING_REQUEST(&current_target->endpoint, request,
client_chunk_handler);
/* print out result of command */
@ -353,13 +363,12 @@ PROCESS_THREAD(router_process, ev, data)
} else {
printf("g ");
}
uip_debug_ipaddr_print(&current_target->ipaddr);
uip_debug_ipaddr_print(&current_target->endpoint.ipaddr);
printf(" %s %s\n", current_uri, current_value);
current_target = NULL;
current_uri[0] = 0;
current_value[0] = 0;
}
}

View File

@ -60,7 +60,7 @@ find_next_sep(const char *str, char sep, int pos)
/*
* l - list all discovered devices
* s - set <IP> <URI> <value>
* d - get <IP> <URI>
* g - get <IP> <URI>
*/
void
serial_protocol_input(char *data)
@ -119,8 +119,12 @@ serial_protocol_input(char *data)
}
break;
}
case '\0':
/* Ignore empty lines */
break;
default:
printf("Unknown command\n");
}
printf("> ");
}
/*---------------------------------------------------------------------------*/

View File

@ -8,6 +8,6 @@ CONTIKI = ../..
MODULES_REL += arch/platform/$(TARGET)
PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul
PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native
include $(CONTIKI)/Makefile.include

View File

@ -13,25 +13,34 @@ The demo will give some visual feedback with a LED (configurable):
This example is known to work with all platforms that support the new button
API.
This example can operate in two modes: A default mode to be used with the
mosquitto MQTT broker and a second mode to be used with the IBM Watson IoT
platform.
To enable Watson mode, define `MQTT_CLIENT_CONF_WITH_IBM_WATSON` as 1 in the
example's `project-conf.h`.
Publishing
----------
By default the example will attempt to publish readings to an MQTT broker
running on the IPv6 address specified as `MQTT_DEMO_BROKER_IP_ADDR` in
running on the IPv6 address specified as `MQTT_CLIENT_CONF_BROKER_IP_ADDR` in
`project-conf.h`. This functionality was tested successfully with
[mosquitto](http://mosquitto.org/).
[mosquitto](http://mosquitto.org/). This define will be ignored in IBM Watson
mode.
The publish messages include sensor readings but also some other information,
such as device uptime in seconds and a message sequence number. The demo will
publish to topic `iot-2/evt/status/fmt/json`. The device will connect using
client-id `d:contiki-ng:mqtt-client:<device-id>`, where `<device-id>` gets
constructed from the device's IEEE address.
client-id `d:<org-id>:mqtt-client:<device-id>`, where `<device-id>` gets
constructed from the device's IEEE address. `<org-id>` can be controlled
through the `MQTT_CLIENT_CONF_ORG_ID` define.
Subscribing
-----------
You can also subscribe to topics and receive commands, but this will only
work if you use "Org ID" != 'quickstart'. To achieve this, you will need to
change 'Org ID' (`DEFAULT_ORG_ID`). In this scenario, the device will subscribe
to:
change `MQTT_CLIENT_CONF_ORG_ID` in `project-conf.h`. In this scenario, the
device will subscribe to:
`iot-2/cmd/+/fmt/json`
@ -53,13 +62,18 @@ messages, outgoing publish messages use proper json payload.
IBM Quickstart Service
----------------------
It is also possible to publish to IBM's quickstart service. To do so, you need
to undefine `MQTT_DEMO_BROKER_IP_ADDR`.
to enable this mode by setting `MQTT_CLIENT_CONF_WITH_IBM_WATSON` to 1 in
`project-conf.h`.
The device will then try to connect to IBM's quickstart over NAT64, so you will
need a NAT64 gateway in your network to make this work. A guide on how to
setup NAT64 is out of scope here.
setup NAT64 is out of scope here, but you can find one in the
[Contiki-NG wiki](https://github.com/contiki-ng/contiki-ng/wiki/NAT64-for-Contiki%E2%80%90NG).
If you want to use IBM's cloud service with a registered device, change
'Org ID' (`DEFAULT_ORG_ID`) and provide the 'Auth Token' (`DEFAULT_AUTH_TOKEN`),
which acts as a 'password', but bear in mind that it gets transported in clear
text.
If you want to use IBM's cloud service with a registered device, you will need
to set `MQTT_CLIENT_CONF_ORG_ID` and then also to provide the 'Auth Token'
(`MQTT_CLIENT_CONF_AUTH_TOKEN`), which acts as a 'password'. You will also
need to configure your Organisation / Registered device on Watson such that
TLS is optional.
Note: The token will be transported in cleartext.

View File

@ -49,22 +49,61 @@
#define LOG_MODULE "mqtt-client"
#define LOG_LEVEL LOG_LEVEL_NONE
/*---------------------------------------------------------------------------*/
/*
* IBM server: messaging.quickstart.internetofthings.ibmcloud.com
* (184.172.124.189) mapped in an NAT64 (prefix 64:ff9b::/96) IPv6 address
* Note: If not able to connect; lookup the IP address again as it may change.
*
* Alternatively, publish to a local MQTT broker (e.g. mosquitto) running on
* the node that hosts your border router
*/
#ifdef MQTT_CLIENT_CONF_BROKER_IP_ADDR
static const char *broker_ip = MQTT_CLIENT_CONF_BROKER_IP_ADDR;
#define DEFAULT_ORG_ID "contiki-ng"
/* Controls whether the example will work in IBM Watson IoT platform mode */
#ifdef MQTT_CLIENT_CONF_WITH_IBM_WATSON
#define MQTT_CLIENT_WITH_IBM_WATSON MQTT_CLIENT_CONF_WITH_IBM_WATSON
#else
static const char *broker_ip = "0064:ff9b:0000:0000:0000:0000:b8ac:7cbd";
#define DEFAULT_ORG_ID "quickstart"
#define MQTT_CLIENT_WITH_IBM_WATSON 0
#endif
/*---------------------------------------------------------------------------*/
/* MQTT broker address. Ignored in Watson mode */
#ifdef MQTT_CLIENT_CONF_BROKER_IP_ADDR
#define MQTT_CLIENT_BROKER_IP_ADDR MQTT_CLIENT_CONF_BROKER_IP_ADDR
#else
#define MQTT_CLIENT_BROKER_IP_ADDR "fd00::1"
#endif
/*---------------------------------------------------------------------------*/
/*
* MQTT Org ID.
*
* If it equals "quickstart", the client will connect without authentication.
* In all other cases, the client will connect with authentication mode.
*
* In Watson mode, the username will be "use-token-auth". In non-Watson mode
* the username will be MQTT_CLIENT_USERNAME.
*
* In all cases, the password will be MQTT_CLIENT_AUTH_TOKEN.
*/
#ifdef MQTT_CLIENT_CONF_ORG_ID
#define MQTT_CLIENT_ORG_ID MQTT_CLIENT_CONF_ORG_ID
#else
#define MQTT_CLIENT_ORG_ID "quickstart"
#endif
/*---------------------------------------------------------------------------*/
/* MQTT token */
#ifdef MQTT_CLIENT_CONF_AUTH_TOKEN
#define MQTT_CLIENT_AUTH_TOKEN MQTT_CLIENT_CONF_AUTH_TOKEN
#else
#define MQTT_CLIENT_AUTH_TOKEN "AUTHTOKEN"
#endif
/*---------------------------------------------------------------------------*/
#if MQTT_CLIENT_WITH_IBM_WATSON
/* With IBM Watson support */
static const char *broker_ip = "0064:ff9b:0000:0000:0000:0000:b8ac:7cbd";
#define MQTT_CLIENT_USERNAME "use-token-auth"
#else /* MQTT_CLIENT_WITH_IBM_WATSON */
/* Without IBM Watson support. To be used with other brokers, e.g. Mosquitto */
static const char *broker_ip = MQTT_CLIENT_BROKER_IP_ADDR;
#ifdef MQTT_CLIENT_CONF_USERNAME
#define MQTT_CLIENT_USERNAME MQTT_CLIENT_CONF_USERNAME
#else
#define MQTT_CLIENT_USERNAME "use-token-auth"
#endif
#endif /* MQTT_CLIENT_WITH_IBM_WATSON */
/*---------------------------------------------------------------------------*/
#ifdef MQTT_CLIENT_CONF_STATUS_LED
#define MQTT_CLIENT_STATUS_LED MQTT_CLIENT_CONF_STATUS_LED
#else
@ -122,18 +161,12 @@ static uint8_t state;
#define CONFIG_CMD_TYPE_LEN 8
#define CONFIG_IP_ADDR_STR_LEN 64
/*---------------------------------------------------------------------------*/
#define RSSI_MEASURE_INTERVAL_MAX 86400 /* secs: 1 day */
#define RSSI_MEASURE_INTERVAL_MIN 5 /* secs */
#define PUBLISH_INTERVAL_MAX 86400 /* secs: 1 day */
#define PUBLISH_INTERVAL_MIN 5 /* secs */
/*---------------------------------------------------------------------------*/
/* A timeout used when waiting to connect to a network */
#define NET_CONNECT_PERIODIC (CLOCK_SECOND >> 2)
#define NO_NET_LED_DURATION (NET_CONNECT_PERIODIC >> 1)
/*---------------------------------------------------------------------------*/
/* Default configuration values */
#define DEFAULT_TYPE_ID "mqtt-client"
#define DEFAULT_AUTH_TOKEN "AUTHZ"
#define DEFAULT_EVENT_TYPE_ID "status"
#define DEFAULT_SUBSCRIBE_CMD_TYPE "+"
#define DEFAULT_BROKER_PORT 1883
@ -423,9 +456,10 @@ init_config()
/* Populate configuration with default values */
memset(&conf, 0, sizeof(mqtt_client_config_t));
memcpy(conf.org_id, DEFAULT_ORG_ID, strlen(DEFAULT_ORG_ID));
memcpy(conf.org_id, MQTT_CLIENT_ORG_ID, strlen(MQTT_CLIENT_ORG_ID));
memcpy(conf.type_id, DEFAULT_TYPE_ID, strlen(DEFAULT_TYPE_ID));
memcpy(conf.auth_token, DEFAULT_AUTH_TOKEN, strlen(DEFAULT_AUTH_TOKEN));
memcpy(conf.auth_token, MQTT_CLIENT_AUTH_TOKEN,
strlen(MQTT_CLIENT_AUTH_TOKEN));
memcpy(conf.event_type_id, DEFAULT_EVENT_TYPE_ID,
strlen(DEFAULT_EVENT_TYPE_ID));
memcpy(conf.broker_ip, broker_ip, strlen(broker_ip));
@ -568,7 +602,7 @@ state_machine(void)
state = STATE_ERROR;
break;
} else {
mqtt_set_username_password(&conn, "use-token-auth",
mqtt_set_username_password(&conn, MQTT_CLIENT_USERNAME,
conf.auth_token);
}
}

Some files were not shown because too many files have changed in this diff Show More