## 4 LOKA: LOw Power Consumption Algorithm
Finally, it waits the sleep mode signal from the LPC824 and it will stay into sleep mode until a new transmission is needed. The third column corresponds to the XB24 coordinator. It is always in active mode to maintain the network and to receive data from the sensor motes. The XB24 coordinator must support the _Sleep_ mode of the XB24 end-devices without baning them from the network. This is achieved through the AT configuration using the Cyclic Sleep Period (SP) and Sleep options (SO). In our case SP corresponds to the minimum time of the cyclic WKT IRQ in the LPC824 of the sensor motes taking into account the low power clock WKT accuracy. Finally, SO configures some options for sleep. to _Power down_ mode (lines 21) and waits until an interruption triggers back it to the _active_ mode. There are three possible IRQs: IRQ_WKT, IRQ_WAKE_UP_PIN and IRQ_BOD. When an IRQ is triggered, the LPC824 continues the execution. Each interruption has its own handler defined to clear its property flag (lines 11-16), if IRQ_BOD is triggered one flag is activated to send the battery level (lines 26,27). In that point, the mode reads the information of the sensors (line 23), commands the XB24 end-device to change to _active_ mode using the function _wake_up_xb24_ (lines 6-10) and sends the information to the collector mode through the XB24 end-device (line 25). Finally, the XB24 is set again to _Sleep_ mode and the LPC824 changes itself to _Power down_ mode repeating the loop. LOKA is a new approach in the newest DTNs since LOKA implements asynchronous package reception in the end-device for commanding operations while the end-device is in _Sleep_ mode. To do this, LOKA can read these packets after the activation of the XB24 end-device (line 24). First, the message is saved in the output buffer of the sender. After that, the sender transmits to the XB24 end-device the message when the coordinator detects that the XB24 end-device is active (since LOKA has activated it changing its mode consumption). Then, LOKA incorporates the reading of the message (line 28) and, finally, the LPC824 carries out the required actions referred to the received packets (line 29). ```
1:function\(sleep\_xb24()\)\(\triangleright\) Order to sleep XB24
2:\(SLEEPRQ\gets TRUE\)\(\triangleright\) Signal to sleep XB24
3:while\(SLEEPSEL\
eq FALSE\)do\(\triangleright\) Wait until XB24 is in sleep mode
4:nothing
5:return
6:function\(wake\_up\_xb24()\)\(\triangleright\) Order to wake up XB24
7:\(SLEEPRQ\gets FALSE\)\(\triangleright\) Signal to wake up XB24
8:while\(SLEEPSEL\
eq TRUE\)do\(\triangleright\) Wait until XB24 is in active mode
9:nothing
10:return
11:functionhandleIRQ_WKT\(\triangleright\) IRQ to send data at periodic interval
12:\(CLE\_WKT\_FLAG\)
13:functionhandleIRQ_WAKE_UP_PIN\(\triangleright\) IRQ to send data if an alarm
14:\(CLE\_WAKE\_UP\_FLAG\)
15:functionhandleIRQ_BOD\(\triangleright\) IRQ if low battery level
16:\(IRQ\_BOD\gets TRUE\)
17:proceduremain
18:\(sleep\_xb24()\)\(\triangleright\) Sensor mode program
19:\(INITIALIZE\)\(DEVICES\)\(AND\)\(IRQ\)\(\triangleright\) Initialize all used devices and IRQs
20:loop\(\triangleright\) Continuous operation
21:setPOWER_DOWN_MODE\(\triangleright\) Go to low power mode
22:\(\triangleright\) Execution only continues after an IRQ triggers active mode
23:\(READ\_ALL\_SENSORS\)
24:\(wake\_up\_xb24()\)
25:\(UART\_SEND\)\(\triangleright\) Send data samples to XB24 via UART
26:ifIRQ_BOD then\(\triangleright\) Notify low battery level
27:\(UART\_SEND\_BATTERY\_LEVEL\)
28:\(UART\_READ\)\(\triangleright\) Read the received packets
29:Management received packets\(\triangleright\) Carry out specific actions about the received packets
30:\(sleep\_xb24()\)

## 5 Experiments

In order to analyze and compare the power consumption of a sensor more that exploits our algorithm, we have built a sensor more prototype in which we have implemented it and a second sensor prototype without it, i.e., it is always in active mode by default.