Moving the avr-rss2 platform examples to the global examples

location as suggested by the maintainers.
This commit is contained in:
Robert Olsson 2016-05-14 12:05:19 +02:00
parent 39094e3c41
commit 3c19e870f1
47 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,25 @@
# Atmega256RFR2 @ 20C, UNT-61E, RSS2 Mote 2015-12-30
# TX-PWR RPC=0x0 vs RPC=0xFF. Current mA
#
15 14.6 11.8
14 15.0 12.1
13 15.3 12.5
12 15.6 12.8
11 15.9 13.1
10 16.1 13.4
9 16.3 13.7
8 16.5 13.8
7 16.7 13.9
6 16.9 14.0
5 17.0 14.2
4 17.2 14.3
3 17.2 14.5
2 17.2 14.6
1 17.3 14.6
0 17.4 14.5
RX 13.7 7.3
IDLE 0 0

View file

@ -0,0 +1,9 @@
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
CONTIKI_PROJECT = avr_radio_power
APPS+=powertrace
all: $(CONTIKI_PROJECT)
CONTIKI = ../../../..
CONTIKI_WITH_RIME = 1
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,79 @@
avr_radio_power
===============
Motivation
-----------
Spins over different radio seting for the Atmel radio. The motivation is to
get understanding and also to get correct data for avrora and Contiki
simulations. Program loops over different TX-power setting and measures
RX consumption also radio off and idle power use in SLEEP_MODE_PWR_SAVE is
measured. Program disables radio duty cycling (RDC) and sets MCU in deep
sleep mode to only get radio consumption.
Usage
-----
The different setting is printed on the terminal. You need a way to measure
the current consumption and relate to the tests.
Example
-------
Program printout with added measurements. The used board was RSS2 mote
with a AtMega256RFR2 CPU. Max is when 0xFF is written to the RPC register.
Run/setup Current use
------------------------------------------------
TX with PWR=0 RPC=0x00 17.80 mA (MAX TX-pwr)
TX with PWR=1 RPC=0x00 17.74
TX with PWR=2 RPC=0x00
TX with PWR=3 RPC=0x00
TX with PWR=4 RPC=0x00
TX with PWR=5 RPC=0x00 17.43
TX with PWR=6 RPC=0x00
TX with PWR=7 RPC=0x00
TX with PWR=8 RPC=0x00
TX with PWR=9 RPC=0x00 17.68
TX with PWR=10 RPC=0x00
TX with PWR=11 RPC=0x00
TX with PWR=12 RPC=0x00
TX with PWR=13 RPC=0x00
TX with PWR=14 RPC=0x00
TX with PWR=15 RPC=0x00
RX with RPC=0x00 -------------------- 13.43 (RX)
-------------------------------------------------
TX with PWR=0 RPC=0xff 14.63 mA (MAX TX-pwr)
TX with PWR=1 RPC=0xff
TX with PWR=2 RPC=0xff
TX with PWR=3 RPC=0xff
TX with PWR=4 RPC=0xff
TX with PWR=5 RPC=0xff
TX with PWR=6 RPC=0xff 14.45
TX with PWR=7 RPC=0xff
TX with PWR=8 RPC=0xff
TX with PWR=9 RPC=0xff
TX with PWR=10 RPC=0xff
TX with PWR=11 RPC=0xff
TX with PWR=12 RPC=0xff
TX with PWR=13 RPC=0xff
TX with PWR=14 RPC=0xff
TX with PWR=15 RPC=0xff
RX with RPC=0xFF -------------------- 7.11 (RX)
RX radio off 0.001 mA
Comments
--------
We see TX consumption decreases from 17.80 to 14.63 mA using Max RPC (0xFF).
NOTE! For RX 13.43 to 7.11 mA. Nice. This actual measurements.
The avr-rss2 port adds support for the AtMegaXXXRFR2 including the new RPC
function.
References
----------
Atmel application note. AT02594: Smart Reduced Power Consumption Techniques
[Here] (http://www.atmel.com/images/atmel-42356-smart-reduced-power-consumption-techniques_applicationnote_at02594.pdf)
Multimeter UNI-T UT61E with USB-logging.

View file

@ -0,0 +1,164 @@
/*
* Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB
* 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.
*
*
* Author : Robert Olsson robert@radio-sensors.com
* Created : 2015-12-30
*/
/**
* \file
* An application for monitoring current use on Atmel
* radios also supporting the RPC function on RFR2 chips.
* Current needs to be measured with amp-meter.
*/
#include "contiki.h"
#include "net/rime/rime.h"
#include "powertrace.h"
#include <stdio.h>
#include "dev/leds.h"
#include "rf230bb.h"
#include "net/packetbuf.h"
#include "net/rime/rimestats.h"
#include "net/netstack.h"
#include <avr/sleep.h>
#include <dev/watchdog.h>
#define TEST_PERIOD 6
static int ps = 0; /* Power-save false */
static char buf[110];
static struct etimer et;
PROCESS(power_use_process, "Power use test");
PROCESS(sleep_process, "Sleep process");
AUTOSTART_PROCESSES(&power_use_process, &sleep_process);
static void
broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from)
{
printf("broadcast message received from %d.%d: '%s'\n",
from->u8[0], from->u8[1], (char *)packetbuf_dataptr());
}
static const struct broadcast_callbacks broadcast_call = {broadcast_recv};
static struct broadcast_conn broadcast;
PROCESS_THREAD(power_use_process, ev, data)
{
static int i, j;
PROCESS_EXITHANDLER(broadcast_close(&broadcast);)
PROCESS_BEGIN();
/* powertrace_start(CLOCK_SECOND * 2); */
broadcast_open(&broadcast, 129, &broadcast_call);
leds_init();
rf230_set_channel(25);
for(i=0; i < 2; i++) { /* Loop over min and max rpc settings */
NETSTACK_RADIO.off(); /* Radio off for rpc change */
NETSTACK_RADIO.off();
etimer_set(&et, CLOCK_SECOND * 8);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
if(i == 0)
rf230_set_rpc(0x0); /* Disbable all RPC features */
else
rf230_set_rpc(0xFF); /* Enable all RPC features. Only XRFR2 radios */
NETSTACK_RADIO.on();
/* Loop over the different TX power settings 0-15 */
for(j=15; j >= 0; j--) {
NETSTACK_RADIO.on();
rf230_set_txpower(j);
ps = 0;
printf("TX with PWR=%d RPC=0x%02x\n", rf230_get_txpower(), rf230_get_rpc());
ps = 1;
etimer_set(&et, CLOCK_SECOND * TEST_PERIOD);
while(1) {
if(etimer_expired(&et))
break;
packetbuf_copyfrom(buf, sizeof(buf)); /* Dummy data */
broadcast_send(&broadcast);
PROCESS_PAUSE();
//leds_on(LEDS_RED);
}
/* Barrier so we can see next run */
NETSTACK_RADIO.off();
etimer_set(&et, CLOCK_SECOND * TEST_PERIOD);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
}
/* RX */
NETSTACK_RADIO.on();
ps = 0;
printf("RX radio on RPC=0x%02x\n", rf230_get_rpc());
ps = 1;
etimer_set(&et, CLOCK_SECOND * TEST_PERIOD);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
NETSTACK_RADIO.off();
}
/* Last just RX OFF*/
ps = 0;
printf("RX radio off\n");
ps = 1;
etimer_set(&et, CLOCK_SECOND * TEST_PERIOD);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
PROCESS_END();
}
/* Sleep process is just put MCU in sleep so we minimiza MCU impact */
PROCESS_THREAD(sleep_process, ev, data)
{
PROCESS_BEGIN();
while(1) {
watchdog_periodic();
if(ps)
set_sleep_mode(SLEEP_MODE_PWR_SAVE);
else
set_sleep_mode(SLEEP_MODE_IDLE);
cli();
sleep_enable();
sei();
sleep_cpu();
sleep_disable();
sei();
PROCESS_PAUSE();
}
PROCESS_END();
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB
* 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.
*
*
* Author : Robert Olsson robert@radio-sensors.com
* Created : 2015-11-22
*/
/**
* \file
* Project specific configuration defines for example
*
*/
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_MAC nullmac_driver
//#define NETSTACK_CONF_MAC csma_driver
//#define NETSTACK_CONF_RDC contikimac_driver
#endif /* PROJECT_CONF_H_ */

View file

@ -0,0 +1,19 @@
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
CONTIKI_PROJECT = hello-sensors
all: $(CONTIKI_PROJECT)
# We use floating vars. Add library.
PRINTF_LIB_FLT = -Wl,-u,vfprintf -lprintf_flt -lm
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
PRINTF_LIB = $(PRINTF_LIB_FLT)
CLIBS = $(PRINTF_LIB)
CUSTOM_RULE_LINK = 1
%.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a
$(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@ $(CLIBS)
CONTIKI = ../../../..
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,11 @@
Hello-sensors
=============
Simple demo to read out sensors from the RSS2 mote.
Demo uses double which has the same size as float on Atmel. We sacrifice
some bytes for this.
Build
-----
make TARGET=avr-rss2

View file

@ -0,0 +1,119 @@
/*
* Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB
* 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.
*
*
* Author : Robert Olsson robert@radio-sensors.com
* Created : 2015-11-22
*/
/**
* \file
* A simple application showing sensor reading on RSS2 mote
*/
#include "contiki.h"
#include "sys/etimer.h"
#include <stdio.h>
#include "adc.h"
#include "i2c.h"
#include "dev/leds.h"
#include "dev/battery-sensor.h"
#include "dev/temp-sensor.h"
#include "dev/temp_mcu-sensor.h"
#include "dev/light-sensor.h"
#include "dev/pulse-sensor.h"
#ifdef CO2
#include "dev/co2_sa_kxx-sensor.h"
#endif
/*---------------------------------------------------------------------------*/
PROCESS(hello_sensors_process, "Hello sensor process");
AUTOSTART_PROCESSES(&hello_sensors_process);
static struct etimer et;
static void
read_values(void)
{
char serial[16];
int i;
/* Read out mote unique 128 bit ID */
i2c_at24mac_read((char *) &serial, 0);
printf("128_bit_ID=");
for(i=0; i < 15; i++)
printf("%02x", serial[i]);
printf("%02x\n", serial[15]);
printf("T=%-5.2f", ((double) temp_sensor.value(0)/100.));
printf(" V_MCU=%-3.1f", ((double) battery_sensor.value(0))/1000.);
printf(" V_IN=%-4.2f", adc_read_v_in());
printf(" V_AD1=%-4.2f", adc_read_a1());
printf(" V_AD2=%-4.2f", adc_read_a2());
printf(" T_MCU=%-4.1f", ((double) temp_mcu_sensor.value(0)/10.));
printf(" LIGHT=%-d", light_sensor.value(0));
printf(" PULSE_0=%-d", pulse_sensor.value(0));
printf(" PULSE_1=%-d", pulse_sensor.value(1));
#ifdef CO2
printf(" CO2=%-d", co2_sa_kxx_sensor.value( CO2_SA_KXX_CO2));
#endif
printf("\n");
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_sensors_process, ev, data)
{
PROCESS_BEGIN();
SENSORS_ACTIVATE(temp_sensor);
SENSORS_ACTIVATE(battery_sensor);
SENSORS_ACTIVATE(temp_mcu_sensor);
SENSORS_ACTIVATE(light_sensor);
SENSORS_ACTIVATE(pulse_sensor);
#ifdef CO2
SENSORS_ACTIVATE(co2_sa_kxx_sensor);
#endif
leds_init();
leds_on(LEDS_RED);
leds_on(LEDS_YELLOW);
/*
* Delay 5 sec
* Gives a chance to trigger some pulses
*/
etimer_set(&et, CLOCK_SECOND * 5);
while(1) {
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
read_values();
etimer_reset(&et);
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB
* 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.
*
*
* Author : Robert Olsson robert@radio-sensors.com
* Created : 2015-11-22
*/
/**
* \file
* Project specific configuration defines for example
*
*/
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_MAC nullmac_driver
//#define NETSTACK_CONF_MAC csma_driver
//#define NETSTACK_CONF_RDC contikimac_driver
#endif /* PROJECT_CONF_H_ */

View file

@ -0,0 +1,49 @@
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
all: coap-client coap-server
APPS=servreg-hack
CONTIKI=../../../../..
ifdef WITH_COMPOWER
APPS+=powertrace
CFLAGS+= -DCONTIKIMAC_CONF_COMPOWER=1 -DWITH_COMPOWER=1 -DQUEUEBUF_CONF_NUM=4
endif
ifdef SERVER_REPLY
CFLAGS+=-DSERVER_REPLY=$(SERVER_REPLY)
endif
ifdef PERIOD
CFLAGS+=-DPERIOD=$(PERIOD)
endif
### -------------------------------------------------------- ###
#CONTIKI_TARGET_SOURCEFILES += control.c vdc.c
# automatically build RESTful resources
REST_RESOURCES_DIR = ./resources
REST_RESOURCES_FILES = $(notdir $(shell find $(REST_RESOURCES_DIR) -name '*.c'))
DC_SENSOR_DIR = ./dev
DC_SENSOR_FILES = $(notdir $(shell find $(DC_SENSOR_DIR) -name '*.c'))
PROJECTDIRS += $(REST_RESOURCES_DIR) $(DC_SENSOR_DIR)
PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES) $(DC_SENSOR_FILES)
# linker optimizations
SMALL=1
# REST Engine shall use Erbium CoAP implementation
APPS += er-coap
APPS += rest-engine
#CFLAGS += -DUIP_CONF_BUFFER_SIZE=384
CFLAGS += -DREST_MAX_CHUNK_SIZE=128
CFLAGS += -DCOAP_MAX_HEADER_SIZE=64
CFLAGS += -DUIP_CONF_TCP=0
### -------------------------------------------------------- ###
CONTIKI_WITH_IPV6 = 1
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,67 @@
Example: mockup of DC converter functionality for IoT-grid.
===========================================
This example imitates DC converter functionality for IoT-grid.
We use standard IoT protocol stack with CoAP application-level protocol.
The settings are as follows.
* APPLICATION: CoAP
* TRANSPORT: UDP
* NETWORK: IPv6/RPL
* ADAPTATION: 6LoWPAN
* MAC: nullmac_driver
* RADIO DUTY CYCLE: nullrdc_driver
* PHYSICAL: IEEE 802.15.4
CoAP resources
----------------
We define a CoAP resource for each functionality of DC converter.
Since each functionality may have several parameters, we define each resource
as a vector of parameters as follows.
* /dcdc/status read-only parameters for power monitoring.
It also support periodic monitoring through CoAP observe option.
** 0 VOUT Output voltage
** 1 VIN Input voltage
** 2 IOUT Output current
** 3 IIN Input current
* /dcdc/vdc configurable parameters for voltage droop control function.
** 0 VGRID Desired grid output voltage
** 1 SLOPE Slope of voltage droop control function
** 2 PMAX Maximum output power allowed
* /dcdc/hwcfg configurable parameters for DC converter hardware.
** 0 VMAX Maximum output voltage allowed
** 1 IMAX Maximum output current allowed
Each functionality is implemented as a sensor type device.
They are located in "dev" folder.
* dc-status-sensor for /dcdc/status
* dc-vdc-sensor for /dcdc/vdc
* dc-hw-sensor for /dcdc/hwcfg
The corresponding CoAP handler for each resource is defined in "resources" folder.
* res-dc-status-obs for /dcdc/status
* res-dc-vdc for /dcdc/vdc
* res-dc-hwcfg for /dcdc/hwcfg
coap-server.c
----------------
The server acts as the RPL root node.
It has 3 CoAP resources as described above.
coap-client.c
----------------
The client periodically send a CoAP command (either GET or PUT) to monitor/update
values of parameters of a resource.
project-conf.h
----------------
This file contains definitions needed for this IoT-grid example as follows.
* Enable IPv6 network stack
* Set nullrdc_driver
* Set nullmac_driver
* Activate CoAP observe client library (COAP_OBSERVE_CLIENT = 1)
* Increase the maximum number of observee and maximum number of open transaction to 10
(COAP_MAX_OPEN_TRANSACTIONS and COAP_MAX_OBSERVEES = 10)

View file

@ -0,0 +1,413 @@
/*
* 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.
*
*/
#include "contiki.h"
#include "contiki-net.h"
#include "lib/random.h"
#include "sys/ctimer.h"
#include "net/ip/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/ip/uip-udp-packet.h"
#ifdef WITH_COMPOWER
#include "powertrace.h"
#endif
#include <stdio.h>
#include <string.h>
/**************************************************************************/
/* from er-rest-example/er-rexample-client.c */
#include <stdlib.h>
#include "er-coap-engine.h"
#include "er-coap.h"
#include "er-coap-observe-client.h"
/* #include "dev/button-sensor.h" */
#if PLATFORM_HAS_LEDS
#include "dev/leds.h"
#endif
#define DEBUG 1
#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
/* FIXME: This server address is hard-coded for Cooja and link-local for unconnected border router. */
/* #define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0xfe80, 0, 0, 0, 0x0212, 0x7402, 0x0002, 0x0202) / * cooja2 * / */
/* #define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0xbbbb, 0, 0, 0, 0, 0, 0, 0x1) */
/* #define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0x2000, 0, 0, 0, 0, 0, 0, 0x0001) */
#define LOCAL_PORT UIP_HTONS(COAP_DEFAULT_PORT + 1)
#define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT)
#define GET_INTERVAL 10
/* #define OBSERVE_INTERVAL 10 */
/**************************************************************************/
#define UDP_CLIENT_PORT 8765
#define UDP_SERVER_PORT 5678
#define UDP_EXAMPLE_ID 190
/* #define DEBUG DEBUG_PRINT */
/* #include "net/ip/uip-debug.h" */
#ifndef PERIOD
/* #define PERIOD 60 */
#define PERIOD 10
#endif
#define START_INTERVAL (15 * CLOCK_SECOND)
#define SEND_INTERVAL (PERIOD * CLOCK_SECOND)
#define SEND_TIME (random_rand() % (SEND_INTERVAL))
/* static struct uip_udp_conn *client_conn; */
static uip_ipaddr_t server_ipaddr;
static coap_observee_t *obs;
static int count_notify = 0;
/**************************************************************************/
static struct etimer et;
/* Example URIs that can be queried. */
#define NUMBER_OF_URLS 4
/* leading and ending slashes only for demo purposes, get cropped automatically when setting the Uri-Path */
char *service_urls[NUMBER_OF_URLS] =
{ ".well-known/core", "/dcdc/status", "/dcdc/vdc", "/dcdc/hwcfg" };
/*
#if PLATFORM_HAS_BUTTON
static int uri_switch = 0;
#endif
*/
/* This function is will be passed to COAP_BLOCKING_REQUEST() to handle responses. */
void
client_chunk_handler(void *response)
{
const uint8_t *chunk;
int len = coap_get_payload(response, &chunk);
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
/* printf("|%.*s", len, (char *)chunk); */
printf("RX: %d\n%s\n", len, (char *)chunk);
}
/**************************************************************************/
/*---------------------------------------------------------------------------*/
PROCESS(coap_client_process, "CoAP client process");
AUTOSTART_PROCESSES(&coap_client_process);
/*---------------------------------------------------------------------------*/
static void
tcpip_handler(void)
{
char *str;
if(uip_newdata()) {
str = uip_appdata;
str[uip_datalen()] = '\0';
printf("DATA recv '%s'\n", str);
}
}
/*---------------------------------------------------------------------------*/
static void
print_local_addresses(void)
{
int i;
uint8_t state;
PRINTF("Client IPv6 addresses: ");
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state;
if(uip_ds6_if.addr_list[i].isused &&
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
PRINTF("\n");
/* hack to make address "final" */
if(state == ADDR_TENTATIVE) {
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
}
}
}
}
/*---------------------------------------------------------------------------*/
static void
set_global_address(void)
{
uip_ipaddr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
/* The choice of server address determines its 6LoPAN header compression.
* (Our address will be compressed Mode 3 since it is derived from our link-local address)
* Obviously the choice made here must also be selected in udp-server.c.
*
* For correct Wireshark decoding using a sniffer, add the /64 prefix to the 6LowPAN protocol preferences,
* e.g. set Context 0 to aaaa::. At present Wireshark copies Context/128 and then overwrites it.
* (Setting Context 0 to aaaa::1111:2222:3333:4444 will report a 16 bit compressed address of aaaa::1111:22ff:fe33:xxxx)
*
* Note the IPCMV6 checksum verification depends on the correct uncompressed addresses.
*/
#if 0
/* Mode 1 - 64 bits inline */
uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
#elif 1
/* Mode 2 - 16 bits inline */
uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0x00ff, 0xfe00, 1);
#else
/* Mode 3 - derived from server link-local (MAC) address */
uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0x0250, 0xc2ff, 0xfea8, 0xcd1a); /* redbee-econotag */
#endif
/* Voravit Added */
/* PRINTF("VORAVIT CLIENT: SERVER IPv6 addresses: \n"); */
/* PRINT6ADDR(&server_ipaddr); */
}
/*---------------------------------------------------------------------------*/
static void
generate_random_payload(int type, char *msg)
{
if(type == 2) { /* /dcdc/vdc */
snprintf((char *)msg, 64, "&VG=%d&SL=%d&PMX=%d", (random_rand() % 25) + 1, (random_rand() % 10) + 1, (random_rand() % 100) + 1);
} else if(type == 3) { /* /dcdc/hwcfg */
snprintf((char *)msg, 64, "&VMX=%d&IMX=%d", (random_rand() % 25) + 1, (random_rand() % 6) + 1);
}
}
/*----------------------------------------------------------------------------*/
/*
* Handle the response to the observe request and the following notifications
*/
static void
notification_callback(coap_observee_t *obs, void *notification, coap_notification_flag_t flag)
{
int len = 0;
const uint8_t *payload = NULL;
/* printf("Notification handler\n"); */
/* printf("Observee URI: %s\n", obs->url); */
if(notification) {
len = coap_get_payload(notification, &payload);
}
switch(flag) {
case NOTIFICATION_OK:
count_notify++;
printf("NOTIFICATION OK: %d\n%*s\n", count_notify, len, (char *)payload);
break;
case OBSERVE_OK: /* server accepeted observation request */
printf("OBSERVE_OK: \n%*s\n", len, (char *)payload);
break;
case OBSERVE_NOT_SUPPORTED:
printf("OBSERVE_NOT_SUPPORTED: \n%*s\n", len, (char *)payload);
obs = NULL;
break;
case ERROR_RESPONSE_CODE:
printf("ERROR_RESPONSE_CODE: \n%*s\n", len, (char *)payload);
obs = NULL;
break;
case NO_REPLY_FROM_SERVER:
printf("NO_REPLY_FROM_SERVER: "
"removing observe registration with token %x%x\n",
obs->token[0], obs->token[1]);
obs = NULL;
break;
}
}
/*---------------------------------------------------------------------------*/
/*
* Toggle the observation of the remote resource
*/
void
toggle_observation(void)
{
if(obs) {
printf("Stopping observation\n");
coap_obs_remove_observee(obs);
obs = NULL;
} else {
printf("Starting observation\n");
obs = coap_obs_request_registration(&server_ipaddr, REMOTE_PORT, service_urls[1], notification_callback, NULL);
}
}
/*---------------------------------------------------------------------------*/
static int count_get = 0;
static int count_put = 0;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(coap_client_process, ev, data)
{
/*
#if WITH_COMPOWER
static int print = 0;
#endif
*/
PROCESS_BEGIN();
PROCESS_PAUSE();
set_global_address();
PRINTF("CoAP client process started\n");
print_local_addresses();
/**************************************************************************/
static coap_packet_t request[1]; /* This way the packet can be treated as pointer as usual. */
/* receives all CoAP messages */
coap_init_engine();
etimer_set(&et, GET_INTERVAL * CLOCK_SECOND);
while(1) {
PROCESS_YIELD();
if(ev == tcpip_event) {
printf("TCPIP_HANDLER\n");
tcpip_handler();
}
if(etimer_expired(&et)) {
count_get++;
/*---------------------------------------------------------------------------*/
if(count_get < 10) { /* we do normal GET 3 times for each resource */
/* TEST GET: looping through the 3 resources: status, vdc, hwcfg */
/* Also CoAP GET doesn't need to have a payload */
coap_init_message(request, COAP_TYPE_CON, COAP_GET, 0);
if(count_get % 3 == 1) {
coap_set_header_uri_path(request, service_urls[1]);
PRINTF("GET %d: %s\n", count_get, service_urls[1]);
} else if(count_get % 3 == 2) {
coap_set_header_uri_path(request, service_urls[2]);
PRINTF("GET %d: %s\n", count_get, service_urls[2]);
} else {
coap_set_header_uri_path(request, service_urls[3]);
PRINTF("GET %d: %s\n", count_get, service_urls[3]);
}
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request,
client_chunk_handler);
} /* if (count_get < 10) */
/*---------------------------------------------------------------------------*/
/* test PUT: vdc and hwcfg on odd and even packet */
/* every 10th timer we PUT a resource: vdc and hwcfg alternately */
if(count_get % 10 == 0) {
/* static char msg[64] = ""; */
char msg[64] = "";
/*---------------------------------------------------------------------------*/
/* We read CO2 sensor if it is enable */
#ifdef CO2
coap_init_message(request, COAP_TYPE_CON, COAP_GET, 0);
coap_set_header_uri_path(request, "/dcdc/co2");
PRINTF("GET %d: %s\n", count_get, "/dcdc/co2");
#if PLATFORM_HAS_LEDS
leds_on(LEDS_YELLOW);
#endif
COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request,
client_chunk_handler);
#endif
/*---------------------------------------------------------------------------*/
count_put++;
coap_init_message(request, COAP_TYPE_CON, COAP_PUT, 0);
if(count_put % 2 == 0) {
coap_set_header_uri_path(request, service_urls[3]);
generate_random_payload(3, msg);
coap_set_payload(request, (uint8_t *)msg, sizeof(msg) - 1);
PRINTF("PUT %d: %s PAYLOAD: %s\n", count_get, service_urls[3], msg);
} else {
coap_set_header_uri_path(request, service_urls[2]);
generate_random_payload(2, msg);
coap_set_payload(request, (uint8_t *)msg, sizeof(msg) - 1);
PRINTF("PUT %d: %s PAYLOAD: %s\n", count_get, service_urls[2], msg);
}
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request,
client_chunk_handler);
}
/* after 2 more timeout we do GET to check the resource new value */
if((count_get > 10) && ((count_get - 2) % 10 == 0)) {
coap_init_message(request, COAP_TYPE_CON, COAP_GET, 0);
if(count_put % 2 == 0) {
coap_set_header_uri_path(request, service_urls[3]);
PRINTF("GET %d: %s\n", count_get, service_urls[3]);
} else {
coap_set_header_uri_path(request, service_urls[2]);
PRINTF("GET %d: %s\n", count_get, service_urls[2]);
}
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request,
client_chunk_handler);
}
/*---------------------------------------------------------------------------*/
/* test GET with observe option when timer expires the 15th time */
if(count_get == 15) {
/* PRINTF("GET %d: OBSERVE: %s\n", count_get, service_urls[2]); */
toggle_observation();
}
etimer_reset(&et);
}
} /* END_WHILE(1) */
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,269 @@
/*
* 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.
*
*/
#include "contiki.h"
#include "contiki-lib.h"
#include "contiki-net.h"
#include "net/ip/uip.h"
#include "net/rpl/rpl.h"
#include "net/netstack.h"
/* #include "dev/leds.h" */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/*
#define DEBUG DEBUG_PRINT
#include "net/ip/uip-debug.h"
*/
/**************************************************************************/
/* add mock-up code for DC-DC converter */
/* #include "control.h" */
/* #include "vdc.h" */
#ifdef CO2
#include "dev/co2_sa_kxx-sensor.h"
#endif
#include "dev/dc-status-sensor.h"
#include "dev/dc-vdc-sensor.h"
#include "dev/dc-hw-sensor.h"
/* from er-rest-example/er-rexample-server.c */
#include "rest-engine.h"
/* #include "er-coap.h" */
#if PLATFORM_HAS_LEDS
#include "dev/leds.h"
#endif
/*
#if PLATFORM_HAS_BUTTON
#include "dev/button-sensor.h"
#endif
*/
#define DEBUG 1
#if DEBUG
/* #include <stdio.h> */
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/* #define TOGGLE_INTERVAL 10 */
/* #define OBSERVE_INTERVAL 10 */
/*
* Resources to be activated need to be imported through the extern keyword.
* The build system automatically compiles the resources in the corresponding sub-directory.
*/
extern resource_t
/* res_hello, */
/* res_push, */
/* res_event, */
/* res_sub; */
/* res_dc_status_obs; */
/* res_dc_status, */
#ifdef CO2
res_dc_co2,
#endif
res_dc_status_obs,
res_dc_vdc,
res_dc_hwcfg;
/*
#if PLATFORM_HAS_LEDS
extern resource_t
// res_leds,
res_toggle;
#endif
*/
/* #if PLATFORM_HAS_LIGHT */
/* #include "dev/light-sensor.h" */
/* extern resource_t res_light; */
/* #endif */
/**************************************************************************/
PROCESS(coap_server_process, "CoAP server process");
AUTOSTART_PROCESSES(&coap_server_process);
/*---------------------------------------------------------------------------*/
static void
print_local_addresses(void)
{
int i;
uint8_t state;
PRINTF("Server 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);
PRINTF("\n");
/* hack to make address "final" */
if(state == ADDR_TENTATIVE) {
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
}
}
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(coap_server_process, ev, data)
{
uip_ipaddr_t ipaddr;
struct uip_ds6_addr *root_if;
PROCESS_BEGIN();
PROCESS_PAUSE();
/* SENSORS_ACTIVATE(button_sensor); */
#ifdef CO2
SENSORS_ACTIVATE(co2_sa_kxx_sensor);
#endif
SENSORS_ACTIVATE(dc_status_sensor);
SENSORS_ACTIVATE(dc_vdc_sensor);
SENSORS_ACTIVATE(dc_hw_sensor);
/**************************************************************************/
#if PLATFORM_HAS_LEDS
/* initialize leds */
leds_init();
leds_on(LEDS_RED);
leds_on(LEDS_YELLOW);
#endif
/* Initilize DC-DC converter parameters */
/* ValueInit(); */
/* VDCInit(); */
/*
#ifdef PARAMS_CHANNEL
PRINTF("PARAMs channel: %u\n", PARAMS_CHANNEL);
#endif
*/
#ifdef RF_CHANNEL
PRINTF("RF channel: %u\n", RF_CHANNEL);
#endif
#ifdef IEEE802154_PANID
PRINTF("PAN ID: 0x%04X\n", IEEE802154_PANID);
#endif
PRINTF("uIP buffer: %u\n", UIP_BUFSIZE);
PRINTF("LL header: %u\n", UIP_LLH_LEN);
PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN);
PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE);
/* Initialize the REST engine. */
rest_init_engine();
/*
* Bind the resources to their Uri-Path.
* WARNING: Activating twice only means alternate path, not two instances!
* All static variables are the same for each URI path.
*/
/* rest_activate_resource(&res_hello, "test/hello"); */
/* rest_activate_resource(&res_mirror, "debug/mirror"); */
/* rest_activate_resource(&res_chunks, "test/chunks"); */
/* rest_activate_resource(&res_separate, "test/separate"); */
/* rest_activate_resource(&res_push, "test/push"); */
/* rest_activate_resource(&res_event, "sensors/button"); */
/* rest_activate_resource(&res_sub, "test/sub"); */
/* rest_activate_resource(&res_b1_sep_b2, "test/b1sepb2"); */
#ifdef CO2
rest_activate_resource(&res_dc_co2, "dcdc/co2");
#endif
rest_activate_resource(&res_dc_status_obs, "dcdc/status");
/* rest_activate_resource(&res_dc_status, "dcdc/status"); */
rest_activate_resource(&res_dc_vdc, "dcdc/vdc");
rest_activate_resource(&res_dc_hwcfg, "dcdc/hwcfg");
/* #if PLATFORM_HAS_LEDS */
/* / * rest_activate_resource(&res_leds, "actuators/leds"); * / */
/* rest_activate_resource(&res_toggle, "actuators/toggle"); */
/* #endif */
/* #if PLATFORM_HAS_LIGHT */
/* rest_activate_resource(&res_light, "sensors/light"); */
/* SENSORS_ACTIVATE(light_sensor); */
/* #endif */
/**************************************************************************/
PRINTF("CoAP server started\n");
#if UIP_CONF_ROUTER
/* The choice of server address determines its 6LoPAN 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 aaaa::. At present Wireshark copies Context/128 and then overwrites it.
* (Setting Context 0 to aaaa::1111:2222:3333:4444 will report a 16 bit compressed address of aaaa::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, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
#elif 1
/* Mode 2 - 16 bits inline */
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0x00ff, 0xfe00, 1);
#else
/* Mode 3 - derived from link local (MAC) address */
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
#endif
uip_ds6_addr_add(&ipaddr, 0, ADDR_MANUAL);
root_if = uip_ds6_addr_lookup(&ipaddr);
if(root_if != NULL) {
rpl_dag_t *dag;
dag = rpl_set_root(RPL_DEFAULT_INSTANCE, (uip_ip6addr_t *)&ipaddr);
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
rpl_set_prefix(dag, &ipaddr, 64);
PRINTF("created a new RPL dag\n");
} else {
PRINTF("failed to create a new RPL DAG\n");
}
#endif /* UIP_CONF_ROUTER */
print_local_addresses();
/* The data sink runs with a 100% duty cycle in order to ensure high
packet reception rates. */
NETSTACK_MAC.off(1);
while(1) {
PROCESS_WAIT_EVENT();
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,168 @@
<?xml version="1.0" encoding="UTF-8"?>
<simconf>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/native_gateway</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/serial_socket</project>
<project EXPORT="discard">/home/user/contikiprojects/sics.se/mobility</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/collect-view</project>
<project EXPORT="discard">/home/user/contikiprojects/sics.se/powertracker</project>
<simulation>
<title>My simulation</title>
<randomseed>123456</randomseed>
<motedelay_us>1000000</motedelay_us>
<radiomedium>
se.sics.cooja.radiomediums.UDGM
<transmitting_range>50.0</transmitting_range>
<interference_range>100.0</interference_range>
<success_ratio_tx>1.0</success_ratio_tx>
<success_ratio_rx>1.0</success_ratio_rx>
</radiomedium>
<events>
<logoutput>40000</logoutput>
</events>
<motetype>
se.sics.cooja.avrmote.RSS2MoteType
<identifier>mote1</identifier>
<description>Mote1</description>
<source EXPORT="discard">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.c</source>
<commands EXPORT="discard">make coap-server.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.avr-rss2</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraClock</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraMoteID</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart0</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart1</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.RFR2Radio</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraADC</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraLED</moteinterface>
</motetype>
<motetype>
se.sics.cooja.avrmote.RSS2MoteType
<identifier>mote2</identifier>
<description>Mote2</description>
<source EXPORT="discard">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.c</source>
<commands EXPORT="discard">make coap-client.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.avr-rss2</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraClock</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraMoteID</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart0</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart1</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.RFR2Radio</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraADC</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraLED</moteinterface>
</motetype>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>100.0</x>
<y>100.0</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.avrmote.interfaces.AvroraMoteID
<id>1</id>
</interface_config>
<motetype_identifier>mote1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>110.0</x>
<y>100.0</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.avrmote.interfaces.AvroraMoteID
<id>2</id>
</interface_config>
<motetype_identifier>mote2</motetype_identifier>
</mote>
</simulation>
<plugin>
se.sics.cooja.plugins.SimControl
<width>280</width>
<z>9</z>
<height>160</height>
<location_x>400</location_x>
<location_y>0</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.Visualizer
<plugin_config>
<moterelations>true</moterelations>
<skin>se.sics.cooja.plugins.skins.IDVisualizerSkin</skin>
<skin>se.sics.cooja.plugins.skins.GridVisualizerSkin</skin>
<viewport>3.908924509090908 0.0 0.0 3.908924509090908 -216.43707345454544 -217.89245090909074</viewport>
</plugin_config>
<width>400</width>
<z>5</z>
<height>400</height>
<location_x>1</location_x>
<location_y>1</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.LogListener
<plugin_config>
<filter />
<formatted_time />
<coloring />
</plugin_config>
<width>1269</width>
<z>8</z>
<height>240</height>
<location_x>400</location_x>
<location_y>160</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.Notes
<plugin_config>
<notes>Enter notes here</notes>
<decorations>true</decorations>
</plugin_config>
<width>989</width>
<z>6</z>
<height>160</height>
<location_x>680</location_x>
<location_y>0</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.MoteInterfaceViewer
<mote_arg>0</mote_arg>
<plugin_config>
<interface>Serial port</interface>
<scrollpos>0,0</scrollpos>
</plugin_config>
<width>508</width>
<z>4</z>
<height>389</height>
<location_x>13</location_x>
<location_y>413</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.MoteInterfaceViewer
<mote_arg>1</mote_arg>
<plugin_config>
<interface>Serial port</interface>
<scrollpos>0,0</scrollpos>
</plugin_config>
<width>545</width>
<z>3</z>
<height>392</height>
<location_x>531</location_x>
<location_y>413</location_y>
</plugin>
</simconf>

View file

@ -0,0 +1,93 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/hwcfg for DC-DC converter hardware configuration
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#include "contiki.h"
/* #include "lib/sensors.h" */
#include "dev/dc-hw-sensor.h"
const struct sensors_sensor dc_hw_sensor;
/*
* hw contains 2 parameters
* hw[0] VMAX
* hw[1] IMAX
*/
uint32_t volatile hw[2] = { 25, 6 };
static int
value(int type)
{
switch(type) {
case 0:
return hw[0];
case 1:
return hw[1];
}
return -1;
}
static int
configure(int type, int c)
{
switch(type) {
case 0:
if((c >= 0) && (c <= 25)) {
hw[0] = c;
return 0;
} else {
return 1;
}
case 1:
if((c >= 0) && (c <= 6)) {
hw[1] = c;
return 0;
} else {
return 0;
}
}
return 1;
}
static int
status(int type)
{
return 1;
}
SENSORS_SENSOR(dc_hw_sensor, "hw sensors", value, configure, status);

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/hwcfg header file
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#ifndef DC_HW_SENSOR_H
#define DC_HW_SENSOR_H
#include "lib/sensors.h"
extern const struct sensors_sensor dc_hw_sensor;
#endif /* DC_HW_SENSOR_H */

View file

@ -0,0 +1,84 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/status read-only parameters for power monitoring
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#include "contiki.h"
/* #include "lib/sensors.h" */
#include "dev/dc-status-sensor.h"
const struct sensors_sensor dc_status_sensor;
/*
* Status contains 4 parameters
* status[0] VOUT
* status[1] VIN
* status[2] IOUT
* status[3] IIN
*/
uint32_t volatile s[4] = { 18, 20, 1, 2 };
static int
value(int type)
{
switch(type) {
case 0:
return s[0];
case 1:
return s[1];
case 2:
return s[2];
case 3:
return s[3];
}
return -1;
}
static int
configure(int type, int c)
{
return 0;
}
static int
status(int type)
{
return 1;
}
SENSORS_SENSOR(dc_status_sensor, "DC status sensors", value, configure, status);

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/status header file
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#ifndef DC_STATUS_SENSOR_H
#define DC_STATUS_SENSOR_H
#include "lib/sensors.h"
extern const struct sensors_sensor dc_status_sensor;
#endif /* DC_STATUS_SENSOR_H */

View file

@ -0,0 +1,97 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/vdc for voltage droop control function
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#include "contiki.h"
/* #include "lib/sensors.h" */
#include "dev/dc-vdc-sensor.h"
const struct sensors_sensor dc_vdc_sensor;
/*
* vdc contains 3 parameters
* vdc[0] VGRID
* vdc[1] SLOPE
* vdc[2] PMAX
*/
uint32_t volatile vdc[3] = { 18, 1, 100 };
static int
value(int type)
{
switch(type) {
case 0:
return vdc[0];
case 1:
return vdc[1];
case 2:
return vdc[2];
}
return -1;
}
static int
configure(int type, int c)
{
switch(type) {
case 0:
if((c >= 0) && (c <= 25)) {
vdc[0] = c;
return 0;
} else {
return 1;
}
case 1:
vdc[1] = c;
return 0;
case 2:
vdc[2] = c;
return 0;
}
return 1;
}
static int
status(int type)
{
return 1;
}
SENSORS_SENSOR(dc_vdc_sensor, "vdc sensors", value, configure, status);

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/vdc sensor header file
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#ifndef DC_VDC_SENSOR_H
#define DC_VDC_SENSOR_H
#include "lib/sensors.h"
extern const struct sensors_sensor dc_vdc_sensor;
#endif /* DC_VDC_SENSOR_H */

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* header file for resources
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#ifndef __ER_DC_TEST_H__
#define __ER_DC_TEST_H__
#define DEBUG 1
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/* double expansion */
#define TO_STRING2(x) # x
#define TO_STRING(x) TO_STRING2(x)
#define MAX_COAP_PAYLOAD 64 + 1 /* +1 for the terminating zero, which is not transmitted */
/* #define MAX_PLUGFEST_BODY 2048 */
/* #define CHUNKS_TOTAL 2012 */
#endif /* __ER_DC_TEST_H__ */

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* test rpl configuration.
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
/* enable IPv6 */
/* #ifndef NETSTACK_CONF_WITH_IPV6 */
#define NETSTACK_CONF_WITH_IPV6 1
/* #endif / * NETSTACK_CONF_WITH_IPV6 * / */
#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_MAC nullmac_driver
#define COAP_OBSERVE_CLIENT 1
#define COAP_MAX_OBSERVEES 10
#define COAP_MAX_OPEN_TRANSACTIONS 10
/* enable debug to activate PRINT6ADDR macro */
/* #undef DEBUG_PRINT */
/* #define DEBUG_PRINT 1 */
/* #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]) */
#endif /* PROJECT_CONF_H_ */

View file

@ -0,0 +1,83 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/co2 testing coap with CO2 sensor from SenseAir
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
/* #include <math.h> */
#include <stdio.h>
#include <string.h>
#include "rest-engine.h"
#include "er-coap.h"
#include "er-dc-test.h"
#if PLATFORM_HAS_LEDS
#include "dev/leds.h"
#endif
#include "dev/co2_sa_kxx-sensor.h"
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
RESOURCE(res_dc_co2, "title=\"co2 reading\"", res_get_handler, NULL, NULL, NULL);
/*---------------------------------------------------------------------------*/
static void
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
coap_packet_t *const coap_req = (coap_packet_t *)request;
int co2 = co2_sa_kxx_sensor.value(CO2_SA_KXX_CO2); // 0 is CO2_SA_KXX_CO2
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
PRINTF("dcdc/co2 GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
/* Code 2.05 CONTENT is default. */
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
/* REST.set_header_max_age(response, 30); */
REST.set_response_payload(
response,
buffer,
/* snprintf((char *)buffer, MAX_COAP_PAYLOAD, "VMX\t%d.000\nIMX\t%d.000\nINT\t%d\n", v_max, i_max, interval)); */
snprintf((char *)buffer, MAX_COAP_PAYLOAD, "CO2\t%d\n", co2));
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
}

View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/vdc configurable parameters for voltage droop control function
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
/* #include <math.h> */
#include <stdio.h>
#include <string.h>
#include "rest-engine.h"
#include "er-coap.h"
#include "er-dc-test.h"
#if PLATFORM_HAS_LEDS
#include "dev/leds.h"
#endif
#include "dev/dc-hw-sensor.h"
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
RESOURCE(res_dc_hwcfg, "title=\"hwcfg parameters\"", res_get_handler, res_post_put_handler, res_post_put_handler, NULL);
/*---------------------------------------------------------------------------*/
static void
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
coap_packet_t *const coap_req = (coap_packet_t *)request;
int v_max = dc_hw_sensor.value(0);
int i_max = dc_hw_sensor.value(1);
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
PRINTF("dcdc/hwcfg GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
/* Code 2.05 CONTENT is default. */
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
/* REST.set_header_max_age(response, 30); */
REST.set_response_payload(
response,
buffer,
/* snprintf((char *)buffer, MAX_COAP_PAYLOAD, "VMX\t%d.000\nIMX\t%d.000\nINT\t%d\n", v_max, i_max, interval)); */
snprintf((char *)buffer, MAX_COAP_PAYLOAD, "VMX\t%d.000\nIMX\t%d.000\n", v_max, i_max));
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
}
/*---------------------------------------------------------------------------*/
static void
res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
coap_packet_t *const coap_req = (coap_packet_t *)request;
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
PRINTF("dcdc/hwcfg PUT (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
const char *variable = NULL;
if(REST.get_post_variable(request, "VMX", &variable) > 0) {
int v_max = atoi(variable);
if(dc_hw_sensor.configure(0, v_max)) {
PRINTF("Value out of range: must be 0 <= VMX <= 30");
}
}
if(REST.get_post_variable(request, "IMX", &variable) > 0) {
int i_max = atoi(variable);
if(dc_hw_sensor.configure(1, i_max)) {
PRINTF("Value out of range: must be 0 <= Imax <= 6");
}
}
REST.set_response_status(response, REST.status.CHANGED);
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
}

View file

@ -0,0 +1,113 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/status read-only parameters for power monitoring
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
#include <stdio.h>
#include <string.h>
#include "rest-engine.h"
#include "er-coap.h"
#include "er-coap-observe.h"
#include "../er-dc-test.h"
#if PLATFORM_HAS_LEDS
#include "dev/leds.h"
#endif
#include "dev/dc-status-sensor.h"
static void res_dc_status_obs_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_dc_status_obs_periodic_handler(void);
PERIODIC_RESOURCE(res_dc_status_obs, "title=\"status parameters\"", res_dc_status_obs_get_handler, NULL, NULL, NULL, 10 * CLOCK_SECOND, res_dc_status_obs_periodic_handler);
static uint32_t observe = 0;
static count = 0;
/*---------------------------------------------------------------------------*/
static void
res_dc_status_obs_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
int vout_value = dc_status_sensor.value(0);
int vin_value = dc_status_sensor.value(1);
int iout_value = dc_status_sensor.value(2);
int iin_value = dc_status_sensor.value(3);
/* a request comes from a remote host */
if(request != NULL) {
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
coap_packet_t *const coap_req = (coap_packet_t *)request;
PRINTF("dcdc/status GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
/* if comes with observe then register it */
if(coap_get_header_observe(request, &observe)) {
/* PRINTF("OBSERVE set\n"); */
/* respond with empty ack */
REST.set_header_content_type(response, observe);
REST.set_response_payload(response, 0, 0);
} else { /* if no observe option, then answer to GET request as normal */
/* PRINTF("OBSERVE NOT set\n"); */
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
REST.set_response_payload(
response,
buffer,
snprintf((char *)buffer, MAX_COAP_PAYLOAD, "ST\tON\nVO\t%d.000\nIO\t%d.000\nVI\t%d.000\nII\t%d.000\n", vout_value, iout_value, vin_value, iin_value));
}
} else { /* this is a notification: need to set payload */
/* PRINTF("NULL REQUEST = PERIODIC\n"); */
REST.set_response_payload(
response,
buffer,
snprintf((char *)buffer, MAX_COAP_PAYLOAD, "ST\tON\nVO\t%d.000\nIO\t%d.000\nVI\t%d.000\nII\t%d.000\n", vout_value, iout_value, vin_value, iin_value));
}
count++;
printf("PERIODIC %d: ST:ON VO:%d IO:%d VI:%d II:%d\n", count, vout_value, iout_value, vin_value, iin_value);
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
}
/*---------------------------------------------------------------------------*/
static void
res_dc_status_obs_periodic_handler()
{
/* send periodic notification to the observers */
REST.notify_subscribers(&res_dc_status_obs);
}

View file

@ -0,0 +1,129 @@
/*
* Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology
* 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
* dcdc/vdc configurable parameters for voltage droop control function
* \author
* Voravit Tanyingyong <voravit@kth.se>
*/
/* #include <math.h> */
#include <stdio.h>
#include <string.h>
#include "rest-engine.h"
#include "er-coap.h"
#include "er-dc-test.h"
#if PLATFORM_HAS_LEDS
#include "dev/leds.h"
#endif
#include "dev/dc-vdc-sensor.h"
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
RESOURCE(res_dc_vdc, "title=\"vdc parameters\"", res_get_handler, res_post_put_handler, res_post_put_handler, NULL);
/*---------------------------------------------------------------------------*/
static void
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
coap_packet_t *const coap_req = (coap_packet_t *)request;
int vdc_grid = dc_vdc_sensor.value(0);
int vdc_slope = dc_vdc_sensor.value(1);
int vdc_pmax = dc_vdc_sensor.value(2);
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
PRINTF("dcdc/vdc GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
/* Code 2.05 CONTENT is default. */
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
/* REST.set_header_max_age(response, 30); */
REST.set_response_payload(
response,
buffer,
snprintf((char *)buffer, MAX_COAP_PAYLOAD, "VG\t%d.000\nSL\t%d.000\nPMAX\t%d.000\n", vdc_grid, vdc_slope, vdc_pmax));
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
}
/*---------------------------------------------------------------------------*/
static void
res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
coap_packet_t *const coap_req = (coap_packet_t *)request;
#if PLATFORM_HAS_LEDS
/* set red led when receiving a packet */
leds_on(LEDS_RED);
#endif
PRINTF("dcdc/vdc PUT (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
const char *variable = NULL;
if(REST.get_post_variable(request, "VG", &variable) > 0) {
int vdc_grid = atoi(variable);
/* PRINTF("VG: %d\n",vdc_grid); */
if(dc_vdc_sensor.configure(0, vdc_grid)) {
PRINTF("Value out of range: must be 0 <= Vgrid <= Vmax");
}
}
if(REST.get_post_variable(request, "SL", &variable) > 0) {
int vdc_slope = atoi(variable);
/* PRINTF("SL: %d\n",vdc_slope); */
if(dc_vdc_sensor.configure(1, vdc_slope)) {
PRINTF("Error: SLOPE is not set!");
}
}
if(REST.get_post_variable(request, "PMX", &variable) > 0) {
int vdc_pmax = atoi(variable);
/* PRINTF("PMAX: %d\n",vdc_pmax); */
if(dc_vdc_sensor.configure(2, vdc_pmax)) {
PRINTF("Error: PMAX is not set!");
}
}
REST.set_response_status(response, REST.status.CHANGED);
#if PLATFORM_HAS_LEDS
/* set yellow led when sending packet */
leds_on(LEDS_YELLOW);
#endif
}

View file

@ -0,0 +1,55 @@
CONTIKI_PROJECT=border-router
all: $(CONTIKI_PROJECT)
CONTIKI=../../../../..
#linker optimizations
SMALL=1
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
PROJECT_SOURCEFILES += eth-bridge.c
#PROJECT_SOURCEFILES += enc28j60.c
PROJECT_SOURCEFILES += enc28j60-ip64-driver.c
APPS += ping6
MODULES += dev/enc28j60 core/net/ip64
#Simple built-in webserver is the default.
#Override with make WITH_WEBSERVER=0 for no webserver.
#WITH_WEBSERVER=webserver-name will use /apps/webserver-name if it can be
#found in the /apps, /platform/$(TARGET)/apps/, or current directory (in that order).
# WITH_WEBSERVER=webserver for /apps/webserver
# WITH_WEBSERVER=raven-webserver for /platform/avr-raven/apps/raven-webserver/
#make clean before changing webservers!
#Note /apps/webserver contains a 2500 byte style sheet which is a severe test
#of the slip connection. Large MSS together with low baud rates without flow
#control will overrun the transmit buffer when the style sheet is requested.
WITH_WEBSERVER=1
ifeq ($(WITH_WEBSERVER),1)
CFLAGS += -DUIP_CONF_TCP=1
CFLAGS += -DWEBSERVER=1
PROJECT_SOURCEFILES += httpd-simple.c
else ifneq ($(WITH_WEBSERVER), 0)
APPS += $(WITH_WEBSERVER)
CFLAGS += -DUIP_CONF_TCP=1
CFLAGS += -DWEBSERVER=2
endif
ifeq ($(PREFIX),)
PREFIX = aaaa::1/64
endif
CONTIKI_WITH_IPV6 = 1
include $(CONTIKI)/Makefile.include
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
connect-router: $(CONTIKI)/tools/tunslip6
sudo $(CONTIKI)/tools/tunslip6 $(PREFIX)
connect-router-cooja: $(CONTIKI)/tools/tunslip6
sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 $(PREFIX)

View file

@ -0,0 +1,66 @@
Document version: 2015-12-29
HOWTO connect the Microchip enc28j60 module
===========================================
It's possible to to add Ethernet to most microcontrollers having a SPI inter-
face. In the Atmel world the SPI pins are used for the ISP programming. Usually
a 6-pin header. Named MOSI, MISO, SCK, CS (Chup Select), Vcc, GND
One popular Ethernet chip is Microchip ENC28J60. It been used for quite some
time and is easy to program and are also supported by many platforms and
projects. Contiki has files under:
Most focus fon AVR platforms. The SPI is used by Atmel ISP-progammings
interface. In addition to those pins you to selects a pin for chip
select (CS).
dev/enc28j60/
The low-level SPI drives is platform or rather CPU-specific. The avr-rss2
platform adds the low-level drivers for Atmel.
platform/avr-rss2/enc28j60_avr.[ch]
This should be usable on most 8-bit avr platforms.
The power consumption might be a problem. The enc28j60 consumes 160mA at 3.3V
when transmitting. The LDO (voltage reg. LP2950) on the mote can only handle
100mA. So external power is needed. Below is a description of a prototype.
Used components:
----------------
Externel power supply 5V.
Small breadboard
DC-jack
Voltage Reg. LCP1700 3.3V
Capacitor 4.7uF
enc28j60 (From Ebay)
Pin-headers
Cables 2x5 (enc28j60) 2x3 SPI (AtMega node)
Used colors:
Black GND
Red VCC 3.3V
Yellow SCK
Green MISO
White MOSI
Blue CS (Chip select)
SPI (Connector view)
--------------------
GREEN YELLOW NC
RED WHITE BLACK
CS is connected to external temp sensor middle pin. Consequently the
external temp sensor can not be used in this application.
Pictures
--------
![Module] ( http://www.radio-sensors.com/pictures/enc28j60.jpg)
![Connector] (http://www.radio-sensors.com/pictures/enc28c60-cable.jpg)
References
-----------

View file

@ -0,0 +1,17 @@
Document version: 2016-02-22
An ethernet-to-802.15.4 NAT/GW IP64
===================================
This project is heavily based on the rpl-border-router in the example directory
using the IP64 framework. This work is done Contiki/Thingsquare as the driver
for enc28j60.
But rather than using slip as in the original example an ethernet interface
the Microchip enc28j60 is used. The needed SPI-glue for AtMega's is added by
this platform. (avr-rss2)
See the README.ETHERNET.md for ethernet module info.

View file

@ -0,0 +1,388 @@
/*
* 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
* border-router
* \author
* Niclas Finne <nfi@sics.se>
* Joakim Eriksson <joakime@sics.se>
* Nicolas Tsiftes <nvt@sics.se>
*/
#include "contiki.h"
#include "contiki-lib.h"
#include "contiki-net.h"
#include "net/ip/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "ip64.h"
#include "net/rpl/rpl.h"
#include "enc28j60.h"
#include "enc28j60-ip64-driver.h"
#include "net/netstack.h"
#include "dev/button-sensor.h"
#include "dev/slip.h"
#include "dev/leds.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define DEBUG DEBUG_PRINT
#include "net/ip/uip-debug.h"
static uip_ipaddr_t prefix;
static uint8_t prefix_set;
PROCESS(border_router_process, "Border router process");
#if WEBSERVER==0
/* No webserver */
AUTOSTART_PROCESSES(&border_router_process);
#elif WEBSERVER>1
/* Use an external webserver application */
#include "webserver-nogui.h"
AUTOSTART_PROCESSES(&border_router_process,&webserver_nogui_process);
#else
/* Use simple webserver with only one page for minimum footprint.
* Multiple connections can result in interleaved tcp segments since
* a single static buffer is used for all segments.
*/
#include "httpd-simple.h"
/* The internal webserver can provide additional information if
* enough program flash is available.
*/
#define WEBSERVER_CONF_LOADTIME 1
#define WEBSERVER_CONF_FILESTATS 1
#define WEBSERVER_CONF_NEIGHBOR_STATUS 1
/* Adding links requires a larger RAM buffer. To avoid static allocation
* the stack can be used for formatting; however tcp retransmissions
* and multiple connections can result in garbled segments.
* TODO:use PSOCk_GENERATOR_SEND and tcp state storage to fix this.
*/
#define WEBSERVER_CONF_ROUTE_LINKS 1
#if WEBSERVER_CONF_ROUTE_LINKS
#define BUF_USES_STACK 1
#endif
PROCESS(webserver_nogui_process, "Web server");
PROCESS_THREAD(webserver_nogui_process, ev, data)
{
PROCESS_BEGIN();
httpd_init();
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
httpd_appcall(data);
}
PROCESS_END();
}
AUTOSTART_PROCESSES(&border_router_process,&webserver_nogui_process);
static const char *TOP = "<html><head><title>ContikiRPL</title></head><body>\n";
static const char *BOTTOM = "</body></html>\n";
#if BUF_USES_STACK
static char *bufptr, *bufend;
#define ADD(...) do { \
bufptr += snprintf(bufptr, bufend - bufptr, __VA_ARGS__); \
} while(0)
#else
static char buf[256];
static int blen;
#define ADD(...) do { \
blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \
} while(0)
#endif
/*---------------------------------------------------------------------------*/
static void
ipaddr_add(const uip_ipaddr_t *addr)
{
uint16_t a;
int i, f;
for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) {
a = (addr->u8[i] << 8) + addr->u8[i + 1];
if(a == 0 && f >= 0) {
if(f++ == 0) ADD("::");
} else {
if(f > 0) {
f = -1;
} else if(i > 0) {
ADD(":");
}
ADD("%x", a);
}
}
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(generate_routes(struct httpd_state *s))
{
static uip_ds6_route_t *r;
static uip_ds6_nbr_t *nbr;
#if BUF_USES_STACK
char buf[256];
#endif
#if WEBSERVER_CONF_LOADTIME
static clock_time_t numticks;
numticks = clock_time();
#endif
PSOCK_BEGIN(&s->sout);
SEND_STRING(&s->sout, TOP);
#if BUF_USES_STACK
bufptr = buf;bufend=bufptr+sizeof(buf);
#else
blen = 0;
#endif
ADD("Neighbors<pre>");
for(nbr = nbr_table_head(ds6_neighbors);
nbr != NULL;
nbr = nbr_table_next(ds6_neighbors, nbr)) {
#if WEBSERVER_CONF_NEIGHBOR_STATUS
#if BUF_USES_STACK
{char* j=bufptr+25;
ipaddr_add(&nbr->ipaddr);
while (bufptr < j) ADD(" ");
switch (nbr->state) {
case NBR_INCOMPLETE: ADD(" INCOMPLETE");break;
case NBR_REACHABLE: ADD(" REACHABLE");break;
case NBR_STALE: ADD(" STALE");break;
case NBR_DELAY: ADD(" DELAY");break;
case NBR_PROBE: ADD(" NBR_PROBE");break;
}
}
#else
{uint8_t j=blen+25;
ipaddr_add(&nbr->ipaddr);
while (blen < j) ADD(" ");
switch (nbr->state) {
case NBR_INCOMPLETE: ADD(" INCOMPLETE");break;
case NBR_REACHABLE: ADD(" REACHABLE");break;
case NBR_STALE: ADD(" STALE");break;
case NBR_DELAY: ADD(" DELAY");break;
case NBR_PROBE: ADD(" NBR_PROBE");break;
}
}
#endif
#else
ipaddr_add(&nbr->ipaddr);
#endif
ADD("\n");
#if BUF_USES_STACK
if(bufptr > bufend - 45) {
SEND_STRING(&s->sout, buf);
bufptr = buf; bufend = bufptr + sizeof(buf);
}
#else
if(blen > sizeof(buf) - 45) {
SEND_STRING(&s->sout, buf);
blen = 0;
}
#endif
}
ADD("</pre>Routes<pre>");
SEND_STRING(&s->sout, buf);
#if BUF_USES_STACK
bufptr = buf; bufend = bufptr + sizeof(buf);
#else
blen = 0;
#endif
for(r = uip_ds6_route_head(); r != NULL; r = uip_ds6_route_next(r)) {
#if BUF_USES_STACK
#if WEBSERVER_CONF_ROUTE_LINKS
ADD("<a href=http://[");
ipaddr_add(&r->ipaddr);
ADD("]/status.shtml>");
ipaddr_add(&r->ipaddr);
ADD("</a>");
#else
ipaddr_add(&r->ipaddr);
#endif
#else
#if WEBSERVER_CONF_ROUTE_LINKS
ADD("<a href=http://[");
ipaddr_add(&r->ipaddr);
ADD("]/status.shtml>");
SEND_STRING(&s->sout, buf); //TODO: why tunslip6 needs an output here, wpcapslip does not
blen = 0;
ipaddr_add(&r->ipaddr);
ADD("</a>");
#else
ipaddr_add(&r->ipaddr);
#endif
#endif
ADD("/%u (via ", r->length);
ipaddr_add(uip_ds6_route_nexthop(r));
if(1 || (r->state.lifetime < 600)) {
ADD(") %lus\n", (unsigned long)r->state.lifetime);
} else {
ADD(")\n");
}
SEND_STRING(&s->sout, buf);
#if BUF_USES_STACK
bufptr = buf; bufend = bufptr + sizeof(buf);
#else
blen = 0;
#endif
}
ADD("</pre>");
#if WEBSERVER_CONF_FILESTATS
static uint16_t numtimes;
ADD("<br><i>This page sent %u times</i>",++numtimes);
#endif
#if WEBSERVER_CONF_LOADTIME
numticks = clock_time() - numticks + 1;
ADD(" <i>(%lu.%02lu sec)</i>",numticks/CLOCK_SECOND,((100*(numticks%CLOCK_SECOND))/CLOCK_SECOND));
#endif
SEND_STRING(&s->sout, buf);
SEND_STRING(&s->sout, BOTTOM);
PSOCK_END(&s->sout);
}
/*---------------------------------------------------------------------------*/
httpd_simple_script_t
httpd_simple_get_script(const char *name)
{
return generate_routes;
}
#endif /* WEBSERVER */
/*---------------------------------------------------------------------------*/
static void
print_local_addresses(void)
{
int i;
uint8_t state;
PRINTA("Server IPv6 addresses:\n");
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state;
if(uip_ds6_if.addr_list[i].isused &&
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
PRINTA(" ");
uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
PRINTA("\n");
}
}
}
/*---------------------------------------------------------------------------*/
void
request_prefix(void)
{
/* mess up uip_buf with a dirty request... */
uip_buf[0] = '?';
uip_buf[1] = 'P';
uip_len = 2;
//slip_send();
uip_clear_buf();
}
/*---------------------------------------------------------------------------*/
void
set_prefix_64(uip_ipaddr_t *prefix_64)
{
rpl_dag_t *dag;
uip_ipaddr_t ipaddr;
memcpy(&prefix, prefix_64, 16);
memcpy(&ipaddr, prefix_64, 16);
prefix_set = 1;
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &ipaddr);
if(dag != NULL) {
rpl_set_prefix(dag, &prefix, 64);
PRINTF("created a new RPL dag\n");
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data)
{
PROCESS_BEGIN();
uip_ipaddr_t ipaddr;
/* While waiting for the prefix to be sent through the SLIP connection, the future
* border router can join an existing DAG as a parent or child, or acquire a default
* router that will later take precedence over the SLIP fallback interface.
* Prevent that by turning the radio off until we are initialized as a DAG root.
*/
prefix_set = 0;
NETSTACK_MAC.off(0);
PROCESS_PAUSE();
SENSORS_ACTIVATE(button_sensor);
leds_init();
ip64_init();
PRINTF("RPL-Border router started\n");
#if 0
/* The border router runs with a 100% duty cycle in order to ensure high
packet reception rates.
Note if the MAC RDC is not turned off now, aggressive power management of the
cpu will interfere with establishing the SLIP connection */
NETSTACK_MAC.off(1);
#endif
/* Now turn the radio on, but disable radio duty cycling.
* Since we are the DAG root, reception delays would constrain mesh throughbut.
*/
NETSTACK_MAC.off(1);
/* Derived from link local (MAC) address */
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
set_prefix_64(&ipaddr);
print_local_addresses();
while(1) {
PROCESS_YIELD();
leds_on(LEDS_YELLOW);
if (ev == sensors_event && data == &button_sensor) {
PRINTF("Initiating global repair\n");
rpl_repair_root(RPL_DEFAULT_INSTANCE);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,104 @@
/*
* Copyright (c) 2012-2013, Thingsquare, http://www.thingsquare.com/.
* 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 "enc28j60.h"
#include "enc28j60-ip64-driver.h"
#include "net/linkaddr.h"
#include "ip64.h"
#include "ip64-eth.h"
#include <string.h>
#include <stdio.h>
PROCESS(enc28j60_ip64_driver_process, "ENC28J60 IP64 driver");
/*---------------------------------------------------------------------------*/
static void
init(void)
{
uint8_t eui64[8];
uint8_t macaddr[6];
/* Assume that linkaddr_node_addr holds the EUI64 of this device. */
memcpy(eui64, &linkaddr_node_addr, sizeof(eui64));
/* Mangle the EUI64 into a 48-bit Ethernet address. */
memcpy(&macaddr[0], &eui64[0], 3);
memcpy(&macaddr[3], &eui64[5], 3);
/* In case the OUI happens to contain a broadcast bit, we mask that
out here. */
macaddr[0] = (macaddr[0] & 0xfe);
/* Set the U/L bit, in order to create a locally administered MAC address */
macaddr[0] = (macaddr[0] | 0x02);
memcpy(ip64_eth_addr.addr, macaddr, sizeof(macaddr));
printf("MAC addr %02x:%02x:%02x:%02x:%02x:%02x\n",
macaddr[0], macaddr[1], macaddr[2],
macaddr[3], macaddr[4], macaddr[5]);
enc28j60_init(macaddr);
process_start(&enc28j60_ip64_driver_process, NULL);
}
/*---------------------------------------------------------------------------*/
static int
output(uint8_t *packet, uint16_t len)
{
enc28j60_send(packet, len);
return len;
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(enc28j60_ip64_driver_process, ev, data)
{
static int len;
static struct etimer e;
PROCESS_BEGIN();
while(1) {
etimer_set(&e, 1);
PROCESS_WAIT_EVENT();
len = enc28j60_read(ip64_packet_buffer, ip64_packet_buffer_maxlen);
if(len > 0) {
IP64_INPUT(ip64_packet_buffer, len);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
const struct ip64_driver enc28j60_ip64_driver = {
init,
output
};
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2012-2013, Thingsquare, http://www.thingsquare.com/.
* 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 ENC28J60_IP64_DRIVER_H
#define ENC28J60_IP64_DRIVER_H
#include "ip64-driver.h"
extern const struct ip64_driver enc28j60_ip64_driver;
#endif /* ENC28J60_IP64_DRIVER_H */

View file

@ -0,0 +1,33 @@
#include "net/ip/uip.h"
#include "net/ipv6/uip-ds6.h"
#include <string.h>
#include "ip64-eth-interface.h"
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define DEBUG DEBUG_NONE
#include "net/ip/uip-debug.h"
static void
init(void)
{
PRINTF("eth-bridge: init\n");
ip64_eth_interface.init();
}
/*---------------------------------------------------------------------------*/
static int
output()
{
PRINTF("eth-bridge: src=");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF(" dst=");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("\n");
ip64_eth_interface.output();
return 0;
}
/*---------------------------------------------------------------------------*/
const struct uip_fallback_interface rpl_interface = {
init, output
};
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,261 @@
/*
* Copyright (c) 2010, Swedish Institute of Computer Science.
* 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.
*
*/
/**
* \file
* A simple web server forwarding page generation to a protothread
* \author
* Adam Dunkels <adam@sics.se>
* Niclas Finne <nfi@sics.se>
* Joakim Eriksson <joakime@sics.se>
*/
#include <stdio.h>
#include <string.h>
#include "contiki-net.h"
//#include "urlconv.h"
#include "httpd-simple.h"
#define webserver_log_file(...)
#define webserver_log(...)
#ifndef WEBSERVER_CONF_CFS_CONNS
#define CONNS UIP_CONNS
#else /* WEBSERVER_CONF_CFS_CONNS */
#define CONNS WEBSERVER_CONF_CFS_CONNS
#endif /* WEBSERVER_CONF_CFS_CONNS */
#ifndef WEBSERVER_CONF_CFS_URLCONV
#define URLCONV 0
#else /* WEBSERVER_CONF_CFS_URLCONV */
#define URLCONV WEBSERVER_CONF_CFS_URLCONV
#endif /* WEBSERVER_CONF_CFS_URLCONV */
#define STATE_WAITING 0
#define STATE_OUTPUT 1
MEMB(conns, struct httpd_state, CONNS);
#define ISO_nl 0x0a
#define ISO_space 0x20
#define ISO_period 0x2e
#define ISO_slash 0x2f
/*---------------------------------------------------------------------------*/
static const char *NOT_FOUND = "<html><body bgcolor=\"white\">"
"<center>"
"<h1>404 - file not found</h1>"
"</center>"
"</body>"
"</html>";
/*---------------------------------------------------------------------------*/
static
PT_THREAD(send_string(struct httpd_state *s, const char *str))
{
PSOCK_BEGIN(&s->sout);
SEND_STRING(&s->sout, str);
PSOCK_END(&s->sout);
}
/*---------------------------------------------------------------------------*/
const char http_content_type_html[] = "Content-type: text/html\r\n\r\n";
static
PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
{
/* char *ptr; */
PSOCK_BEGIN(&s->sout);
SEND_STRING(&s->sout, statushdr);
/* ptr = strrchr(s->filename, ISO_period); */
/* if(ptr == NULL) { */
/* s->ptr = http_content_type_plain; */
/* } else if(strcmp(http_html, ptr) == 0) { */
/* s->ptr = http_content_type_html; */
/* } else if(strcmp(http_css, ptr) == 0) { */
/* s->ptr = http_content_type_css; */
/* } else if(strcmp(http_png, ptr) == 0) { */
/* s->ptr = http_content_type_png; */
/* } else if(strcmp(http_gif, ptr) == 0) { */
/* s->ptr = http_content_type_gif; */
/* } else if(strcmp(http_jpg, ptr) == 0) { */
/* s->ptr = http_content_type_jpg; */
/* } else { */
/* s->ptr = http_content_type_binary; */
/* } */
/* SEND_STRING(&s->sout, s->ptr); */
SEND_STRING(&s->sout, http_content_type_html);
PSOCK_END(&s->sout);
}
/*---------------------------------------------------------------------------*/
const char http_header_200[] = "HTTP/1.0 200 OK\r\nServer: Contiki/2.4 http://www.sics.se/contiki/\r\nConnection: close\r\n";
const char http_header_404[] = "HTTP/1.0 404 Not found\r\nServer: Contiki/2.4 http://www.sics.se/contiki/\r\nConnection: close\r\n";
static
PT_THREAD(handle_output(struct httpd_state *s))
{
PT_BEGIN(&s->outputpt);
s->script = NULL;
s->script = httpd_simple_get_script(&s->filename[1]);
if(s->script == NULL) {
strncpy(s->filename, "/notfound.html", sizeof(s->filename));
PT_WAIT_THREAD(&s->outputpt,
send_headers(s, http_header_404));
PT_WAIT_THREAD(&s->outputpt,
send_string(s, NOT_FOUND));
uip_close();
webserver_log_file(&uip_conn->ripaddr, "404 - not found");
PT_EXIT(&s->outputpt);
} else {
PT_WAIT_THREAD(&s->outputpt,
send_headers(s, http_header_200));
PT_WAIT_THREAD(&s->outputpt, s->script(s));
}
s->script = NULL;
PSOCK_CLOSE(&s->sout);
PT_END(&s->outputpt);
}
/*---------------------------------------------------------------------------*/
const char http_get[] = "GET ";
const char http_index_html[] = "/index.html";
//const char http_referer[] = "Referer:"
static
PT_THREAD(handle_input(struct httpd_state *s))
{
PSOCK_BEGIN(&s->sin);
PSOCK_READTO(&s->sin, ISO_space);
if(strncmp(s->inputbuf, http_get, 4) != 0) {
PSOCK_CLOSE_EXIT(&s->sin);
}
PSOCK_READTO(&s->sin, ISO_space);
if(s->inputbuf[0] != ISO_slash) {
PSOCK_CLOSE_EXIT(&s->sin);
}
#if URLCONV
s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
urlconv_tofilename(s->filename, s->inputbuf, sizeof(s->filename));
#else /* URLCONV */
if(s->inputbuf[1] == ISO_space) {
strncpy(s->filename, http_index_html, sizeof(s->filename));
} else {
s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
strncpy(s->filename, s->inputbuf, sizeof(s->filename));
}
#endif /* URLCONV */
webserver_log_file(&uip_conn->ripaddr, s->filename);
s->state = STATE_OUTPUT;
while(1) {
PSOCK_READTO(&s->sin, ISO_nl);
#if 0
if(strncmp(s->inputbuf, http_referer, 8) == 0) {
s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
webserver_log(s->inputbuf);
}
#endif
}
PSOCK_END(&s->sin);
}
/*---------------------------------------------------------------------------*/
static void
handle_connection(struct httpd_state *s)
{
handle_input(s);
if(s->state == STATE_OUTPUT) {
handle_output(s);
}
}
/*---------------------------------------------------------------------------*/
void
httpd_appcall(void *state)
{
struct httpd_state *s = (struct httpd_state *)state;
if(uip_closed() || uip_aborted() || uip_timedout()) {
if(s != NULL) {
s->script = NULL;
memb_free(&conns, s);
}
} else if(uip_connected()) {
s = (struct httpd_state *)memb_alloc(&conns);
if(s == NULL) {
uip_abort();
webserver_log_file(&uip_conn->ripaddr, "reset (no memory block)");
return;
}
tcp_markconn(uip_conn, s);
PSOCK_INIT(&s->sin, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1);
PSOCK_INIT(&s->sout, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1);
PT_INIT(&s->outputpt);
s->script = NULL;
s->state = STATE_WAITING;
timer_set(&s->timer, CLOCK_SECOND * 10);
handle_connection(s);
} else if(s != NULL) {
if(uip_poll()) {
if(timer_expired(&s->timer)) {
uip_abort();
s->script = NULL;
memb_free(&conns, s);
webserver_log_file(&uip_conn->ripaddr, "reset (timeout)");
}
} else {
timer_restart(&s->timer);
}
handle_connection(s);
} else {
uip_abort();
}
}
/*---------------------------------------------------------------------------*/
void
httpd_init(void)
{
tcp_listen(UIP_HTONS(80));
memb_init(&conns);
#if URLCONV
urlconv_init();
#endif /* URLCONV */
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,74 @@
/*
* Copyright (c) 2010, Swedish Institute of Computer Science.
* 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.
*
*/
/**
* \file
* A simple webserver
* \author
* Adam Dunkels <adam@sics.se>
* Niclas Finne <nfi@sics.se>
* Joakim Eriksson <joakime@sics.se>
*/
#ifndef HTTPD_SIMPLE_H_
#define HTTPD_SIMPLE_H_
#include "contiki-net.h"
/* The current internal border router webserver ignores the requested file name */
/* and needs no per-connection output buffer, so save some RAM */
#ifndef WEBSERVER_CONF_CFS_PATHLEN
#define HTTPD_PATHLEN 2
#else /* WEBSERVER_CONF_CFS_CONNS */
#define HTTPD_PATHLEN WEBSERVER_CONF_CFS_PATHLEN
#endif /* WEBSERVER_CONF_CFS_CONNS */
struct httpd_state;
typedef char (* httpd_simple_script_t)(struct httpd_state *s);
struct httpd_state {
struct timer timer;
struct psock sin, sout;
struct pt outputpt;
char inputbuf[HTTPD_PATHLEN + 24];
/*char outputbuf[UIP_TCP_MSS]; */
char filename[HTTPD_PATHLEN];
httpd_simple_script_t script;
char state;
};
void httpd_init(void);
void httpd_appcall(void *state);
httpd_simple_script_t httpd_simple_get_script(const char *name);
#define SEND_STRING(s, str) PSOCK_SEND(s, (uint8_t *)str, strlen(str))
#endif /* HTTPD_SIMPLE_H_ */

View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2010, Swedish Institute of Computer Science.
* 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.
*
*/
#ifndef PROJECT_ROUTER_CONF_H_
#define PROJECT_ROUTER_CONF_H_
#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_MAC nullmac_driver
#ifndef UIP_FALLBACK_INTERFACE
#define UIP_FALLBACK_INTERFACE rpl_interface
#endif
#ifndef QUEUEBUF_CONF_NUM
#define QUEUEBUF_CONF_NUM 4
#endif
#ifndef UIP_CONF_BUFFER_SIZE
#define UIP_CONF_BUFFER_SIZE 600
#endif
#ifndef UIP_CONF_RECEIVE_WINDOW
#define UIP_CONF_RECEIVE_WINDOW 60
#endif
#ifndef WEBSERVER_CONF_CFS_CONNS
#define WEBSERVER_CONF_CFS_CONNS 2
#endif
#endif /* PROJECT_ROUTER_CONF_H_ */

View file

@ -0,0 +1,21 @@
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
all: report sink
APPS=servreg-hack
CONTIKI=../../../../..
ifdef WITH_COMPOWER
APPS+=powertrace
CFLAGS+= -DCONTIKIMAC_CONF_COMPOWER=1 -DWITH_COMPOWER=1 -DQUEUEBUF_CONF_NUM=4
endif
ifdef SERVER_REPLY
CFLAGS+=-DSERVER_REPLY=$(SERVER_REPLY)
endif
ifdef PERIOD
CFLAGS+=-DPERIOD=$(PERIOD)
endif
CONTIKI_WITH_IPV6 = 1
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,17 @@
This application is derived form rpl-udp.
It's modified to show:
* Reading out sensors from the avr-rss2 platform. Which should follow the
Contiki conventions.
* Encode the data according to the sensd TAG format. In effect the sensd
GW and rest of "eco-system" as Mobile apps etc can be used for a simple
and flexible data collection, Sink mote will be connected to sensd GW.
References and code:
https://github.com/herjulf/sensd
https://github.com/herjulf/Read-Sensors (Android app. Also at Google Play)

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2015, RAdio Sensors AB, Uppsala Sweden
* 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
* Project specific configuration defines for example
*
* \author
* Robert Olsson <robert@radio-sensors.com>
*/
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_MAC nullmac_driver
//#define NETSTACK_CONF_MAC csma_driver
//#define NETSTACK_CONF_RDC contikimac_driver
//#define NETSTACK_CONF_FRAMER framer_802154
//#define NETSTACK_CONF_RADIO rf230_driver
#endif /* PROJECT_CONF_H_ */

View file

@ -0,0 +1,240 @@
/*
* 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.
*
*/
#include "contiki.h"
#include "lib/random.h"
#include "sys/ctimer.h"
#include "net/ip/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/ip/uip-udp-packet.h"
#include "sys/ctimer.h"
#include "dev/leds.h"
#include "dev/battery-sensor.h"
#include "dev/temp_mcu-sensor.h"
#include "dev/light-sensor.h"
#ifdef CO2
#include "dev/co2_sa_kxx-sensor.h"
#endif
#ifdef WITH_COMPOWER
#include "powertrace.h"
#endif
#include <stdio.h>
#include <string.h>
#define UDP_CLIENT_PORT 8765
#define UDP_SERVER_PORT 5678
#define UDP_EXAMPLE_ID 190
#define DEBUG DEBUG_PRINT
#include "net/ip/uip-debug.h"
#ifndef PERIOD
#define PERIOD 10
#endif
#define START_INTERVAL (15 * CLOCK_SECOND)
#define SEND_INTERVAL (PERIOD * CLOCK_SECOND)
#define SEND_TIME (random_rand() % (SEND_INTERVAL))
#define MAX_PAYLOAD_LEN 50
static struct uip_udp_conn *client_conn;
static uip_ipaddr_t server_ipaddr;
extern uint16_t node_id; /* Can be set by cooja */
/*---------------------------------------------------------------------------*/
PROCESS(udp_client_process, "UDP client process");
AUTOSTART_PROCESSES(&udp_client_process);
/*---------------------------------------------------------------------------*/
static void
tcpip_handler(void)
{
char *str;
if(uip_newdata()) {
str = uip_appdata;
str[uip_datalen()] = '\0';
printf("DATA recv '%s'\n", str);
}
}
/*---------------------------------------------------------------------------*/
static void
send_packet(void *ptr)
{
static int seq_id;
char buf[MAX_PAYLOAD_LEN];
int len = 0;
seq_id++;
len += snprintf((char *) &buf[len], sizeof(buf), "&: ");
len += snprintf((char *) &buf[len], sizeof(buf), "V_MCU=%-d ", battery_sensor.value(0));
/*
* Cooja needs to set a node_id. So we can skip sensor reading in case of simulation.
*/
if(node_id == 0) {
len += snprintf((char *) &buf[len], sizeof(buf), "T_MCU=%-d ", temp_mcu_sensor.value(0));
len += snprintf((char *) &buf[len], sizeof(buf), "LIGHT=%-d ", light_sensor.value(0));
#ifdef CO2
len += snprintf((char *) &buf[len], sizeof(buf), "CO2=%-d ", co2_sa_kxx_sensor.value(value));
#endif
}
PRINTF("TX %d to %d %s\n",
server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id, buf);
leds_on(LEDS_YELLOW);
uip_udp_packet_sendto(client_conn, buf, strlen(buf),
&server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
}
/*---------------------------------------------------------------------------*/
static void
print_local_addresses(void)
{
int i;
uint8_t state;
PRINTF("Client IPv6 addresses: ");
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state;
if(uip_ds6_if.addr_list[i].isused &&
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
PRINTF("\n");
/* hack to make address "final" */
if (state == ADDR_TENTATIVE) {
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
}
}
}
}
/*---------------------------------------------------------------------------*/
static void
set_global_address(void)
{
uip_ipaddr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
/* The choice of server address determines its 6LoPAN header compression.
* (Our address will be compressed Mode 3 since it is derived from our link-local address)
* Obviously the choice made here must also be selected in udp-server.c.
*
* For correct Wireshark decoding using a sniffer, add the /64 prefix to the 6LowPAN protocol preferences,
* e.g. set Context 0 to aaaa::. At present Wireshark copies Context/128 and then overwrites it.
* (Setting Context 0 to aaaa::1111:2222:3333:4444 will report a 16 bit compressed address of aaaa::1111:22ff:fe33:xxxx)
*
* Note the IPCMV6 checksum verification depends on the correct uncompressed addresses.
*/
#if 0
/* Mode 1 - 64 bits inline */
uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
#elif 1
/* Mode 2 - 16 bits inline */
uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0x00ff, 0xfe00, 1);
#else
/* Mode 3 - derived from server link-local (MAC) address */
uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0x0250, 0xc2ff, 0xfea8, 0xcd1a); //redbee-econotag
#endif
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
static struct etimer periodic;
static struct ctimer backoff_timer;
#if WITH_COMPOWER
static int print = 0;
#endif
PROCESS_BEGIN();
PROCESS_PAUSE();
SENSORS_ACTIVATE(battery_sensor);
SENSORS_ACTIVATE(temp_mcu_sensor);
SENSORS_ACTIVATE(light_sensor);
#ifdef CO2
SENSORS_ACTIVATE(co2_sa_kxx_sensor);
#endif
set_global_address();
leds_init();
PRINTF("UDP client process started\n");
print_local_addresses();
/* new connection with remote host */
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL);
if(client_conn == NULL) {
PRINTF("No UDP connection available, exiting the process!\n");
PROCESS_EXIT();
}
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT));
PRINTF("Created a connection with the server ");
PRINT6ADDR(&client_conn->ripaddr);
PRINTF(" local/remote port %u/%u\n",
UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));
#if WITH_COMPOWER
powertrace_sniff(POWERTRACE_ON);
#endif
etimer_set(&periodic, SEND_INTERVAL);
while(1) {
PROCESS_YIELD();
if(ev == tcpip_event) {
tcpip_handler();
}
if(etimer_expired(&periodic)) {
etimer_reset(&periodic);
ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);
#if WITH_COMPOWER
if (print == 0) {
powertrace_print("#P");
}
if (++print == 3) {
print = 0;
}
#endif
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8"?>
<simconf>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/native_gateway</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/serial_socket</project>
<project EXPORT="discard">/home/user/contikiprojects/sics.se/mobility</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/collect-view</project>
<project EXPORT="discard">/home/user/contikiprojects/sics.se/powertracker</project>
<simulation>
<title>UDP sink/report simulation</title>
<randomseed>123456</randomseed>
<motedelay_us>1000000</motedelay_us>
<radiomedium>
se.sics.cooja.radiomediums.UDGM
<transmitting_range>50.0</transmitting_range>
<interference_range>100.0</interference_range>
<success_ratio_tx>1.0</success_ratio_tx>
<success_ratio_rx>1.0</success_ratio_rx>
</radiomedium>
<events>
<logoutput>40000</logoutput>
</events>
<motetype>
se.sics.cooja.avrmote.RSS2MoteType
<identifier>mote1</identifier>
<description>Mote1</description>
<source EXPORT="discard">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.c</source>
<commands EXPORT="discard">make report.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.avr-rss2</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraClock</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraMoteID</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart0</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart1</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.RFR2Radio</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraADC</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraLED</moteinterface>
</motetype>
<motetype>
se.sics.cooja.avrmote.RSS2MoteType
<identifier>mote2</identifier>
<description>Mote2</description>
<source EXPORT="discard">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.c</source>
<commands EXPORT="discard">make sink.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.avr-rss2</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraClock</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraMoteID</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart0</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart1</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.RFR2Radio</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraADC</moteinterface>
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraLED</moteinterface>
</motetype>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>100.0</x>
<y>100.0</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.avrmote.interfaces.AvroraMoteID
<id>1</id>
</interface_config>
<motetype_identifier>mote1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>110.0</x>
<y>100.0</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.avrmote.interfaces.AvroraMoteID
<id>2</id>
</interface_config>
<motetype_identifier>mote2</motetype_identifier>
</mote>
</simulation>
<plugin>
se.sics.cooja.plugins.SimControl
<width>280</width>
<z>9</z>
<height>160</height>
<location_x>400</location_x>
<location_y>0</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.Visualizer
<plugin_config>
<moterelations>true</moterelations>
<skin>se.sics.cooja.plugins.skins.IDVisualizerSkin</skin>
<skin>se.sics.cooja.plugins.skins.GridVisualizerSkin</skin>
<viewport>3.908924509090908 0.0 0.0 3.908924509090908 -216.43707345454544 -217.89245090909074</viewport>
</plugin_config>
<width>400</width>
<z>5</z>
<height>400</height>
<location_x>1</location_x>
<location_y>1</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.LogListener
<plugin_config>
<filter />
<formatted_time />
<coloring />
</plugin_config>
<width>1269</width>
<z>8</z>
<height>240</height>
<location_x>400</location_x>
<location_y>160</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.Notes
<plugin_config>
<notes>Enter notes here</notes>
<decorations>true</decorations>
</plugin_config>
<width>989</width>
<z>6</z>
<height>160</height>
<location_x>680</location_x>
<location_y>0</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.MoteInterfaceViewer
<mote_arg>0</mote_arg>
<plugin_config>
<interface>Serial port</interface>
<scrollpos>0,0</scrollpos>
</plugin_config>
<width>508</width>
<z>4</z>
<height>389</height>
<location_x>13</location_x>
<location_y>413</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.MoteInterfaceViewer
<mote_arg>1</mote_arg>
<plugin_config>
<interface>Serial port</interface>
<scrollpos>0,0</scrollpos>
</plugin_config>
<width>545</width>
<z>3</z>
<height>392</height>
<location_x>531</location_x>
<location_y>413</location_y>
</plugin>
</simconf>

View file

@ -0,0 +1,184 @@
/*
* 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.
*
*/
#include "contiki.h"
#include "contiki-lib.h"
#include "contiki-net.h"
#include "net/ip/uip.h"
#include "net/rpl/rpl.h"
#include "net/netstack.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define DEBUG DEBUG_PRINT
#include "net/ip/uip-debug.h"
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UDP_CLIENT_PORT 8765
#define UDP_SERVER_PORT 5678
#define UDP_EXAMPLE_ID 190
static struct uip_udp_conn *server_conn;
PROCESS(udp_server_process, "UDP server process");
AUTOSTART_PROCESSES(&udp_server_process);
/*---------------------------------------------------------------------------*/
static void
tcpip_handler(void)
{
char *appdata;
if(uip_newdata()) {
leds_on(LEDS_RED);
appdata = (char *)uip_appdata;
appdata[uip_datalen()] = 0;
PRINTF("Report RX '%s' from ", appdata);
PRINTF("%d",
UIP_IP_BUF->srcipaddr.u8[sizeof(UIP_IP_BUF->srcipaddr.u8) - 1]);
PRINTF("\n");
#if SERVER_REPLY
PRINTF("DATA sending reply\n");
uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
uip_udp_packet_send(server_conn, "Reply", sizeof("Reply"));
uip_create_unspecified(&server_conn->ripaddr);
#endif
}
}
/*---------------------------------------------------------------------------*/
static void
print_local_addresses(void)
{
int i;
uint8_t state;
PRINTF("Server 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);
PRINTF("\n");
/* hack to make address "final" */
if (state == ADDR_TENTATIVE) {
uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
}
}
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{
uip_ipaddr_t ipaddr;
struct uip_ds6_addr *root_if;
PROCESS_BEGIN();
PROCESS_PAUSE();
SENSORS_ACTIVATE(button_sensor);
leds_init();
PRINTF("UDP server started\n");
#if UIP_CONF_ROUTER
/* The choice of server address determines its 6LoPAN 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 aaaa::. At present Wireshark copies Context/128 and then overwrites it.
* (Setting Context 0 to aaaa::1111:2222:3333:4444 will report a 16 bit compressed address of aaaa::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, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
#elif 1
/* Mode 2 - 16 bits inline */
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0x00ff, 0xfe00, 1);
#else
/* Mode 3 - derived from link local (MAC) address */
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
#endif
uip_ds6_addr_add(&ipaddr, 0, ADDR_MANUAL);
root_if = uip_ds6_addr_lookup(&ipaddr);
if(root_if != NULL) {
rpl_dag_t *dag;
dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&ipaddr);
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
rpl_set_prefix(dag, &ipaddr, 64);
PRINTF("created a new RPL dag\n");
} else {
PRINTF("failed to create a new RPL DAG\n");
}
#endif /* UIP_CONF_ROUTER */
print_local_addresses();
/* The data sink runs with a 100% duty cycle in order to ensure high
packet reception rates. */
//NETSTACK_MAC.off(1);
server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL);
if(server_conn == NULL) {
PRINTF("No UDP connection available, exiting the process!\n");
PROCESS_EXIT();
}
udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT));
PRINTF("Created a server connection with remote address ");
PRINT6ADDR(&server_conn->ripaddr);
PRINTF(" local/remote port %u/%u\n", UIP_HTONS(server_conn->lport),
UIP_HTONS(server_conn->rport));
while(1) {
PROCESS_YIELD();
if(ev == tcpip_event) {
tcpip_handler();
} else if (ev == sensors_event && data == &button_sensor) {
PRINTF("Initiaing global repair\n");
rpl_repair_root(RPL_DEFAULT_INSTANCE);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,12 @@
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
all: sensd_client server
CONTIKI=../../../../..
ifdef PERIOD
CFLAGS+=-DPERIOD=$(PERIOD)
endif
CONTIKI_WITH_IPV6 = 1
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,222 @@
Contiki client for sensd
========================
Sensd README describes the concept. sensd code is on github.
sensd - A WSN Internet GW, hub, agent, proxy & cloud
====================================================
Authors
--------
Robert Olsson <robert@radio-sensors.com>
Jens Laas <jens.laas@uadm.uu.se>
Contributors
------------
Abstract
--------
We've outlined, designed and implemented and very simple concept for WSN
data sharing, including data collection, storage and retrieval using
standard text tools. The concept restricts Internet access to WSN
motes and acts agent not to expose motes directly for robustness and
security reasons. Low level, physical or link WSN protocol can be used.
including 6lowpan, RIME etc and any type of Radio Duty Cycling (RDC).
sensd works on the application layer. A TCP connection initiates an
implicit "subscribe". The M2P model is currently supported.
Key concepts
------------
* Agent. sensd works as an agent and does not allow direct Internet
access to motes. Recall motes are constrained in most aspects and
can not support many connections, has weak security etc.
* Hub. Share the data from the root or sink node over TCP. In effect sensor
data can be sent over Internet to be shared over among TCP active listeners.
The TCP connection initiates an implicit "subscribe".
* Proxy. The support proxy functions over ipv4 and well as ipv6. Sensd can
forward to a proxy on a public IP. The typical case is when GW is behind
a NAT.
* WSN RP "rendez-vous point". A concepts where data from various WSN nets
are merged. This models a "cloud service" functionality for WSN networks.
sensd can be used both to forward data to RP. It can also work as the RP.
RP receiving WSN data and allowing multiple TCP listeners.
* All programs are written C, script in Java and bash. Designed for small
footprint and with minimal dependencies. sensd runs on Raspberry Pi and
Openwrt.
* This work introduces a simple tag format for sensor data. The overall
idea is that data tagging is an "agreement" between producers and consumer.
Tags are simple are description of the data. Example T=25.2. where T=
is the tag 25.2 the value. Most likely this a temperature. But we
can't be sure since we don't know since this is an agreement between
the producer and the consumer. Tags are also used for identification.
Example tags, E64= Where globally unique ID can used. Another more
relaxed example is TXT= a user description. See docs.
* Geotagging and timestamping is supported via tags.
* Ecosystem support. There are telphone apps to for data monitoring and
and plotting. Android app can act as WSN-agent and forward to proxy/RP.
* The concept also includes a mapping to URI (Unified Resource Identifier)
to form a WSN caching server similar to CoAP using http-proxy.
* Copyright. Open-Source via GPL. Projecet used github.com
Introduction
------------
This is collection of software to implement data monitoring and data collection
from WSN Wireless Sensor Networks. The goal is to have a very simple,
straight-forward and robust framework.
The scenario: One or several motes is connected to USB or serial port to gather
received information from connected WSN motes. Data can be visualized in
several ways.
* Sensor data report can be transmitted and propagated throughout the
Internet. sensd acts as server and sends incoming report to active
listeners.
* Data is kept in ASCII with tagging and ID information. Data is conveniently
handled, copied and viewed with standard text utilities of your OS.
* Last mote report is cached into the file system suitable for URI use. The
Format is SID/TAG. Typical tags are EUI64 and unique serial numbers. The
different TAGS are left for mote user to define. Although the TAGS used in
our example setup are included in this draft for example purposes.
Both formats can easily be stored or linked directly in web tree to form a
URI to format WSN logging/datafile or caching service.
A daemon that reads WSN mote reports from USB/serial and stores data in a ASCII
data file. Default is located at _/var/log/sensors.dat_
Addtional components
--------------------
* seltag [More info] (https://github.com/herjulf/sensd/blob/master/seltag/README.md)
* js A set of Java-scripts can plot, print and visualize sensor data from
sensd directly in your web-browser.
* documentation and sample files. [More info] (https://github.com/herjulf/sensd/blob/master/seltag/README.md)
* Read Sensors Android app. [Source Code] (https://github.com/herjulf/Read-Sensors)
Datafile logging
----------------
Below is and example of the anatomy of a sensors.dat file we are currently using in our WSN
data collection networks.
2012-05-22 14:07:46 UT=1337688466 ID=283c0cdd030000d7 PS=0 T=30.56 T_MCU=34.6 V_MCU=3.08 UP=2C15C V_IN=4.66
2012-05-22 14:11:41 UT=1337688701 ID=28a9d5dc030000af PS=0 T=36.00 V_MCU=2.92 UP=12C8A0 RH=42.0 V_IN=4.13 V_A1=3.43 [ADDR=0.175 SEQ=33 RSSI=21 LQI=255 DRP=1.00]
Each line is a mote report. They start with date and time and are followed by a set of
tags. The tags is different for different motes. In other words they can
send different data. Essential is the ID which should be unique for each mote.
The information with brackets is information generated by the receiving mote
and is not a part the motes data. Typically RSSI (Receiver Signal Strength
Indicator) and LQI (Link Quality Indicator)
Internet sensor data
--------------------
Start sensd with the `-report` option. This enables reports to be transmitted
over IP to remote listeners. Default TCP port 1234.
Server side example:
sensd -report -p 1234 -D /dev/ttyUSB0
Client side. Example using netcat:
nc server-ip 1234
URI format
----------
URI (Unified Resource Identifier) displays the node ID and the tags in a file tree.
It is easy to export this into a web tree to form a URI similar to a CoAP gateway.
Example: In our case we have a unique sensor ID followed by the different data
fields represented by "tags".
/tmp/WSN1-GW1/281a98d20200004a:
DRP ID LQI PS RH RSSI SEQ T V_IN V_MCU ADDR
/tmp/WSN1-GW1/28be51ce02000031:
DRP ID LQI PS RH RSSI SEQ T UP V_IN V_MCU ADDR
Read Temp from a sensor:
cat /tmp/WSN1-GW1/281a98d20200004a/T
19.44
And it's very easy to link this tree into a web-server.
GPS support
-----------
Positioning support has been added via GPS device connected to serial
or USB port. Tags added when enabled GWGPS_LON & GWGPS_LAT.
GPS code from. https://github.com/herjulf/gps_simple
Getting the source and building
-------------------------------
Code is stored in github. Typically procedure below is the very straight-
forward unix way:
git clone http://github.com/herjulf/sensd
cd sensd
make
Put your binaries after your preference:
Pre-built binary versions
--------------------------
For x86:
Sensd and friends are available in Bifrost/Linux packages. Those packages are
statically linked and can be used on most x86 Linuxes. 32-bit compiled.
http://ftp.sunet.se/pub/Linux/distributions/bifrost/download/opt/opt-sensd-2.3-1.tar.gz
Use
---
The WSN data logging and caching concept is in actual use with Contiki, RIME
broadcast application.
Tips
----
One can use netcat to listen to reports:
Example:
nc radio-sensors.com 1235
To save in file use nohup:
nohup nc radio-sensors.com 1235 > /var/log/sensors.dat
As sensd used TCP and ASCII encoding. tetlnet and web-browsers can be used
as well.

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2015, RAdio Sensors AB, Uppsala Sweden
* 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
* Project specific configuration defines for example
*
* \author
* Robert Olsson <robert@radio-sensors.com>
*/
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_MAC nullmac_driver
//#define NETSTACK_CONF_MAC csma_driver
//#define NETSTACK_CONF_RDC contikimac_driver
//#define NETSTACK_CONF_FRAMER framer_802154
//#define NETSTACK_CONF_RADIO rf230_driver
#endif /* PROJECT_CONF_H_ */

View file

@ -0,0 +1,203 @@
/*
* Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB
* 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.
*
*
* Author : Robert Olsson robert@radio-sensors.com
* Created : 2015-12-28
*/
/**
* \file
* A simple application reporting sensor data. Can be sensd
*/
#include <string.h>
#include "contiki-net.h"
#include "leds.h"
#include "dev/leds.h"
#include "dev/battery-sensor.h"
#include "dev/temp-sensor.h"
#include "dev/temp_mcu-sensor.h"
#include "dev/light-sensor.h"
#include "dev/pulse-sensor.h"
#ifdef CO2
#include "dev/co2_sa_kxx-sensor.h"
#endif
#ifndef PERIOD
#define PERIOD 10
#endif
#define REPORT_INTERVAL (PERIOD * CLOCK_SECOND)
#define DEBUG DEBUG_PRINT
#include "uip-debug.h"
#define PORT 1234
#define MAX_PAYLOAD_LEN 80
static struct psock ps;
static uint8_t out_buf[MAX_PAYLOAD_LEN];
static char in_buffer[MAX_PAYLOAD_LEN];
static int i;
static int send_now;
static clock_time_t report_interval = REPORT_INTERVAL;
static uint8_t state;
static uip_ipaddr_t addr;
static struct timer t, t1;
static struct etimer et, et1;
PROCESS(sensd_client_process, "sensd TCP client process");
PROCESS(report_timer_process, "report pacemaker");
AUTOSTART_PROCESSES
(&sensd_client_process,&report_timer_process);
static int
do_report(void)
{
static int seq_id;
int len = 0;
seq_id++;
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "&: ");
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "TXT=ERICSON-6LOWPAN ");
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "TARGET=avr-rss2 ");
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "V_MCU=%-d ", battery_sensor.value(0));
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "T_MCU=%-d ", temp_mcu_sensor.value(0));
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "LIGHT=%-d ", light_sensor.value(0));
#ifdef CO2
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "CO2=%-d ", co2_sa_kxx_sensor.value(CO2_SA_KXX_CO2));
#endif
len += snprintf((char *) &out_buf[len], sizeof(out_buf), "\n\r");
return len;
}
static void
print_local_addresses(void)
{
PRINTF("Server IPv6 addresses:\n\r");
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state;
if(uip_ds6_if.addr_list[i].isused &&
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
PRINTF("\n\r");
}
}
}
static void
set_global_address(void)
{
uip_ipaddr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
}
static int handle_connection(struct psock *p, long ts) {
PSOCK_BEGIN(p);
if(send_now) {
do_report();
leds_on(LEDS_YELLOW);
PSOCK_SEND(p, (const uint8_t *) out_buf, strlen((const char *) out_buf));
send_now = 0;
}
PSOCK_END(p);
}
PROCESS_THREAD(report_timer_process, ev, data) {
PROCESS_BEGIN();
while(1) {
timer_set(&t1, report_interval);
etimer_set(&et1, timer_remaining(&t1));
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et1));
send_now = 1;
leds_on(LEDS_RED);
}
PROCESS_END();
}
PROCESS_THREAD(sensd_client_process, ev, data) {
PROCESS_BEGIN();
set_global_address();
print_local_addresses();
SENSORS_ACTIVATE(temp_sensor);
SENSORS_ACTIVATE(battery_sensor);
SENSORS_ACTIVATE(temp_mcu_sensor);
SENSORS_ACTIVATE(light_sensor);
SENSORS_ACTIVATE(pulse_sensor);
#ifdef CO2
SENSORS_ACTIVATE(co2_sa_kxx_sensor);
#endif
leds_init();
leds_on(LEDS_RED);
leds_on(LEDS_YELLOW);
printf("Starting TCP client on port=%d\n", PORT);
/* Set server address. typically sensd */
//uip_ip6addr(&addr, 0xfe80, 0, 0, 0, 0xfec2, 0x3d00, 1, 0x63ae);
//uip_ip6addr(&addr, 0x0000, 0, 0, 0, 0, 0xffff, 0xc0a8, 0x0201);
//uip_ip6addr(&addr, 0x0000, 0, 0, 0, 0, 0xffff, 0xc0a8, 0x0255);
uip_ip6addr(&addr, 0x0000, 0, 0, 0, 0, 0xffff, 0xc010, 0x7dea); //192.16.125.234
random_init(50);
while(1) {
/* Delay connection attempts */
timer_set(&t, 2*CLOCK_SECOND);
etimer_set(&et, timer_remaining(&t));
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
/* Time out teh actual connection attempt */
timer_set(&t, 10*CLOCK_SECOND);
printf("Connecting");
tcp_connect(&addr, UIP_HTONS(PORT), NULL);
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
if(uip_aborted() || uip_timedout() || uip_closed()) {
printf(" Failed\n");
} else if(uip_connected()) {
printf(" Success\n");
PSOCK_INIT(&ps, (uint8_t *)in_buffer, sizeof(in_buffer));
do {
handle_connection(&ps, clock_seconds());
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
} while(!(uip_closed() || uip_aborted() || uip_timedout()));
printf("Disconnected\n");
}
}
PROCESS_END();
}

