## 4 LOKA: LOw Power Consumption Algorithm
Once the LPC824 is in the _Power-down_ mode, it wakes up when one of the following conditions is satisfied:  
* The voltage supplied is less than 3 V. Then, an IRQ occurs on BOD. * End of the WKT count. Then, an IRQ occurs on WKT. * A falling edge in the WKT pin. Then, an IRQ occurs by the associate digital input-output (DIO) pin. Related to the XB24, it implements two types of power modes to reduce the consumption: _Pin sleep_ and _Cyclic sleep_. These sleep modes can be configured through a voltage level in the first mode or through AT commands in the second mode. In this way, our choice is _Pin sleep_ mode because the LPC824 could command to the XB24 the time to change from sleep mode to active mode or vice versa. Thus, the Sleep Mode Register (SMR) of the XB24 is set to Pin Hibernate option to support it and LPC824 is connected to the Sleep_RQ pin of the XB24 to control its idle or activation mode. At the same time, LPC824 is connected to the On/Sleep pin of the XB24 to read the current mode through a voltage level as the Section 3.3 illustrated. For the XB24 firmware, we can choose between two different types depending on the data packaging:  
* AT firmware. Using this firmware, the device is configured to send the information by AT commands. All the data read in the XB24 UART port will be sent depending on some initial configurations that must be defined by the user. The communication is done in a serial fashion. * API firmware. Using this firmware, the information is sent and received in a package form. Therefore, the XB24 will send different packages depending on the content reading in the UART, which is supported by a specific protocol defined by the manufacturer. Considering the differences between both firmwares, on the one hand, the AT firmware is chosen for the XB24 end-device (sensor motes) because the transmission size is smaller than the transmission on the API firmware. On the other and, the API firmware is chosen for the XB24 coordinator (collector mote) because the package form enables to identify the sender. In this order, the Figure 4 illustrates the time-to-time that each element of a sensor mote is in low power consumption mode or in active mode as well as the exchange of data between the sensor mote and the collector mote. Thereupon, the Diagram of Figure 4 is explained _column by column_ analyzing the program flow of each device taking into account that the LPC824 and the XB24 end-device correspond to the sensor mote and the XB24 coordinator corresponds to the collector mote. In respect of the first column, initially, the LPC824 is in _Power down_ mode. It will wake up and change to active mode when the wake-up pin value changes due to an alarm detection or time out. Both events raise an exception in the microcontroller that should be handled with the highest priority. As consequence, it reads the values of the sensor's variables. After that, the LPC824 sends a wake-up signal to the XB24 end-device Sleep_RQ pin and waits to detect the wake up signal reading by the On/Sleep pin of the XB24 end-device. When the XB24 is waked up, the LPC824 sends the information read by the UART to the XB24 end-device in order to be transmitted to the XB24 coordinator. When the wireless transmission is completed, the LPC824 commands the XB24 end-device to enter into _Sleep_ mode using the XB24 Sleep_RQ pin. Finally, the LPC824 acknowledges the new mode of the XB24 end-device by means of the On/Sleep pin and sets itself to _Power-down_ mode until a new exception is detected. The second columns corresponds to the XB24 end-device. Initially, the XB24 end-device is in _Sleep_ mode after the initialization and it is joined to the WSN. The XB24 end-device will be in _Sleep_ mode until it detects the wake up signal from the LPC824 in its Sleep_RQ pin. When it detects the signal, it changes to active mode reporting in the On/Sleep pin. At this moment, the XB24 end-device reads the information by the UART and sends it to the XB24 coordinator.