Merge branch 'contiki'

Conflicts:
	cpu/cc26xx-cc13xx/lib/cc13xxware
	cpu/cc26xx-cc13xx/lib/cc26xxware
This commit is contained in:
Harald Pichler 2017-01-31 15:00:59 +01:00
commit 2f8549aaae
319 changed files with 58114 additions and 6745 deletions

View file

@ -8,6 +8,7 @@ PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
PRINTF_LIB = $(PRINTF_LIB_FLT)
CLIBS = $(PRINTF_LIB)
MODULES += dev/bme280
CUSTOM_RULE_LINK = 1
%.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a

View file

@ -49,9 +49,8 @@
#include "dev/temp_mcu-sensor.h"
#include "dev/light-sensor.h"
#include "dev/pulse-sensor.h"
#ifdef CO2
#include "dev/bme280/bme280-sensor.h"
#include "dev/co2_sa_kxx-sensor.h"
#endif
/*---------------------------------------------------------------------------*/
PROCESS(hello_sensors_process, "Hello sensor process");
AUTOSTART_PROCESSES(&hello_sensors_process);
@ -80,9 +79,29 @@ read_values(void)
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));
if( i2c_probed & I2C_CO2SA ) {
printf(" CO2=%-d", co2_sa_kxx_sensor.value( CO2_SA_KXX_CO2));
}
if( i2c_probed & I2C_BME280 ) {
#if STD_API
printf(" BME280_TEMP=%-d", bme280_sensor.value(BME280_SENSOR_TEMP));
printf(" BME280_RH=%-d", bme280_sensor.value(BME280_SENSOR_HUMIDITY));
printf(" BME280_P=%-d", bme280_sensor.value(BME280_SENSOR_PRESSURE));
#else
/* Trigger burst read */
bme280_sensor.value(BME280_SENSOR_TEMP);
printf(" T_BME280=%5.2f", (double)bme280_mea.t_overscale100 / 100.);
printf(" RH_BME280=%5.2f", (double)bme280_mea.h_overscale1024 / 1024.);
#ifdef BME280_64BIT
printf(" P_BME280=%5.2f", (double)bme280_mea.p_overscale256 / 256.);
#else
printf(" P_BME280=%5.2f", (double)bme280_mea.p);
#endif
#endif
}
printf("\n");
}
/*---------------------------------------------------------------------------*/
@ -95,9 +114,14 @@ PROCESS_THREAD(hello_sensors_process, ev, data)
SENSORS_ACTIVATE(temp_mcu_sensor);
SENSORS_ACTIVATE(light_sensor);
SENSORS_ACTIVATE(pulse_sensor);
#ifdef CO2
SENSORS_ACTIVATE(co2_sa_kxx_sensor);
#endif
if( i2c_probed & I2C_BME280 ) {
SENSORS_ACTIVATE(bme280_sensor);
}
if( i2c_probed & I2C_CO2SA ) {
SENSORS_ACTIVATE(co2_sa_kxx_sensor);
}
leds_init();
leds_on(LEDS_RED);
leds_on(LEDS_YELLOW);

View file

@ -42,6 +42,8 @@
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
/* #define BME280_32BIT */
#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_MAC nullmac_driver

View file