View file

@ -0,0 +1,128 @@
/*
* Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB
* 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.
*
*
* Author : Robert Olsson robert@radio-sensors.com
* Created : 2015-12-28
*/
/**
* \file
* A simple TCP server for client app.
*/
#include <string.h>
#include "contiki-net.h"
#include "leds.h"
#define DEBUG DEBUG_PRINT
#include "uip-debug.h"
#define PORT 1236
static struct psock ps;
static uint8_t buf[120];
static int i;
static uint8_t state;
static void
print_local_addresses(void)
{
PRINTF("Server IPv6 addresses:\n\r");
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state;
if(uip_ds6_if.addr_list[i].isused &&
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
PRINTF("\n\r");
}
}
}
static void
set_global_address(void)
{
uip_ipaddr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
}
static
PT_THREAD(handle_connection(struct psock *p))
{
PSOCK_BEGIN(p);
//PSOCK_SEND_STR(p, "Type something!\n");
leds_on(LEDS_RED);
PSOCK_READTO(p, '\n');
printf("RX=%s", buf);
//PSOCK_SEND_STR(p, "Got: ");
//PSOCK_SEND(p, buf, PSOCK_DATALEN(p));
//PSOCK_SEND_STR(p, "EOL\r\n");
//PSOCK_CLOSE(p);
PSOCK_END(p);
}
PROCESS(server_process, "Server");
AUTOSTART_PROCESSES(&server_process);
PROCESS_THREAD(server_process, ev, data)
{
PROCESS_BEGIN();
set_global_address();
leds_init();
print_local_addresses();
printf("Starting TCP server on port=%d\n", PORT);
tcp_listen(UIP_HTONS(PORT));
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
if(uip_aborted() )
printf("TCP aborted\n");
if(uip_timedout() )
printf("TCP timeoutn\n");
if(uip_closed() )
printf("TCP closed\n");
if(uip_connected()) {
printf("TCP Connected\n\r");
PSOCK_INIT(&ps, buf, sizeof(buf));
while(!(uip_aborted() || uip_closed() || uip_timedout())) {
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
handle_connection(&ps);
}
}
}
PROCESS_END();
}