diff --git a/apps/arduino/arduino-process.c b/apps/arduino/arduino-process.c index 8cda5a0ae..56a04d50d 100644 --- a/apps/arduino/arduino-process.c +++ b/apps/arduino/arduino-process.c @@ -56,6 +56,7 @@ #include "adc.h" #include "hw-arduino.h" #include "contiki.h" +#include "net/netstack.h" #define DEBUG 0 #if DEBUG @@ -110,20 +111,26 @@ PROCESS(arduino_sketch, "Arduino Sketch Wrapper"); #define LOOP_INTERVAL (1 * CLOCK_SECOND) #endif +#ifndef SLEEP_NETWORK_INTERVAL +#define SLEEP_NETWORK_INTERVAL (60 * CLOCK_SECOND) +#endif + PROCESS_THREAD(arduino_sketch, ev, data) { static struct etimer loop_periodic_timer; - + static struct etimer network_off_periodic_timer; PROCESS_BEGIN(); adc_init (); mcu_sleep_init (); setup (); /* Define application-specific events here. */ etimer_set(&loop_periodic_timer, LOOP_INTERVAL); + etimer_set(&network_off_periodic_timer, SLEEP_NETWORK_INTERVAL); while (1) { PROCESS_WAIT_EVENT(); #if PLATFORM_HAS_BUTTON if(ev == sensors_event && data == &button_sensor) { + NETSTACK_MAC.off(1); mcu_sleep_off(); PRINTF("*******BUTTON*******\n"); @@ -136,11 +143,16 @@ PROCESS_THREAD(arduino_sketch, ev, data) } #endif /* PLATFORM_HAS_BUTTON */ - if(etimer_expired(&loop_periodic_timer)) { - mcu_sleep_off(); - loop (); - mcu_sleep_on(); - etimer_reset(&loop_periodic_timer); + if(etimer_expired(&network_off_periodic_timer)) { +// NETSTACK_MAC.off(0); + NETSTACK_MAC.on(); + etimer_reset(&network_off_periodic_timer); + } + if(etimer_expired(&loop_periodic_timer)) { + mcu_sleep_off(); + loop (); + mcu_sleep_on(); + etimer_reset(&loop_periodic_timer); } } PROCESS_END();