diff --git a/examples/ipv6/sky-websense/Makefile b/examples/ipv6/sky-websense/Makefile new file mode 100644 index 000000000..20595ba84 --- /dev/null +++ b/examples/ipv6/sky-websense/Makefile @@ -0,0 +1,14 @@ +all: sky-websense + +CONTIKI=../../.. + +WITH_UIP6=1 +UIP_CONF_IPV6=1 + +APPS += webserver + +CFLAGS += -DPROJECT_CONF_H=\"project-rpl-web-conf.h\" +PROJECTDIRS += ../rpl-border-router +PROJECT_SOURCEFILES += httpd-simple.c + +include $(CONTIKI)/Makefile.include diff --git a/examples/ipv6/sky-websense/Makefile.target b/examples/ipv6/sky-websense/Makefile.target new file mode 100644 index 000000000..d56a50bcc --- /dev/null +++ b/examples/ipv6/sky-websense/Makefile.target @@ -0,0 +1 @@ +TARGET = sky diff --git a/examples/ipv6/sky-websense/project-rpl-web-conf.h b/examples/ipv6/sky-websense/project-rpl-web-conf.h new file mode 100644 index 000000000..6413a5e3a --- /dev/null +++ b/examples/ipv6/sky-websense/project-rpl-web-conf.h @@ -0,0 +1,47 @@ +/* + * 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. + * + * $Id: project-rpl-web-conf.h,v 1.1 2010/05/09 12:56:48 nifi Exp $ + */ + +#ifndef __PROJECT_RPL_WEB_CONF_H__ +#define __PROJECT_RPL_WEB_CONF_H__ + +#undef QUEUEBUF_CONF_NUM +#define QUEUEBUF_CONF_NUM 6 + +#undef UIP_CONF_BUFFER_SIZE +#define UIP_CONF_BUFFER_SIZE 140 + +#undef UIP_CONF_RECEIVE_WINDOW +#define UIP_CONF_RECEIVE_WINDOW 60 + +#undef WEBSERVER_CONF_CFS_CONNS +#define WEBSERVER_CONF_CFS_CONNS 2 + +#endif /* __PROJECT_RPL_WEB_CONF_H__ */ diff --git a/examples/ipv6/sky-websense/sky-websense.c b/examples/ipv6/sky-websense/sky-websense.c new file mode 100644 index 000000000..90c14f03e --- /dev/null +++ b/examples/ipv6/sky-websense/sky-websense.c @@ -0,0 +1,134 @@ +/* + * 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. + * + * $Id: sky-websense.c,v 1.1 2010/05/09 12:56:48 nifi Exp $ + */ + +/** + * \file + * Light and temperatur sensor web demo + * \author + * Niclas Finne + * Joakim Eriksson + * Joel Hoglund + */ + +#include "contiki.h" +#include "httpd-simple.h" +#include "webserver-nogui.h" +#include "dev/sht11-sensor.h" +#include "dev/light-sensor.h" +#include "dev/leds.h" +#include + +PROCESS(web_sense_process, "Sense Web Demo"); + +AUTOSTART_PROCESSES(&web_sense_process); + +#define HISTORY 16 +static int temperature[HISTORY]; +static int light1[HISTORY]; +static int sensors_pos; + +/*---------------------------------------------------------------------------*/ +static const char *TOP = "Contiki Web Sense\n"; +static const char *BOTTOM = "\n"; +/*---------------------------------------------------------------------------*/ +/* Only one single request at time */ +static char buf[256]; +static int blen; +#define ADD(...) do { \ + blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \ + } while(0) +static void +generate_chart(const char *title, const char *unit, int min, int max, int *values) +{ + int i; + blen = 0; + ADD("

%s

\n" + " 0 ? "," : "", values[(sensors_pos + i) % HISTORY]); + } + ADD("\">"); +} +static +PT_THREAD(send_values(struct httpd_state *s)) +{ + PSOCK_BEGIN(&s->sout); + + SEND_STRING(&s->sout, TOP); + + if(s->filename[1] == 'l' || s->filename[1] != 't') { + generate_chart("Light", "Light", 0, 500, light1); + SEND_STRING(&s->sout, buf); + } + if(s->filename[1] == 't' || s->filename[1] != 'l') { + generate_chart("Temperature", "Celsius", 15, 50, temperature); + 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 send_values; +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(web_sense_process, ev, data) +{ + static struct etimer timer; + PROCESS_BEGIN(); + + sensors_pos = 0; + process_start(&webserver_nogui_process, NULL); + + etimer_set(&timer, CLOCK_SECOND * 2); + SENSORS_ACTIVATE(light_sensor); + SENSORS_ACTIVATE(sht11_sensor); + + while(1) { + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer)); + etimer_reset(&timer); + + light1[sensors_pos] = 10 * light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC) / 7; + temperature[sensors_pos] = ((sht11_sensor.value(SHT11_SENSOR_TEMP) / 10) - 396) / 10; +; + sensors_pos = (sensors_pos + 1) % HISTORY; + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/