@ -172,7 +172,7 @@ set_global_address(void)
{
uip_ipaddr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
@ -183,23 +183,23 @@ set_global_address(void)
*
* 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
* e.g. set Context 0 to fd00::. 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)
* (Setting Context 0 to fd00::1111:2222:3333:4444 will report a 16 bit
* compressed address of fd00::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);
uip_ip6addr(&server_ipaddr, UIP_DS6_DEFAULT_PREFIX, 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);
uip_ip6addr(&server_ipaddr, UIP_DS6_DEFAULT_PREFIX, 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 */
uip_ip6addr(&server_ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0x0250, 0xc2ff, 0xfea8, 0xcd1a); /* redbee-econotag */
#endif
/* Voravit Added */
/* PRINTF("VORAVIT CLIENT: SERVER IPv6 addresses: \n"); */

View file

@ -31,6 +31,7 @@
#include "contiki-lib.h"
#include "contiki-net.h"
#include "net/ip/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/rpl/rpl.h"
#include "net/netstack.h"
@ -227,21 +228,21 @@ PROCESS_THREAD(coap_server_process, ev, data)
* 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)
* (Setting Context 0 to fd00::1111:2222:3333:4444 will report a 16 bit
* compressed address of fd00::1111:22ff:fe33:xxxx)
* Note Wireshark's IPCMV6 checksum verification depends on the correct
* uncompressed addresses.
*/
#if 0
/* Mode 1 - 64 bits inline */
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 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);
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0x00ff, 0xfe00, 1);
#else
/* Mode 3 - derived from link local (MAC) address */
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
#endif
@ -250,7 +251,7 @@ PROCESS_THREAD(coap_server_process, ev, data)
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);
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
rpl_set_prefix(dag, &ipaddr, 64);
PRINTF("created a new RPL dag\n");
} else {

View file

@ -370,7 +370,7 @@ PROCESS_THREAD(border_router_process, ev, data)
NETSTACK_MAC.off(1);
/* Derived from link local (MAC) address */
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
set_prefix_64(&ipaddr);
print_local_addresses();

View file

@ -143,7 +143,7 @@ set_global_address(void)
{
uip_ipaddr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
@ -153,10 +153,10 @@ set_global_address(void)
*
* 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
* e.g. set Context 0 to fd00::. 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)
* (Setting Context 0 to fd00::1111:2222:3333:4444 will report a 16 bit
* compressed address of fd00::1111:22ff:fe33:xxxx)
*
* Note the IPCMV6 checksum verification depends on the correct uncompressed
* addresses.
@ -164,13 +164,13 @@ set_global_address(void)
#if 0
/* Mode 1 - 64 bits inline */
uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
uip_ip6addr(&server_ipaddr, UIP_DS6_DEFAULT_PREFIX, 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);
uip_ip6addr(&server_ipaddr, UIP_DS6_DEFAULT_PREFIX, 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
uip_ip6addr(&server_ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0x0250, 0xc2ff, 0xfea8, 0xcd1a); //redbee-econotag
#endif
}
/*---------------------------------------------------------------------------*/

View file

@ -31,6 +31,7 @@
#include "contiki-lib.h"
#include "contiki-net.h"
#include "net/ip/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/rpl/rpl.h"
#include "net/netstack.h"
@ -124,21 +125,21 @@ PROCESS_THREAD(udp_server_process, ev, data)
* 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)
* (Setting Context 0 to fd00::1111:2222:3333:4444 will report a 16 bit
* compressed address of fd00::1111:22ff:fe33:xxxx)
* Note Wireshark's IPCMV6 checksum verification depends on the correct
* uncompressed addresses.
*/
#if 0
/* Mode 1 - 64 bits inline */
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 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);
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0x00ff, 0xfe00, 1);
#else
/* Mode 3 - derived from link local (MAC) address */
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
#endif
@ -147,7 +148,7 @@ PROCESS_THREAD(udp_server_process, ev, data)
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);
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
rpl_set_prefix(dag, &ipaddr, 64);
PRINTF("created a new RPL dag\n");
} else {

View file

@ -118,7 +118,7 @@ static void
set_global_address(void)
{
uip_ipaddr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ip6addr(&ipaddr, 0xfd00, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
}

View file

@ -70,7 +70,7 @@ static void
set_global_address(void)
{
uip_ipaddr_t ipaddr;
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ip6addr(&ipaddr, 0xfd00, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
}

View file

@ -45,6 +45,6 @@
#define BUTTON_SENSOR_CONF_ON 1
#define UIP_CONF_ICMP6 1
#define RIMESTATS_CONF_ENABLED 1
#define UIP_CONF_ND6_SEND_NA 1
#define UIP_CONF_ND6_SEND_NS 1
#endif /* PROJECT_CONF_H_ */

View file

@ -1,5 +1,5 @@
DEFINES+=PROJECT_CONF_H=\"project-conf.h\"
CONTIKI_PROJECT = test-pwm timer-test
CONTIKI_PROJECT = test-pwm timer-test test-uart
all: $(CONTIKI_PROJECT)

View file

@ -50,7 +50,6 @@
#include "dev/watchdog.h"
#include "dev/sys-ctrl.h"
#include "pwm.h"
#include "systick.h"
#include "lpm.h"
#include "dev/ioc.h"
#include <stdio.h>

View file

@ -0,0 +1,110 @@
/*
* Copyright (c) 2016, Indian Institute of Science <http://www.iisc.ernet.in>
* 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.
*
*/
/**
* \addtogroup cc2538-examples
* @{
*
* \defgroup cc2538-test-uart Test the CC2538 UART
*
* Demonstrates the use of the CC2538 UART
*
* @{
*
* \file
* A quick program for testing the UART1 on the cc2538 based
* platform which can be used to interface with sensor with UART
* interface and to communicate with other development boards
* \author
* Akshay P M <akshaypm@ece.iisc.ernet.in>
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "sys/etimer.h"
#include "dev/leds.h"
#include "dev/uart.h"
#include "dev/serial-line.h"
#include <stdio.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
static struct etimer et;
/*---------------------------------------------------------------------------*/
PROCESS(cc2538_uart_demo_process, "cc2538 uart demo");
AUTOSTART_PROCESSES(&cc2538_uart_demo_process);
/*---------------------------------------------------------------------------*/
unsigned int
uart1_send_bytes(const unsigned char *s, unsigned int len)
{
unsigned int i = 0;
while(s && *s != 0) {
if(i >= len) {
break;
}
uart_write_byte(1, *s++);
i++;
}
return i;
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cc2538_uart_demo_process, ev, data)
{
char *rxdata;
static uint16_t count=0;
char string[20];
PROCESS_BEGIN();
uart_set_input(1, serial_line_input_byte);
etimer_set(&et, CLOCK_SECOND * 4);
leds_toggle(LEDS_GREEN);
while(1) {
PROCESS_WAIT_UNTIL(etimer_expired(&et));
sprintf(string, "sending string %u.\n", ++count);
uart1_send_bytes((uint8_t *)string, sizeof(string) - 1);
etimer_reset(&et);
printf("string is being sent\n");
PROCESS_YIELD();
if(ev == serial_line_event_message) {
leds_toggle(LEDS_RED);
rxdata = data;
printf("Data received over UART %s\n", rxdata);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -152,7 +152,7 @@ PROCESS_THREAD(cc2538_demo_process, ev, data)
} else if(data == &button_left_sensor || data == &button_right_sensor) {
leds_toggle(LEDS_BUTTON);
} else if(data == &button_down_sensor) {
cpu_cpsid();
INTERRUPTS_DISABLE();
leds_on(LEDS_REBOOT);
watchdog_reboot();
} else if(data == &button_up_sensor) {

View file

@ -4,5 +4,5 @@ all: $(CONTIKI_PROJECT)
CONTIKI = ../../..
CONTIKI_WITH_IPV6 = 1
CFLAGS += -DUIP_CONF_ND6_SEND_NA=1
CFLAGS += -DUIP_CONF_ND6_SEND_NS=1
include $(CONTIKI)/Makefile.include

View file

@ -96,13 +96,10 @@
#undef COAP_PROXY_OPTION_PROCESSING
#define COAP_PROXY_OPTION_PROCESSING 0
/* Turn of DAO ACK to make code smaller */
/* Turn off DAO ACK to make code smaller */
#undef RPL_CONF_WITH_DAO_ACK
#define RPL_CONF_WITH_DAO_ACK 0
#undef RPL_CONF_OF
#define RPL_CONF_OF rpl_of0
/* Enable client-side support for COAP observe */
#define COAP_OBSERVE_CLIENT 1
#endif /* __PROJECT_ERBIUM_CONF_H__ */

12
examples/fat/Makefile Normal file
View file

@ -0,0 +1,12 @@
DEFINES+=PROJECT_CONF_H=\"project-conf.h\"
CONTIKI = ../..
all: example-fat
CONTIKI_WITH_RIME = 1
ifeq ($(TARGET), zoul)
BOARD ?= remote-revb
endif
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,2 @@
TARGET = zoul
BOARD ?= remote-revb

6
examples/fat/README.md Normal file
View file

@ -0,0 +1,6 @@
FAT File System Example
=======================
Supported Hardware (tested or known to work)
--------------------------------------------
* Zoul: RE-Mote revision B

View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 2016, Benoît Thébaudeau <benoit@wsystem.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.
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* Example demonstrating how to use the FAT file system.
*/
/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include "contiki.h"
#include "ff.h"
/*---------------------------------------------------------------------------*/
PROCESS(example_fat_process, "FAT example");
AUTOSTART_PROCESSES(&example_fat_process);
/*---------------------------------------------------------------------------*/
#define TEST_FILENAME "test.txt"
#define TEST_LINE "Hello world!"
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_fat_process, ev, data)
{
static FATFS FatFs; /* Work area (file system object) for logical drive */
FIL fil; /* File object */
char line[82]; /* Line buffer */
FRESULT fr; /* FatFs return code */
PROCESS_BEGIN();
printf("FAT example\n");
/* Register work area to the default drive */
f_mount(&FatFs, "", 0);
printf("Writing \"%s\" to \"%s\"\n", TEST_LINE, TEST_FILENAME);
/* Create the test file */
fr = f_open(&fil, TEST_FILENAME, FA_WRITE | FA_CREATE_ALWAYS);
if(fr) {
printf("f_open() error: %d\n", fr);
PROCESS_EXIT();
}
/* Write the test line */
f_printf(&fil, "%s\n", TEST_LINE);
/* Close the file */
f_close(&fil);
printf("Reading back \"%s\":\n\n", TEST_FILENAME);
/* Open the test file */
fr = f_open(&fil, TEST_FILENAME, FA_READ);
if(fr) {
printf("f_open() error: %d\n", fr);
PROCESS_EXIT();
}
/* Read all the lines and display them */
while(f_gets(line, sizeof(line), &fil)) {
printf(line);
}
/* Close the file */
f_close(&fil);
printf("\nDone\n");
PROCESS_END();
}

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2016, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.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 PROJECT_CONF_H_
#define PROJECT_CONF_H_
/*---------------------------------------------------------------------------*/
#if CONTIKI_TARGET_ZOUL
#define RTC_CONF_INIT 1
#define RTC_CONF_SET_FROM_SYS 1
#endif
#endif /* PROJECT_CONF_H_ */
/*---------------------------------------------------------------------------*/

View file

@ -179,7 +179,7 @@ PROCESS_THREAD(udp_server_process, ev, data)
if(ev == tcpip_event) {
tcpip_handler();
} else if (ev == sensors_event && data == &button_sensor) {
PRINTF("Initiaing global repair\n");
PRINTF("Initiating global repair\n");
rpl_repair_root(RPL_DEFAULT_INSTANCE);
}
}

View file

@ -120,17 +120,20 @@ print_network_status(void)
PRINTF("- Routing links (%u in total):\n", rpl_ns_num_nodes());
link = rpl_ns_node_head();
while(link != NULL) {
if(link->parent != NULL) {
uip_ipaddr_t child_ipaddr;
uip_ipaddr_t parent_ipaddr;
rpl_ns_get_node_global_addr(&child_ipaddr, link);
rpl_ns_get_node_global_addr(&parent_ipaddr, link->parent);
PRINTF("-- ");
PRINT6ADDR(&child_ipaddr);
uip_ipaddr_t child_ipaddr;
uip_ipaddr_t parent_ipaddr;
rpl_ns_get_node_global_addr(&child_ipaddr, link);
rpl_ns_get_node_global_addr(&parent_ipaddr, link->parent);
PRINTF("-- ");
PRINT6ADDR(&child_ipaddr);
if(link->parent == NULL) {
memset(&parent_ipaddr, 0, sizeof(parent_ipaddr));
PRINTF(" --- DODAG root ");
} else {
PRINTF(" to ");
PRINT6ADDR(&parent_ipaddr);
PRINTF(" (lifetime: %lu seconds)\n", (unsigned long)link->lifetime);
}
PRINTF(" (lifetime: %lu seconds)\n", (unsigned long)link->lifetime);
link = rpl_ns_node_next(link);
}
#endif
@ -170,15 +173,21 @@ PROCESS_THREAD(node_process, ev, data)
static enum { role_6ln, role_6dr, role_6dr_sec } node_role;
node_role = role_6ln;
int coordinator_candidate = 0;
#ifdef CONTIKI_TARGET_Z1
/* Set node with MAC address c1:0c:00:00:00:00:01 as coordinator,
* convenient in cooja for regression tests using z1 nodes
* */
#ifdef CONTIKI_TARGET_Z1
extern unsigned char node_mac[8];
unsigned char coordinator_mac[8] = { 0xc1, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
if(memcmp(node_mac, coordinator_mac, 8) == 0) {
coordinator_candidate = (memcmp(node_mac, coordinator_mac, 8) == 0);
#elif CONTIKI_TARGET_COOJA
coordinator_candidate = (node_id == 1);
#endif
if(coordinator_candidate) {
if(LLSEC802154_ENABLED) {
node_role = role_6dr_sec;
} else {
@ -187,7 +196,6 @@ PROCESS_THREAD(node_process, ev, data)
} else {
node_role = role_6ln;
}
#endif
#if CONFIG_VIA_BUTTON
{

View file

@ -155,8 +155,8 @@
#define RPL_NS_CONF_LINK_NUM 8
#undef NBR_TABLE_CONF_MAX_NEIGHBORS
#define NBR_TABLE_CONF_MAX_NEIGHBORS 8
#undef UIP_CONF_ND6_SEND_NA
#define UIP_CONF_ND6_SEND_NA 0
#undef UIP_CONF_ND6_SEND_NS
#define UIP_CONF_ND6_SEND_NS 0
#undef SICSLOWPAN_CONF_FRAG
#define SICSLOWPAN_CONF_FRAG 0
@ -181,4 +181,8 @@
#endif /* CONTIKI_TARGET_CC2538DK || CONTIKI_TARGET_ZOUL \
|| CONTIKI_TARGET_OPENMOTE_CC2538 */
#if CONTIKI_TARGET_COOJA
#define COOJA_CONF_SIMULATE_TURNAROUND 0
#endif /* CONTIKI_TARGET_COOJA */
#endif /* __PROJECT_CONF_H__ */

View file

@ -0,0 +1,279 @@
<?xml version="1.0" encoding="UTF-8"?>
<simconf>
<project EXPORT="discard">[APPS_DIR]/mrm</project>
<project EXPORT="discard">[APPS_DIR]/mspsim</project>
<project EXPORT="discard">[APPS_DIR]/avrora</project>
<project EXPORT="discard">[APPS_DIR]/serial_socket</project>
<project EXPORT="discard">[APPS_DIR]/collect-view</project>
<project EXPORT="discard">[APPS_DIR]/powertracker</project>
<project EXPORT="discard">[APPS_DIR]/radiologger-headless</project>
<simulation>
<title>RPL+TSCH</title>
<randomseed>123456</randomseed>
<motedelay_us>1000000</motedelay_us>
<radiomedium>
org.contikios.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>
org.contikios.cooja.contikimote.ContikiMoteType
<identifier>mtype660</identifier>
<description>Cooja Mote Type #z11</description>
<source>[CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.c</source>
<commands>make TARGET=cooja clean
make TARGET=cooja node.cooja</commands>
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.Battery</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiVib</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiMoteID</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiRS232</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiBeeper</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiIPAddress</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiRadio</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiButton</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiPIR</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiClock</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiLED</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiCFS</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
<symbols>false</symbols>
</motetype>
<mote>
<interface_config>
org.contikios.cooja.interfaces.Position
<x>-1.285769821276336</x>
<y>38.58045647334346</y>
<z>0.0</z>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
<id>1</id>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiRadio
<bitrate>250.0</bitrate>
</interface_config>
<motetype_identifier>mtype660</motetype_identifier>
</mote>
<mote>
<interface_config>
org.contikios.cooja.interfaces.Position
<x>-19.324109516886306</x>
<y>76.23135780254927</y>
<z>0.0</z>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
<id>2</id>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiRadio
<bitrate>250.0</bitrate>
</interface_config>
<motetype_identifier>mtype660</motetype_identifier>
</mote>
<mote>
<interface_config>
org.contikios.cooja.interfaces.Position
<x>5.815501305791592</x>
<y>76.77463755494317</y>
<z>0.0</z>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
<id>3</id>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiRadio
<bitrate>250.0</bitrate>
</interface_config>
<motetype_identifier>mtype660</motetype_identifier>
</mote>
<mote>
<interface_config>
org.contikios.cooja.interfaces.Position
<x>31.920697784030082</x>
<y>50.5212265977149</y>
<z>0.0</z>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
<id>4</id>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiRadio
<bitrate>250.0</bitrate>
</interface_config>
<motetype_identifier>mtype660</motetype_identifier>
</mote>
<mote>
<interface_config>
org.contikios.cooja.interfaces.Position
<x>47.21747673247198</x>
<y>30.217765340599726</y>
<z>0.0</z>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
<id>5</id>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiRadio
<bitrate>250.0</bitrate>
</interface_config>
<motetype_identifier>mtype660</motetype_identifier>
</mote>
<mote>
<interface_config>
org.contikios.cooja.interfaces.Position
<x>10.622284947035123</x>
<y>109.81862399725188</y>
<z>0.0</z>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
<id>6</id>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiRadio
<bitrate>250.0</bitrate>
</interface_config>
<motetype_identifier>mtype660</motetype_identifier>
</mote>
<mote>
<interface_config>
org.contikios.cooja.interfaces.Position
<x>52.41150716335335</x>
<y>109.93228340481916</y>
<z>0.0</z>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
<id>7</id>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiRadio
<bitrate>250.0</bitrate>
</interface_config>
<motetype_identifier>mtype660</motetype_identifier>
</mote>
<mote>
<interface_config>
org.contikios.cooja.interfaces.Position
<x>70.18727461718498</x>
<y>70.06861701541145</y>
<z>0.0</z>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
<id>8</id>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiRadio
<bitrate>250.0</bitrate>
</interface_config>
<motetype_identifier>mtype660</motetype_identifier>
</mote>
<mote>
<interface_config>
org.contikios.cooja.interfaces.Position
<x>80.29870484201041</x>
<y>99.37351603835938</y>
<z>0.0</z>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
<id>9</id>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiRadio
<bitrate>250.0</bitrate>
</interface_config>
<motetype_identifier>mtype660</motetype_identifier>
</mote>
</simulation>
<plugin>
org.contikios.cooja.plugins.SimControl
<width>242</width>
<z>4</z>
<height>160</height>
<location_x>11</location_x>
<location_y>241</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.Visualizer
<plugin_config>
<moterelations>true</moterelations>
<skin>org.contikios.cooja.plugins.skins.IDVisualizerSkin</skin>
<skin>org.contikios.cooja.plugins.skins.GridVisualizerSkin</skin>
<skin>org.contikios.cooja.plugins.skins.TrafficVisualizerSkin</skin>
<skin>org.contikios.cooja.plugins.skins.UDGMVisualizerSkin</skin>
<viewport>1.7405603810040515 0.0 0.0 1.7405603810040515 47.95980153208088 -42.576134155447555</viewport>
</plugin_config>
<width>236</width>
<z>3</z>
<height>230</height>
<location_x>1</location_x>
<location_y>1</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.LogListener
<plugin_config>
<filter />
<formatted_time />
<coloring />
</plugin_config>
<width>1031</width>
<z>0</z>
<height>394</height>
<location_x>273</location_x>
<location_y>6</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.TimeLine
<plugin_config>
<mote>0</mote>
<mote>1</mote>
<mote>2</mote>
<mote>3</mote>
<mote>4</mote>
<mote>5</mote>
<mote>6</mote>
<mote>7</mote>
<mote>8</mote>
<showRadioRXTX />
<showRadioHW />
<showLEDs />
<zoomfactor>16529.88882215865</zoomfactor>
</plugin_config>
<width>1304</width>
<z>2</z>
<height>311</height>
<location_x>0</location_x>
<location_y>412</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.RadioLogger
<plugin_config>
<split>150</split>
<formatted_time />
<showdups>false</showdups>
<hidenodests>false</hidenodests>
<analyzers name="6lowpan-pcap" />
</plugin_config>
<width>500</width>
<z>1</z>
<height>300</height>
<location_x>30</location_x>
<location_y>442</location_y>
</plugin>
</simconf>

View file

@ -40,9 +40,7 @@
#include <stdio.h>
#include <string.h>
/* Only for TMOTE Sky? */
#include "dev/serial-line.h"
#include "dev/uart1.h"
#include "net/ipv6/uip-ds6-route.h"
#define UDP_CLIENT_PORT 8765
@ -204,11 +202,6 @@ PROCESS_THREAD(udp_client_process, ev, data)
PRINTF(" local/remote port %u/%u\n",
UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));
/* initialize serial line */
uart1_set_input(serial_line_input_byte);
serial_line_init();
#if WITH_COMPOWER
powertrace_sniff(POWERTRACE_ON);
#endif

View file

@ -116,9 +116,9 @@
#define RPL_CONF_MAX_INSTANCES 1 /* default 1 */
#define RPL_CONF_MAX_DAG_PER_INSTANCE 1 /* default 2 */
/* No RA, No NA */
#undef UIP_CONF_ND6_SEND_NA
#define UIP_CONF_ND6_SEND_NA 0
/* No RA, No NS */
#undef UIP_CONF_ND6_SEND_NS
#define UIP_CONF_ND6_SEND_NS 0
#undef UIP_CONF_ND6_SEND_RA
#define UIP_CONF_ND6_SEND_RA 0

View file

@ -201,7 +201,7 @@ PROCESS_THREAD(node_process, ev, data)
if (host_found) {
/* Make sample count dependent on asn. After a disconnect, waveforms remain
synchronous. Use node_mac to create phase offset between waveforms in different nodes */
sample_count = ((current_asn.ls4b/((1000/(TSCH_CONF_DEFAULT_TIMESLOT_LENGTH/1000)))/INTERVAL)+node_mac[7]) % (SIZE_OF_WAVEFORM-1);
sample_count = ((tsch_current_asn.ls4b/((1000/(TSCH_CONF_DEFAULT_TIMESLOT_LENGTH/1000)))/INTERVAL)+node_mac[7]) % (SIZE_OF_WAVEFORM-1);
printf("%d sec. waveform=%s. cnt=%d. value=%d\n", total_time, waveform_table[selected_waveform].str, sample_count, waveform_table[selected_waveform].table[sample_count]);
my_sprintf(udp_buf, waveform_table[selected_waveform].table[sample_count]);
uip_udp_packet_send(udp_conn_tx, udp_buf, strlen(udp_buf));

View file

@ -85,4 +85,9 @@
#undef TSCH_LOG_CONF_ID_FROM_LINKADDR
#define TSCH_LOG_CONF_ID_FROM_LINKADDR(addr) ((addr) ? (addr)->u8[LINKADDR_SIZE - 2] : 0)
#if CONTIKI_TARGET_COOJA
#define COOJA_CONF_SIMULATE_TURNAROUND 0
#endif /* CONTIKI_TARGET_COOJA */
#endif /* __PROJECT_CONF_H__ */

View file

@ -58,10 +58,10 @@ static void
recv(const linkaddr_t *originator, uint8_t seqno, uint8_t hops)
{
printf("Sink got message from %d.%d, seqno %d, hops %d: len %d '%s'\n",
originator->u8[0], originator->u8[1],
seqno, hops,
packetbuf_datalen(),
(char *)packetbuf_dataptr());
originator->u8[0], originator->u8[1],
seqno, hops,
packetbuf_datalen(),
(char *)packetbuf_dataptr());
}
/*---------------------------------------------------------------------------*/
static const struct collect_callbacks callbacks = { recv };
@ -70,15 +70,15 @@ PROCESS_THREAD(example_collect_process, ev, data)
{
static struct etimer periodic;
static struct etimer et;
PROCESS_BEGIN();
collect_open(&tc, 130, COLLECT_ROUTER, &callbacks);
if(linkaddr_node_addr.u8[0] == 1 &&
linkaddr_node_addr.u8[1] == 0) {
printf("I am sink\n");
collect_set_sink(&tc, 1);
printf("I am sink\n");
collect_set_sink(&tc, 1);
}
/* Allow some time for the network to settle. */
@ -88,22 +88,19 @@ PROCESS_THREAD(example_collect_process, ev, data)
while(1) {
/* Send a packet every 30 seconds. */
if(etimer_expired(&periodic)) {
etimer_set(&periodic, CLOCK_SECOND * 30);
etimer_set(&et, random_rand() % (CLOCK_SECOND * 30));
}
etimer_set(&periodic, CLOCK_SECOND * 30);
etimer_set(&et, random_rand() % (CLOCK_SECOND * 30));
PROCESS_WAIT_EVENT();
PROCESS_WAIT_UNTIL(etimer_expired(&et));
if(etimer_expired(&et)) {
{
static linkaddr_t oldparent;
const linkaddr_t *parent;
printf("Sending\n");
packetbuf_clear();
packetbuf_set_datalen(sprintf(packetbuf_dataptr(),
"%s", "Hello") + 1);
"%s", "Hello") + 1);
collect_send(&tc, 15);
parent = collect_parent(&tc);
@ -118,6 +115,7 @@ PROCESS_THREAD(example_collect_process, ev, data)
}
}
PROCESS_WAIT_UNTIL(etimer_expired(&periodic));
}
PROCESS_END();

View file

@ -23,3 +23,23 @@ all: $(CONTIKI_PROJECT)
CONTIKI = ../..
include $(CONTIKI)/Makefile.include
PYTHON ?= python
SENSNIFF = $(CONTIKI)/tools/sensniff/sensniff.py
ifeq ($(BAUDRATE),)
BAUDRATE = 460800
endif
SENSNIFF_FLAGS += -b $(BAUDRATE)
ifneq ($(PORT),)
SENSNIFF_FLAGS += -d $(PORT)
endif
sniff:
ifeq ($(wildcard $(SENSNIFF)), )
$(error Could not find the sensniff script. Did you run 'git submodule update --init' ?")
else
$(PYTHON) $(SENSNIFF) $(SENSNIFF_FLAGS)
endif

View file

@ -11,6 +11,12 @@ Running
* Run sensniff on your host
* Fire up wireshark and enjoy.
You can run sensniff manually, or you can simply run `make sniff` from within
this directory. If you choose the latter option, you may have to specify the
port where you device is connected by using the PORT variable. For example, if
your device is connected to `/dev/ttyUSB1` then you should run
`make PORT=/dev/ttyUSB1 sniff`.
Make sure your device's UART baud rate matches the `-b` argument passed to
sensniff. I strongly recommend using at least 460800. This comment does not
apply if your device is using native USB.
@ -44,7 +50,7 @@ The following radios have been tested:
* CC2530/CC2531
* CC1200
One you have the radio sorted out, you also need to configure character I/O.
Once you have the radio sorted out, you also need to configure character I/O.
The firmware captures wireless frames and streams them over a serial line to
the host where your device is connected. This can be achieved over UART or over
CDC-ACM. The example makes zero assumptions about your hardware's capability,
@ -79,5 +85,12 @@ and:
#define SENSNIFF_IO_DRIVER_H "header-with-my-own-defines.h"
* The build system will also try to include `platform/Makefile.platform`. You
can create this Makefile if you want to extend the build system e.g. by adding
source files to the build, or by specifying Make variables. A common reason why
you may wish to do so would be to specify your device's baudrate. In doing so,
`make sniff` will pass the correct value as the argument to `-b`. You do not
have to create this file if you don't need to do so.
That should be it!

View file

@ -46,6 +46,8 @@
/*---------------------------------------------------------------------------*/
#if CC2538_IO_CONF_USB
#define USB_SERIAL_CONF_ENABLE 1
#else
#define UART0_CONF_BAUD_RATE 460800
#endif
/*---------------------------------------------------------------------------*/
#define SENSNIFF_IO_DRIVER_H "pool/cc2538-io.h"

View file

@ -0,0 +1 @@
BAUDRATE = 1000000

View file

@ -2,5 +2,5 @@ all: udp-server udp-client
CONTIKI = ../..
CONTIKI_WITH_IPV6 = 1
CFLAGS += -DUIP_CONF_ND6_SEND_NA=1
CFLAGS += -DUIP_CONF_ND6_SEND_NS=1
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,6 @@
all: websocket-example
CONTIKI=../..
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,6 @@
install:
npm install websocket
run:
nodejs example-server.js

View file

@ -0,0 +1,57 @@
"use strict";
var serverPort = 8080;
var websocket = require('websocket').server;
var http = require('http');
var server = http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('This is a websocket server, not intended for http\n');
response.end();
});
server.listen(serverPort, function() {
console.log('Server is listening on port ' + serverPort);
});
var wsServer = new websocket({
httpServer: server
});
var connections = [];
function broadcastMessage(message) {
for (var i = 0; i < connections.length; i++) {
connections[i].sendUTF(message);
}
}
wsServer.on('request', function(request) {
/* Save the connection */
var connection = request.accept(null, request.origin);
/* Store the connection in the list of connections */
var connectionIndex = connections.push(connection) - 1;
console.log('Connection from ' + connection.remoteAddress + '.');
broadcastMessage('Connection from ' + connection.remoteAddress + '.');
connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log((new Date()) + ' Message received: ' +
message.utf8Data);
broadcastMessage(message.utf8Data);
}
});
// user disconnected
connection.on('close', function(connection) {
console.log((new Date()) + ' Connection lost: ' +
connection.remoteAddress);
connections.splice(connectionIndex, 1);
});
});

View file

@ -0,0 +1,93 @@
/*
* Copyright (c) 2012, 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 "websocket.h"
#include <stdio.h>
static struct websocket s;
static void callback(struct websocket *s, websocket_result_t r,
const uint8_t *data, uint16_t datalen);
#define RECONNECT_INTERVAL 10 * CLOCK_SECOND
static struct ctimer reconnect_timer;
/*---------------------------------------------------------------------------*/
PROCESS(websocket_example_process, "Websocket Example");
AUTOSTART_PROCESSES(&websocket_example_process);
/*---------------------------------------------------------------------------*/
static void
reconnect_callback(void *ptr)
{
websocket_open(&s, "ws://172.16.0.1:8080/",
"contiki", NULL, callback);
}
/*---------------------------------------------------------------------------*/
static void
callback(struct websocket *s, websocket_result_t r,
const uint8_t *data, uint16_t datalen)
{
if(r == WEBSOCKET_CLOSED ||
r == WEBSOCKET_RESET ||
r == WEBSOCKET_HOSTNAME_NOT_FOUND ||
r == WEBSOCKET_TIMEDOUT) {
ctimer_set(&reconnect_timer, RECONNECT_INTERVAL, reconnect_callback, s);
} else if(r == WEBSOCKET_CONNECTED) {
websocket_send_str(s, "Connected");
} else if(r == WEBSOCKET_DATA) {
printf("websocket-example: Received data '%.*s' (len %d)\n", datalen,
data, datalen);
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(websocket_example_process, ev, data)
{
static struct etimer et;
PROCESS_BEGIN();
ctimer_set(&reconnect_timer, RECONNECT_INTERVAL, reconnect_callback, &s);
websocket_init(&s);
while(1) {
etimer_set(&et, CLOCK_SECOND / 8);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
char buf[] = "012345678";
static int count;
buf[0] = (count % 9) + '0';
count++;
websocket_send_str(&s, buf);
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -5,12 +5,15 @@ CONTIKI_PROJECT += test-bmp085-bmp180 test-motion test-rotation-sensor
CONTIKI_PROJECT += test-grove-light-sensor test-grove-loudness-sensor
CONTIKI_PROJECT += test-weather-meter test-grove-gyro test-lcd test-iaq
CONTIKI_PROJECT += test-pm10-sensor test-vac-sensor test-aac-sensor
CONTIKI_PROJECT += test-zonik test-dht22.c test-ac-dimmer.c
CONTIKI_PROJECT += test-zonik test-dht22.c test-ac-dimmer.c test-servo.c
CONTIKI_PROJECT += test-bme280
CONTIKI_TARGET_SOURCEFILES += tsl256x.c sht25.c bmpx8x.c motion-sensor.c
CONTIKI_TARGET_SOURCEFILES += adc-sensors.c weather-meter.c grove-gyro.c
CONTIKI_TARGET_SOURCEFILES += rgb-bl-lcd.c pm10-sensor.c iaq.c zonik.c relay.c
CONTIKI_TARGET_SOURCEFILES += dht22.c servo.c ac-dimmer.c
CONTIKI_TARGET_SOURCEFILES += dht22.c servo.c ac-dimmer.c bme280-arch.c
MODULES += /dev/bme280
all: $(CONTIKI_PROJECT)

View file

@ -46,7 +46,7 @@ As above to specify a given port use the `PORT=/dev/ttyUSB0` argument.
Alternatively you can save the above `PORT`, `TARGET` or `BOARD` as follows:
`export BOARD=/dev/ttyUSB0`
`export TARGET=zoul BOARD=remote-revb PORT=/dev/ttyUSB0`
This will save you to type these when running a command on the terminal

View file

@ -0,0 +1,56 @@
RE-Mote IP64 README file
========================
This example shows how to use the Zolertia's Orion Ethernet router, based on the Zoul and ENC28J60 modules, with active POE support.
IP64 router
-----------------
The router packs a built-in webserver and optionally can run on 2.4GHz or with the Sub-1GHz radio interface. In the `project-conf.h` file you can alternatively enable one or another as follows:
* RF 2.4GHz (cc2538 built-in)
````
#define NETSTACK_CONF_RADIO cc2538_rf_driver
#define ANTENNA_SW_SELECT_DEF_CONF ANTENNA_SW_SELECT_2_4GHZ
````
* RF Sub-1GHz (CC1200)
````
#define NETSTACK_CONF_RADIO cc1200_driver
#define ANTENNA_SW_SELECT_DEF_CONF ANTENNA_SW_SELECT_SUBGHZ
````
To compile and flash run:
````
cd ip64-router
make TARGET=zoul BOARD=router ip64-router.upload
````
As default we enable the `DHCP` support for autoconfiguration. Just connect to a DHCP-enabled device to obtain an IPv4 IP address and that's it!.
HTTP client examples
-----------------
There are available 2 examples ready to use using the `http-socket` library:
* The `client` example just makes a HTTP `GET` request to a know page and retrieves
the result.
* The `ifttt-client` example sends a HTTP `POST` request to [IFTTT](https://ifttt.com/recipes) whenever the user button is pressed, building an Internet button to connect to several channels and applications, such as `Drive`, `Evernote` and many others.
To configure the `IFTTT` demo just edit the `project-conf.h` file and change the name of the event and write your API key:
````
#define IFTTT_EVENT "button"
#define IFTTT_KEY "XXXXXX"
````
To compile and flash:
````
cd client
make TARGET=zoul ifttt-client.upload
````

View file

@ -0,0 +1,12 @@
CFLAGS+=-DPROJECT_CONF_H=\"project-conf.h\"
CONTIKI_PROJECT = client ifttt_client
all: $(CONTIKI_PROJECT)
BOARD = orion
MODULES += core/net/http-socket
WITH_IP64 = 1
CONTIKI = ../../../../..
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,139 @@
/*
* Copyright (c) 2016, Zolertia - http://www.zolertia.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-net.h"
#include "http-socket.h"
#include "ip64-addr.h"
#include "dev/leds.h"
#include "rpl.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
static struct http_socket s;
static char data_received[HTTP_CLIENT_BUFFER_LEN];
static int bytes_received = 0;
static int restarts;
static struct ctimer reconnect_timer;
static const char *url = "http://httpbin.org/ip";
/*---------------------------------------------------------------------------*/
static void callback(struct http_socket *s, void *ptr,
http_socket_event_t e,
const uint8_t *data, uint16_t datalen);
/*---------------------------------------------------------------------------*/
PROCESS(http_example_process, "HTTP Example");
AUTOSTART_PROCESSES(&http_example_process);
/*---------------------------------------------------------------------------*/
static void
reconnect(void *dummy)
{
rpl_set_mode(RPL_MODE_MESH);
http_socket_get(&s, url, 0, 0, callback, NULL);
}
/*---------------------------------------------------------------------------*/
static void
restart(void)
{
int scale;
restarts++;
printf("Number of restarts %d\n", restarts);
scale = restarts;
if(scale > 5) {
scale = 5;
}
ctimer_set(&reconnect_timer, random_rand() % ((CLOCK_SECOND * 10) << scale),
reconnect, NULL);
}
/*---------------------------------------------------------------------------*/
static void
callback(struct http_socket *s, void *ptr,
http_socket_event_t e,
const uint8_t *data, uint16_t datalen)
{
uint8_t i;
if(e == HTTP_SOCKET_ERR) {
printf("HTTP socket error\n");
} else if(e == HTTP_SOCKET_TIMEDOUT) {
printf("HTTP socket error: timed out\n");
restart();
} else if(e == HTTP_SOCKET_ABORTED) {
printf("HTTP socket error: aborted\n");
restart();
} else if(e == HTTP_SOCKET_HOSTNAME_NOT_FOUND) {
printf("HTTP socket error: hostname not found\n");
restart();
} else if(e == HTTP_SOCKET_CLOSED) {
if(bytes_received) {
printf("HTTP socket received data:\n\n");
for(i=0; i<bytes_received; i++) {
printf("%c", data_received[i]);
}
printf("\n");
bytes_received = 0;
}
} else if(e == HTTP_SOCKET_DATA) {
strcat(data_received, (const char *)data);
bytes_received += datalen;
printf("HTTP socket received %d bytes of data\n", datalen);
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(http_example_process, ev, data)
{
static struct etimer et;
uip_ip4addr_t ip4addr;
uip_ip6addr_t ip6addr;
PROCESS_BEGIN();
uip_ipaddr(&ip4addr, 8, 8, 8, 8);
ip64_addr_4to6(&ip4addr, &ip6addr);
uip_nameserver_update(&ip6addr, UIP_NAMESERVER_INFINITE_LIFETIME);
etimer_set(&et, CLOCK_SECOND * 20);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
http_socket_init(&s);
http_socket_get(&s, url, 0, 0, callback, NULL);
leds_on(LEDS_RED);
restarts = 0;
etimer_set(&et, CLOCK_SECOND);
while(1) {
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
etimer_reset(&et);
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,154 @@
/*
* Copyright (c) 2016, Zolertia - http://www.zolertia.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-net.h"
#include "http-socket.h"
#include "ip64-addr.h"
#include "dev/leds.h"
#include "rpl.h"
#include "dev/button-sensor.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
static struct http_socket s;
static char data_received[HTTP_CLIENT_BUFFER_LEN];
static char url_buffer[HTTP_CLIENT_BUFFER_LEN];
static int bytes_received = 0;
static int restarts;
static struct ctimer reconnect_timer;
/*---------------------------------------------------------------------------*/
static void callback(struct http_socket *s, void *ptr,
http_socket_event_t e,
const uint8_t *data, uint16_t datalen);
/*---------------------------------------------------------------------------*/
PROCESS(http_example_process, "IFTTT HTTP Example");
AUTOSTART_PROCESSES(&http_example_process);
/*---------------------------------------------------------------------------*/
static void
reconnect(void *dummy)
{
rpl_set_mode(RPL_MODE_MESH);
leds_on(LEDS_GREEN);
http_socket_post(&s, url_buffer, NULL, 0, NULL, callback, NULL);
}
/*---------------------------------------------------------------------------*/
static void
restart(void)
{
int scale;
restarts++;
printf("Number of restarts %d\n", restarts);
leds_off(LEDS_GREEN);
scale = restarts;
if(scale > 5) {
scale = 5;
}
ctimer_set(&reconnect_timer, random_rand() % ((CLOCK_SECOND * 10) << scale),
reconnect, NULL);
}
/*---------------------------------------------------------------------------*/
static void
callback(struct http_socket *s, void *ptr,
http_socket_event_t e,
const uint8_t *data, uint16_t datalen)
{
uint8_t i;
if(e == HTTP_SOCKET_ERR) {
printf("HTTP socket error\n");
} else if(e == HTTP_SOCKET_TIMEDOUT) {
printf("HTTP socket error: timed out\n");
restart();
} else if(e == HTTP_SOCKET_ABORTED) {
printf("HTTP socket error: aborted\n");
restart();
} else if(e == HTTP_SOCKET_HOSTNAME_NOT_FOUND) {
printf("HTTP socket error: hostname not found\n");
restart();
} else if(e == HTTP_SOCKET_CLOSED) {
if(bytes_received) {
printf("HTTP socket received data:\n\n");
for(i=0; i<bytes_received; i++) {
printf("%c", data_received[i]);
}
printf("\n");
bytes_received = 0;
leds_off(LEDS_GREEN);
}
} else if(e == HTTP_SOCKET_DATA) {
strcat(data_received, (const char *)data);
bytes_received += datalen;
printf("HTTP socket received %d bytes of data\n", datalen);
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(http_example_process, ev, data)
{
static struct etimer et;
uip_ip4addr_t ip4addr;
uip_ip6addr_t ip6addr;
PROCESS_BEGIN();
uip_ipaddr(&ip4addr, 8, 8, 8, 8);
ip64_addr_4to6(&ip4addr, &ip6addr);
uip_nameserver_update(&ip6addr, UIP_NAMESERVER_INFINITE_LIFETIME);
etimer_set(&et, CLOCK_SECOND * 20);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
memset(url_buffer, 0, HTTP_CLIENT_BUFFER_LEN);
snprintf(url_buffer, HTTP_CLIENT_BUFFER_LEN,
"http://maker.ifttt.com/trigger/%s/with/key/%s",
IFTTT_EVENT, IFTTT_KEY);
http_socket_init(&s);
restarts = 0;
while(1) {
PROCESS_YIELD();
if((ev == sensors_event) && (data == &button_sensor)) {
if(button_sensor.value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) ==
BUTTON_SENSOR_PRESSED_LEVEL) {
leds_on(LEDS_GREEN);
printf("Button pressed! sending a POST to IFTTT\n");
http_socket_post(&s, url_buffer, NULL, 0, NULL, callback, NULL);
}
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2016, Zolertia - http://www.zolertia.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 PROJECT_CONF_H_
#define PROJECT_CONF_H_
/*---------------------------------------------------------------------------*/
/* Use either the cc1200_driver for sub-1GHz, or cc2538_rf_driver (default)
* for 2.4GHz built-in radio interface
*/
#undef NETSTACK_CONF_RADIO
#define NETSTACK_CONF_RADIO cc2538_rf_driver
/* Alternate between ANTENNA_SW_SELECT_SUBGHZ or ANTENNA_SW_SELECT_2_4GHZ */
#define ANTENNA_SW_SELECT_DEF_CONF ANTENNA_SW_SELECT_2_4GHZ
#define NETSTACK_CONF_RDC nullrdc_driver
#define RESOLV_CONF_SUPPORTS_MDNS 0
#define UIP_CONF_MAX_ROUTES 3
#define NBR_TABLE_CONF_MAX_NEIGHBORS 3
#define HTTP_CLIENT_BUFFER_LEN 256
#define IFTTT_EVENT "button"
#define IFTTT_KEY "XXXXXX"
/*---------------------------------------------------------------------------*/
#endif /* PROJECT_CONF_H_ */
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,16 @@
DEFINES += PROJECT_CONF_H=\"project-conf.h\"
all: ip64-router
BOARD = orion
CONTIKI = ../../../../..
WITH_IP64 = 1
CONTIKI_WITH_IPV6 = 1
DEFINES += UIP_CONF_TCP=1
PROJECT_SOURCEFILES += httpd-simple.c
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1 @@
TARGET = zoul

View file

@ -0,0 +1,229 @@
/*
* 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 "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);
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/Zolertia/\r\nConnection: close\r\n";
const char http_header_404[] = "HTTP/1.0 404 Not found\r\nServer: Contiki/Zolertia/\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";
/*---------------------------------------------------------------------------*/
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);
}
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,70 @@
/*
* 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"
#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,324 @@
/*
* Copyright (c) 2016, Zolertia - http://www.zolertia.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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup zolertia-orion-router
* @{
*
* \file
* Example of an Ethernet IP64 router with weberver
*
* \author
* Antonio Lignan <alinan@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "contiki-lib.h"
#include "contiki-net.h"
#include "net/ip/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/rpl/rpl.h"
#include "rpl-dag-root.h"
#include "dev/leds.h"
#include "ip64.h"
#include "net/netstack.h"
#include "httpd-simple.h"
#include <stdio.h>
#include <stdlib.h>
/*---------------------------------------------------------------------------*/
#define BUFFER_LENGTH 256
/*---------------------------------------------------------------------------*/
#define LEDS_DHCP LEDS_GREEN
#define WEBSERVER_CONF_LOADTIME 0
#define WEBSERVER_CONF_FILESTATS 0
#define WEBSERVER_CONF_NEIGHBOR_STATUS 0
/*---------------------------------------------------------------------------*/
PROCESS(router_node_process, "Router node w/ webserver");
/*---------------------------------------------------------------------------*/
#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(&router_node_process,&webserver_nogui_process);
/*---------------------------------------------------------------------------*/
static const char *TOP = "<html><head><title>Zolertia IP64 Router</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[BUFFER_LENGTH];
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[BUFFER_LENGTH];
#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);
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>(%u.%02u 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;
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(router_node_process, ev, data)
{
PROCESS_BEGIN();
static struct etimer et;
/* Turn radio off while initialazing */
NETSTACK_MAC.off(0);
/* Initialize the IP64 module so we'll start translating packets */
ip64_init();
printf("Waiting for an address...\n");
/* Wait to get a DHCP address */
etimer_set(&et, CLOCK_SECOND * 5);
while(1) {
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
leds_toggle(LEDS_DHCP);
if(ip64_hostaddr_is_configured()) {
const uip_ip4addr_t *hostaddr = ip64_get_hostaddr();
const uip_ip4addr_t *netmask = ip64_get_netmask();
const uip_ip4addr_t *gwaddr = ip64_get_draddr();
printf("IPv4 DHCP address: %d.%d.%d.%d\n", hostaddr->u8[0],
hostaddr->u8[1],
hostaddr->u8[2],
hostaddr->u8[3]);
printf("Netmask : %d.%d.%d.%d\n", netmask->u8[0], netmask->u8[1],
netmask->u8[2], netmask->u8[3]);
printf("Gateway: %d.%d.%d.%d\n", gwaddr->u8[0], gwaddr->u8[1],
gwaddr->u8[2], gwaddr->u8[3]);
break;
}
etimer_reset(&et);
}
leds_off(LEDS_DHCP);
/* Turn the radio on and create the network */
NETSTACK_MAC.off(1);
/* Set us up as a RPL root node. */
rpl_dag_root_init_dag();
/* ... and do nothing more. */
while(1) {
PROCESS_WAIT_EVENT();
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 2016, Zolertia - http://www.zolertia.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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup zoul-examples
* @{
*
* \defgroup zolertia-orion-router Zolertia's Orion border router
*
* Implements a simple IP64 router with a webserver
*
* @{
*
* \file
* Configuration file for the Zolertia's Orion IP64 router
*
* \author
* Antonio Lignan <alinan@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
/* Prevent the router from dropping below LPM2 to avoid RAM overflow */
#define LPM_CONF_MAX_PM 0
/* Use either the cc1200_driver for sub-1GHz, or cc2538_rf_driver (default)
* for 2.4GHz built-in radio interface
*/
#undef NETSTACK_CONF_RADIO
#define NETSTACK_CONF_RADIO cc2538_rf_driver
/* Disable RDC */
#define NETSTACK_CONF_RDC nullrdc_driver
/* USe DHCP */
#define IP64_CONF_DHCP 1
/* Webserver settings */
#define WEBSERVER_CONF_ROUTE_LINKS 0
#define UIP_CONF_RECEIVE_WINDOW 128
#define WEBSERVER_CONF_CFS_CONNS 2
#define UIP_CONF_BUFFER_SIZE 900
#define UIP_CONF_TCP_MSS 128
#endif /* PROJECT_CONF_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -48,7 +48,13 @@
*/
#define MOTION_SENSOR_PORT GPIO_A_NUM
#define MOTION_SENSOR_PIN 5
#define MOTION_SENSOR_VECTOR NVIC_INT_GPIO_PORT_A
#define MOTION_SENSOR_VECTOR GPIO_A_IRQn
/* Specify the digital light sensor model to use: TSL2561 (default) or TSL2563 */
#define TSL256X_CONF_REF TSL2561_SENSOR_REF
/* Use the following I2C address for the BME280 sensor (from MikroElektronika) */
#define BME280_CONF_ADDR 0x76
#endif /* PROJECT_CONF_H_ */

View file

@ -4,9 +4,6 @@ CONTIKI_PROJECT = test-power-mgmt
BOARD ?= remote-revb
# Works in Linux and probably on OSX too (RTCC example)
CFLAGS = -DDATE="\"`date +"%02u %02d %02m %02y %02H %02M %02S"`\""
all: $(CONTIKI_PROJECT)
CONTIKI = ../../../..

View file

@ -46,6 +46,9 @@
#define BROADCAST_CHANNEL 129
#define NETSTACK_CONF_RDC nullrdc_driver
#define RTC_CONF_INIT 1
#define RTC_CONF_SET_FROM_SYS 1
#endif /* PROJECT_CONF_H_ */
/**

View file

@ -59,10 +59,6 @@ static struct etimer et;
/* RE-Mote revision B, low-power PIC version */
#define PM_EXPECTED_VERSION 0x20
/*---------------------------------------------------------------------------*/
#ifndef DATE
#define DATE "Unknown"
#endif
/*---------------------------------------------------------------------------*/
#define TEST_LEDS_FAIL leds_off(LEDS_ALL); \
leds_on(LEDS_RED); \
PROCESS_EXIT();
@ -80,7 +76,6 @@ PROCESS_THREAD(test_remote_pm, ev, data)
static uint8_t aux;
static uint16_t voltage;
static uint32_t cycles;
static char *next;
PROCESS_BEGIN();
@ -162,38 +157,13 @@ PROCESS_THREAD(test_remote_pm, ev, data)
/* Configure the RTCC to schedule a "hard" restart of the shutdown mode,
* waking up from a RTCC interrupt to the low-power PIC
*/
printf("PM: System date: %s\n", DATE);
if(strcmp("Unknown", DATE) == 0) {
printf("PM: could not retrieve date from system\n");
printf("PM\n");
if(rtcc_get_time_date(simple_td) == AB08_ERROR) {
printf("PM: Couldn't read time and date\n");
TEST_LEDS_FAIL;
}
/* Configure RTC and return structure with all parameters */
rtcc_init();
/* Configure the RTC with the current values */
simple_td->weekdays = (uint8_t)strtol(DATE, &next, 10);
simple_td->day = (uint8_t)strtol(next, &next, 10);
simple_td->months = (uint8_t)strtol(next, &next, 10);
simple_td->years = (uint8_t)strtol(next, &next, 10);
simple_td->hours = (uint8_t)strtol(next, &next, 10);
simple_td->minutes = (uint8_t)strtol(next, &next, 10);
simple_td->seconds = (uint8_t)strtol(next, NULL, 10);
simple_td->miliseconds = 0;
simple_td->mode = RTCC_24H_MODE;
simple_td->century = RTCC_CENTURY_20XX;
if(rtcc_set_time_date(simple_td) == AB08_ERROR) {
printf("PM: Time and date configuration failed\n");
TEST_LEDS_FAIL;
} else {
if(rtcc_get_time_date(simple_td) == AB08_ERROR) {
printf("PM: Couldn't read time and date\n");
TEST_LEDS_FAIL;
}
}
printf("PM: Configured time: ");
rtcc_print(RTCC_PRINT_DATE_DEC);

View file

@ -3,9 +3,6 @@ CONTIKI_PROJECT = test-rtcc
TARGET = zoul
# Works in Linux and probably on OSX too (RTCC example)
CFLAGS = -DDATE="\"`date +"%02u %02d %02m %02y %02H %02M %02S"`\""
all: $(CONTIKI_PROJECT)
CONTIKI = ../../../..

View file

@ -47,6 +47,9 @@
#define NETSTACK_CONF_RDC nullrdc_driver
#define RTC_CONF_INIT 1
#define RTC_CONF_SET_FROM_SYS 1
#endif /* PROJECT_CONF_H_ */
/*---------------------------------------------------------------------------*/
/**

View file

@ -55,10 +55,6 @@
#include <stdio.h>
#include <stdlib.h>
/*---------------------------------------------------------------------------*/
#ifndef DATE
#define DATE "Unknown"
#endif
/*---------------------------------------------------------------------------*/
#define LOOP_PERIOD 60L
#define LOOP_INTERVAL (CLOCK_SECOND * LOOP_PERIOD)
#define TEST_ALARM_SECOND 15
@ -109,58 +105,13 @@ rtcc_interrupt_callback(uint8_t value)
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_remote_rtcc_process, ev, data)
{
static char *next;
PROCESS_BEGIN();
/* Alternatively for test only, undefine DATE and define on your own as
* #define DATE "07 06 12 15 16 00 00"
* Also note that if you restart the node at a given time, it will use the
* already defined DATE, so if you want to update the device date/time you
* need to reflash the node
*/
/* Get the system date in the following format: wd dd mm yy hh mm ss */
printf("RE-Mote RTC test, system date: %s\n", DATE);
/* Sanity check */
if(strcmp("Unknown", DATE) == 0) {
printf("Fail: could not retrieve date from system\n");
PROCESS_EXIT();
}
/* Configure RTC and return structure with all parameters */
rtcc_init();
printf("RE-Mote RTC test\n");
/* Map interrupt callback handler */
RTCC_REGISTER_INT1(rtcc_interrupt_callback);
/* Configure the RTC with the current values */
simple_td->weekdays = (uint8_t)strtol(DATE, &next, 10);
simple_td->day = (uint8_t)strtol(next, &next, 10);
simple_td->months = (uint8_t)strtol(next, &next, 10);
simple_td->years = (uint8_t)strtol(next, &next, 10);
simple_td->hours = (uint8_t)strtol(next, &next, 10);
simple_td->minutes = (uint8_t)strtol(next, &next, 10);
simple_td->seconds = (uint8_t)strtol(next, NULL, 10);
/* Don't care about the milliseconds... */
simple_td->miliseconds = 0;
/* This example relies on 24h mode */
simple_td->mode = RTCC_24H_MODE;
/* And to simplify the configuration, it relies it will be executed in the
* present century
*/
simple_td->century = RTCC_CENTURY_20XX;
/* Set the time and date */
if(rtcc_set_time_date(simple_td) == AB08_ERROR) {
printf("Fail: Time and date not configured\n");
PROCESS_EXIT();
}
/* Wait a bit */
etimer_set(&et, (CLOCK_SECOND * 2));
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

View file

@ -0,0 +1,93 @@
/*
* Copyright (c) 2016, Zolertia <http://www.zolertia.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 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.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup zoul-examples
* @{
*
* \defgroup zoul-bme280-test BME280 temperature and humidity sensor test
*
* Demonstrates the use of the BME280 digital temperature and humidity sensor
* @{
*
* \file
* A quick program for testing the BME280 temperature and humidity sensor
* \author
* Antonio Lignan <alinan@zolertia.com>
*/
/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include "contiki.h"
#include "dev/bme280/bme280.h"
#include "dev/bme280/bme280-sensor.h"
/*---------------------------------------------------------------------------*/
#define BME280_USE_STD_API 1
/*---------------------------------------------------------------------------*/
PROCESS(zoul_bme280_process, "BME280 test");
AUTOSTART_PROCESSES(&zoul_bme280_process);
/*---------------------------------------------------------------------------*/
static struct etimer et;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(zoul_bme280_process, ev, data)
{
PROCESS_BEGIN();
SENSORS_ACTIVATE(bme280_sensor);
/* Let it spin and read sensor data */
while(1) {
etimer_set(&et, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
#if BME280_USE_STD_API
printf("temperature = %-d ", bme280_sensor.value(BME280_SENSOR_TEMP));
printf("humidity = %-d ", bme280_sensor.value(BME280_SENSOR_HUMIDITY));
printf("pressure = %-d\n", bme280_sensor.value(BME280_SENSOR_PRESSURE));
#else /* BME280_USE_STD_API */
/* Trigger burst read */
bme280_sensor.value(BME280_SENSOR_TEMP);
printf("temperature = %5.2f" , (double)bme280_mea.t_overscale100 / 100.);
printf("humidity = %5.2f ", (double)bme280_mea.h_overscale1024 / 1024.);
#ifdef BME280_64BIT
printf("pressure = %5.2f\n", (double)bme280_mea.p_overscale256 / 256.);
#else /* BME280_64BIT */
printf("pressure = %5.2f\n", (double)bme280_mea.p);
#endif /* BME280_64BIT */
#endif /* BME280_USE_STD_API */
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/