## 4 LOKA: LOw Power Consumption Algorithm  
This section introduces LOKA, an algorithm to optimize the energy consumption in the above WSN scenario. LOKA is based on the efficient use of power modes of the XB24 and the LPC824. Knowing the transmission data interval of a sensor more, LOKA selects the adequate power mode in order to save energy when the more does not require high computing power. LOKA is implemented in the sensor motes since an end-device element can work in different consumption modes: idle, taking samples or transmitting information. However, the coordinator is always in active mode because it must be available to receive data from any end-device while keeping up the network. Thus, LOKA is not implemented in the collector mote. Two devices of the sensor mote are taken into account in LOKA: the LPC824 microcontroller and the XB24 module. Both come together to optimize the system consumption and they need to agree in the flow of the program control. In order to optimize the energy consumption, both devices should be sleeping when there is no need of processing or sending data. Thus, these devices are in an idle state until a periodical timer wakes them up or when an alarm event is detected. While it is true that duty-cycling mechanisms are integrated in ZigBee devices [38], many ZigBee commercial modules need an external microcontroller to manage them. In this sense, to the best of our knowledge there is no algorithm o mechanism that allows deploying a duty-cycling mechanism into two devices (ZigBee module and external microcontroller) at the same time. The novelty of LOKA is the management of a two duty-cycling mechanism in only one algorithm using a commercial end-device module of the ZigBee protocol and an external microcontroller. The proposed algorithm controls the sleep time of both, the end-device and the microcontroller depending on the network needs. Furthermore, LOKA handles the delay buffers of the ZigBee module, enhancing the energy consumption. This improvement is a new approach in newest delay tolerant networking protocols. Regarding to the LPC824, there are four power consumption modes that can be activated by the System Control Register (SCR): _Sleep_, _Deep-sleep_, _Power-down_ and _Deep power-down_. These modes power off different mechanisms of the LPC824 in order to consume less energy. The Sleep mode only affects to the CPU. The _Deep-sleep_ and _Power-down_ modes affect to the CPU and all the selected peripherals with the following difference: in _Deep-sleep_ mode the flash memory is in standby mode, while in _Power-down_ mode it is powered down. Finally, _Deep power-down_ mode affects all system except for the general purpose registers in the power management unit and the self-wake-up timer. In this mode, the LPC824 reboots when it wakes-up. In this way, the _Deep-power_ down mode is the most efficient low power consumption configuration supported for our scenario because the sensor mote needs to power down all possible devices without rebooting to minimize the energy consumption. All peripherals and memories will be configured to power down in _Power-down_ mode, except the following ones:  
Figure 3: LPC824 microcontroller connection circuit into the sensor mote. * Brown-out detection (BOD). It is used to send an interruption when a low battery level is detected. * Wake-up time (WKT). It is used to generate a cyclic interruption in order to take samples and send them to the collector more periodically. * Wake-up pin IRQ. It is used to send a interruption when an alarm event is detected. * Brown-out IRQ. It corresponds to the active interrupt handler when the brown-out is detected. * WKT IRQ. It corresponds to the active interruption handler when the wake-up time ends or a signal is detected in wake-up pin. * WKT low-power 10 kHz clock source. A low power clock is active to synchronize the above elements in _Power-down_ mode.