diff --git a/cpu/avr/dev/button-sensor.c b/cpu/avr/dev/button-sensor.c index 067df7246..14b959d2e 100644 --- a/cpu/avr/dev/button-sensor.c +++ b/cpu/avr/dev/button-sensor.c @@ -11,6 +11,7 @@ const struct sensors_sensor button_sensor; static struct timer debouncetimer; static int status(int type); static int enabled = 0; +volatile static int bstate; struct sensors_sensor *sensors[1]; unsigned char sensors_flags[1]; @@ -23,11 +24,11 @@ ISR(INT4_vect) { // leds_toggle(LEDS_RED); - if(BUTTON_CHECK_IRQ()) { if(timer_expired(&debouncetimer)) { // led1_on(); timer_set(&debouncetimer, CLOCK_SECOND / 8); + bstate = (PINE & _BV(PE4) ? 0 : 1); sensors_changed(&button_sensor); // led1_off(); } @@ -39,9 +40,9 @@ ISR(INT4_vect) static int value(int type) { - return (PINE & _BV(PE4) ? 0 : 1) || !timer_expired(&debouncetimer); + //return (PINE & _BV(PE4) ? 0 : 1) || !timer_expired(&debouncetimer); - //return 0; + return bstate; } static int diff --git a/cpu/avr/radio/rf230bb/rf230bb.c b/cpu/avr/radio/rf230bb/rf230bb.c index a6b7572cf..624018f36 100644 --- a/cpu/avr/radio/rf230bb/rf230bb.c +++ b/cpu/avr/radio/rf230bb/rf230bb.c @@ -1796,7 +1796,8 @@ rf230_cca(void) // if (cca & 0x40) {/*DEBUGFLOW('3')*/;} else {rf230_pending=1;DEBUGFLOW('4');} if (cca & 0x40) { // DEBUGFLOW('5'); - return 1; +// return 1; + return 0; } else { // DEBUGFLOW('6'); busyexit: diff --git a/examples/osd/arduino-climate3/sketch.pde b/examples/osd/arduino-climate3/sketch.pde index 9f9cb22d7..3e729d277 100644 --- a/examples/osd/arduino-climate3/sketch.pde +++ b/examples/osd/arduino-climate3/sketch.pde @@ -120,7 +120,7 @@ void setup (void) rest_init_engine (); rest_activate_resource (&res_htu21dtemp, "s/temp"); rest_activate_resource (&res_htu21dhum, "s/hum"); - rest_activate_resource (&res_dtemp1, "s/t1/temp"); + rest_activate_resource (&res_dtemp1, "s/tempd"); rest_activate_resource (&res_battery, "s/battery"); } @@ -149,6 +149,9 @@ void loop (void) if(htu21d_hum_s[0]==' '){ memcpy (htu21d_hum_s,htu21d_hum_s+1,strlen(htu21d_hum_s)+1); } + if(d_temp_s[0]==' '){ + memcpy (d_temp_s,d_temp_s+1,strlen(d_temp_s)+1); + } // debug only printf("Temp: %s",htu21d_temp_s); diff --git a/examples/osd/arduino-merkurboard/project-conf.h b/examples/osd/arduino-merkurboard/project-conf.h index e0b72b6dc..2d5781ca4 100644 --- a/examples/osd/arduino-merkurboard/project-conf.h +++ b/examples/osd/arduino-merkurboard/project-conf.h @@ -44,10 +44,12 @@ /* For projects, optimize memory and enable RDC again. */ //#undef NETSTACK_CONF_RDC //#define NETSTACK_CONF_RDC nullrdc_driver +//#undef NETSTACK_CONF_MAC +//#define NETSTACK_CONF_MAC nullmac_driver /* Increase rpl-border-router IP-buffer when using more than 64. */ -#undef REST_MAX_CHUNK_SIZE -#define REST_MAX_CHUNK_SIZE 64 +//#undef REST_MAX_CHUNK_SIZE +//#define REST_MAX_CHUNK_SIZE 64 /* Estimate your header size, especially when using Proxy-Uri. */ /* @@ -78,9 +80,4 @@ */ - - - - - #endif /* PROJECT_RPL_WEB_CONF_H_ */ diff --git a/examples/osd/climate2/er-example-server.c b/examples/osd/climate2/er-example-server.c index c3342c9e3..8daf9e6b8 100644 --- a/examples/osd/climate2/er-example-server.c +++ b/examples/osd/climate2/er-example-server.c @@ -82,7 +82,7 @@ extern resource_t res_ds1820; #endif #if defined (PLATFORM_HAS_LEDS) -#include "dev/leds.h" +#include "dev/led.h" extern resource_t res_leds; #endif @@ -100,7 +100,8 @@ void hw_init() { #if defined (PLATFORM_HAS_LEDS) - leds_off(LEDS_RED); +// leds_off(LEDS_RED); +led1_off(); #endif #if PLATFORM_HAS_DS1820 ds1820_temp(); @@ -139,10 +140,10 @@ PROCESS_THREAD(rest_server_example, ev, data) PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); /* if static routes are used rather than RPL */ -#if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE) - set_global_address(); - configure_routing(); -#endif +//#if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE) +// set_global_address(); +// configure_routing(); +//#endif /* Initialize the OSD Hardware. */ hw_init(); diff --git a/examples/osd/climate2/project-conf.h b/examples/osd/climate2/project-conf.h index 11c9b1dd4..0bc192b3a 100644 --- a/examples/osd/climate2/project-conf.h +++ b/examples/osd/climate2/project-conf.h @@ -41,11 +41,11 @@ /* Some platforms have weird includes. */ -#undef IEEE802154_CONF_PANID +//#undef IEEE802154_CONF_PANID /* Save energy */ -#define RDC_CONF_PT_YIELD_OFF +//#define RDC_CONF_PT_YIELD_OFF /* Disabling RDC for demo purposes. Core updates often require more memory. */ /* For projects, optimize memory and enable RDC again. */ diff --git a/examples/osd/triggerbaord/project-conf.h b/examples/osd/triggerbaord/project-conf.h index 510c66786..62e1d8d2b 100644 --- a/examples/osd/triggerbaord/project-conf.h +++ b/examples/osd/triggerbaord/project-conf.h @@ -51,8 +51,8 @@ //#define NETSTACK_CONF_RDC nullrdc_driver /* Increase rpl-border-router IP-buffer when using more than 64. */ -#undef REST_MAX_CHUNK_SIZE -#define REST_MAX_CHUNK_SIZE 64 +//#undef REST_MAX_CHUNK_SIZE +//#define REST_MAX_CHUNK_SIZE 64 /* Estimate your header size, especially when using Proxy-Uri. */ /* @@ -68,7 +68,7 @@ /* Multiplies with chunk size, be aware of memory constraints. */ #undef COAP_MAX_OPEN_TRANSACTIONS -#define COAP_MAX_OPEN_TRANSACTIONS 4 +#define COAP_MAX_OPEN_TRANSACTIONS 8 /* Must be <= open transaction number, default is COAP_MAX_OPEN_TRANSACTIONS-1. */ /* @@ -82,10 +82,22 @@ #define COAP_LINK_FORMAT_FILTERING 0 */ +/* +#undef LLSEC802154_CONF_ENABLED +#define LLSEC802154_CONF_ENABLED 1 +#undef NETSTACK_CONF_FRAMER +#define NETSTACK_CONF_FRAMER noncoresec_framer +#undef NETSTACK_CONF_LLSEC +#define NETSTACK_CONF_LLSEC noncoresec_driver +#undef NONCORESEC_CONF_SEC_LVL +#define NONCORESEC_CONF_SEC_LVL 1 +#define NONCORESEC_CONF_KEY { 0x00 , 0x01 , 0x02 , 0x03 , \ + 0x04 , 0x05 , 0x06 , 0x07 , \ + 0x08 , 0x09 , 0x0A , 0x0B , \ + 0x0C , 0x0D , 0x0E , 0x0F } - - - +*/ #endif /* PROJECT_RPL_WEB_CONF_H_ */ + diff --git a/examples/osd/triggerbaord/resources/res-bled.c b/examples/osd/triggerbaord/resources/res-bled.c new file mode 100644 index 000000000..0afa1889d --- /dev/null +++ b/examples/osd/triggerbaord/resources/res-bled.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + */ + +/** + * \file + * Door resource + * \author + * Harald Pichler + */ + +#include "contiki.h" + +#include +#include "rest-engine.h" +#include "Arduino.h" + +static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); +static void res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); + +/* A simple getter example. Returns the reading from the sensor with a simple etag */ +RESOURCE(res_bled, + "title=\"LED: , POST/PUT mode=on|off\";rt=\"Control\"", + res_get_handler, + res_post_put_handler, + res_post_put_handler, + NULL); + +extern uint8_t bled_pin; +extern uint8_t bled_status; + +static void +res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + unsigned int accept = -1; + REST.get_header_accept(request, &accept); + + if(accept == -1 || accept == REST.type.TEXT_PLAIN) { + REST.set_header_content_type(response, REST.type.TEXT_PLAIN); + snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", bled_status); + + REST.set_response_payload(response, buffer, strlen((char *)buffer)); + } else if(accept == REST.type.APPLICATION_JSON) { + REST.set_header_content_type(response, REST.type.APPLICATION_JSON); + snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'led':%d}", bled_status); + + REST.set_response_payload(response, buffer, strlen((char *)buffer)); + } else { + REST.set_response_status(response, REST.status.NOT_ACCEPTABLE); + const char *msg = "Supporting content-types text/plain and application/json"; + REST.set_response_payload(response, msg, strlen(msg)); + } +} + +static void +res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + size_t len = 0; + const char *mode = NULL; + int success = 1; + + if(success && (len = REST.get_post_variable(request, "mode", &mode))) { + if(strncmp(mode, "on", len) == 0) { + digitalWrite(bled_pin, HIGH); + bled_status=1; + } else if(strncmp(mode, "off", len) == 0) { + digitalWrite(bled_pin, LOW); + bled_status=0; + } else { + success = 0; + } + } else { + success = 0; + } if(!success) { + REST.set_response_status(response, REST.status.BAD_REQUEST); + } +} diff --git a/examples/osd/triggerbaord/resources/res-event.c b/examples/osd/triggerbaord/resources/res-event.c old mode 100644 new mode 100755 index 7524d2ad2..6470c311b --- a/examples/osd/triggerbaord/resources/res-event.c +++ b/examples/osd/triggerbaord/resources/res-event.c @@ -39,6 +39,7 @@ #include #include "rest-engine.h" #include "er-coap.h" +#include "dev/button-sensor.h" #define DEBUG 0 #if DEBUG @@ -76,10 +77,25 @@ static int32_t event_counter = 0; static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { - REST.set_header_content_type(response, REST.type.TEXT_PLAIN); - REST.set_response_payload(response, buffer, snprintf((char *)buffer, preferred_size, "EVENT %lu", event_counter)); + int buttonstate = button_sensor.value(0); + + unsigned int accept = -1; + REST.get_header_accept(request, &accept); + if(accept == -1 || accept == REST.type.TEXT_PLAIN) { + REST.set_header_content_type(response, REST.type.TEXT_PLAIN); + REST.set_response_payload(response, buffer, snprintf((char *)buffer, preferred_size, "EVENT %lu STATE %d", event_counter, buttonstate)); + } else if(accept == REST.type.APPLICATION_JSON) { + REST.set_header_content_type(response, REST.type.APPLICATION_JSON); + REST.set_response_payload(response, buffer, snprintf((char *)buffer, preferred_size, "{'EVENT':%lu ,'STATE': %d}", event_counter, buttonstate)); + } else { + REST.set_response_status(response, REST.status.NOT_ACCEPTABLE); + REST.set_response_payload(response, buffer, snprintf((char *)buffer, preferred_size, "Supporting content-types text/plain and application/json")); + } /* A post_handler that handles subscriptions/observing will be called for periodic resources by the framework. */ + + // tell client when to schedule re-registration: 1 Hour + REST.set_header_max_age(response, /* uint32_t, Seconds */ 3600); } /* * Additionally, res_event_handler must be implemented for each EVENT_RESOURCE. diff --git a/examples/osd/triggerbaord/sketch.pde b/examples/osd/triggerbaord/sketch.pde old mode 100644 new mode 100755 index 73aeb00f7..d026c6985 --- a/examples/osd/triggerbaord/sketch.pde +++ b/examples/osd/triggerbaord/sketch.pde @@ -16,10 +16,9 @@ extern "C" { #include "net/netstack.h" #include "dev/button-sensor.h" - - extern resource_t - res_led, + res_led, + res_bled, res_battery, res_cputemp, res_event, @@ -28,6 +27,8 @@ extern resource_t uint8_t led_pin=4; uint8_t led_status; +uint8_t bled_pin=7; +uint8_t bled_status; } void setup (void) @@ -36,15 +37,21 @@ void setup (void) pinMode(led_pin, OUTPUT); digitalWrite(led_pin, HIGH); led_status=0; + // switch off the bled + pinMode(bled_pin, OUTPUT); + digitalWrite(bled_pin, LOW); + bled_status=0; // sensors SENSORS_ACTIVATE(button_sensor); // init coap resourcen rest_init_engine (); + #pragma GCC diagnostic ignored "-Wwrite-strings" rest_activate_resource (&res_led, "s/led"); + rest_activate_resource (&res_bled, "s/bled"); rest_activate_resource (&res_battery, "s/battery"); rest_activate_resource (&res_cputemp, "s/cputemp"); - rest_activate_resource(&res_event, "s/button"); -// rest_activate_resource (&res_battery, "p/server"); + rest_activate_resource(&res_event, "s/button"); + #pragma GCC diagnostic pop // NETSTACK_MAC.off(1); } diff --git a/platform/osd-merkur-128/Makefile.osd-merkur-128 b/platform/osd-merkur-128/Makefile.osd-merkur-128 index 8817f3855..48881a6f0 100644 --- a/platform/osd-merkur-128/Makefile.osd-merkur-128 +++ b/platform/osd-merkur-128/Makefile.osd-merkur-128 @@ -85,7 +85,7 @@ include $(CONTIKIAVR)/Makefile.avr include $(CONTIKIAVR)/radio/Makefile.radio MODULES += core/net/mac core/net core/net/mac/sicslowmac \ - core/net/mac/contikimac core/net/llsec \ + core/net/mac/contikimac core/net/llsec core/net/llsec/noncoresec \ # core/net/ipv6 core/net/ipv4 core/net/ip \ # core/net/rime \ # core/net/rpl \ diff --git a/platform/osd-merkur-128/contiki-conf.h b/platform/osd-merkur-128/contiki-conf.h index 043dff995..638145710 100644 --- a/platform/osd-merkur-128/contiki-conf.h +++ b/platform/osd-merkur-128/contiki-conf.h @@ -173,6 +173,8 @@ typedef unsigned short uip_stats_t; #define NETSTACK_CONF_RDC sicslowmac_driver #define NETSTACK_CONF_FRAMER framer_802154 #define NETSTACK_CONF_RADIO rf230_driver +/* CCA theshold energy -91 to -61 dBm (default -77). Set this smaller than the $ */ +#define RF230_CONF_CCA_THRES -85 /* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */ #define RF230_CONF_AUTOACK 1 /* Request 802.15.4 ACK on all packets sent (else autoretry). This is primarily for testing. */ @@ -227,6 +229,7 @@ typedef unsigned short uip_stats_t; #define CONTIKIMAC_CONF_WITH_PHASE_OPTIMIZATION 0 #define CONTIKIMAC_CONF_COMPOWER 1 #define RIMESTATS_CONF_ENABLED 0 +#define WITH_FAST_SLEEP 0 #if NETSTACK_CONF_WITH_IPV6 #define NETSTACK_CONF_FRAMER framer_802154 @@ -243,6 +246,8 @@ typedef unsigned short uip_stats_t; #define RF230_CONF_FRAME_RETRIES 1 /* Long csma backoffs will compromise radio cycling; set to 0 for 1 csma */ #define RF230_CONF_CSMA_RETRIES 0 +/* CCA theshold energy -91 to -61 dBm (default -77). Set this smaller than the $ */ +#define RF230_CONF_CCA_THRES -90 #define SICSLOWPAN_CONF_FRAG 1 #define SICSLOWPAN_CONF_MAXAGE 3 /* 211 bytes per queue buffer. Contikimac burst mode needs 15 for a 1280 byte MTU */ diff --git a/platform/osd-merkur-256/Makefile.osd-merkur-256 b/platform/osd-merkur-256/Makefile.osd-merkur-256 index 0a60d2044..36828e93b 100644 --- a/platform/osd-merkur-256/Makefile.osd-merkur-256 +++ b/platform/osd-merkur-256/Makefile.osd-merkur-256 @@ -85,7 +85,7 @@ include $(CONTIKIAVR)/Makefile.avr include $(CONTIKIAVR)/radio/Makefile.radio MODULES += core/net/mac core/net core/net/mac/sicslowmac \ - core/net/mac/contikimac core/net/llsec \ + core/net/mac/contikimac core/net/llsec core/net/llsec/noncoresec \ # core/net/ipv6 core/net/ipv4 core/net/ip \ # core/net/rime \ # core/net/rpl \ diff --git a/platform/osd-merkur-256/contiki-conf.h b/platform/osd-merkur-256/contiki-conf.h index fb8cf3178..e66aac285 100644 --- a/platform/osd-merkur-256/contiki-conf.h +++ b/platform/osd-merkur-256/contiki-conf.h @@ -174,6 +174,8 @@ typedef unsigned short uip_stats_t; #define NETSTACK_CONF_RDC sicslowmac_driver #define NETSTACK_CONF_FRAMER framer_802154 #define NETSTACK_CONF_RADIO rf230_driver +/* CCA theshold energy -91 to -61 dBm (default -77). Set this smaller than the $ */ +#define RF230_CONF_CCA_THRES -85 /* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */ #define RF230_CONF_AUTOACK 1 /* Request 802.15.4 ACK on all packets sent (else autoretry). This is primarily for testing. */ @@ -228,6 +230,7 @@ typedef unsigned short uip_stats_t; #define CONTIKIMAC_CONF_WITH_PHASE_OPTIMIZATION 0 #define CONTIKIMAC_CONF_COMPOWER 1 #define RIMESTATS_CONF_ENABLED 0 +#define WITH_FAST_SLEEP 0 #if NETSTACK_CONF_WITH_IPV6 #define NETSTACK_CONF_FRAMER framer_802154 @@ -244,6 +247,8 @@ typedef unsigned short uip_stats_t; #define RF230_CONF_FRAME_RETRIES 1 /* Long csma backoffs will compromise radio cycling; set to 0 for 1 csma */ #define RF230_CONF_CSMA_RETRIES 0 +/* CCA theshold energy -91 to -61 dBm (default -77). Set this smaller than the $ */ +#define RF230_CONF_CCA_THRES -90 #define SICSLOWPAN_CONF_FRAG 1 #define SICSLOWPAN_CONF_MAXAGE 3 /* 211 bytes per queue buffer. Contikimac burst mode needs 15 for a 1280 byte MTU */