## 4 Simulation and Evaluation
### Simulation Environment: WSNSim  
WSNSim developed by [PERSON] _et al_ is a component based, event driven runtime and more power modeling simulation environment to simulate the energy usage in each node for certain applications [22][23]. The components in WSNSim are similar to Mote developed by University of California at Berkeley, which include CLOCK, SENSOR, ADC, LED, RADIO and APPLICATION. The function of each component is defined as follows.  
**-CLOCK:**: in charge of timing, can offer the current simulating time, is the basic of the simulating events.
**-SENSOR:**: provides the sensor data according to the requirement in the application.  
Figure 1: Routing Tree Example  
* collects the SENSOR data.
* shows the status of the node.
* communicates with other nodes and base station.
* performs specific application.  
The power model used in WSNSim is from Mote MICA2 node with sensor board in a 3V power supply. Table 1 presents the power model for the Mica2 hardware platform. As the table shows, the different CPU power modes cover a wide range of current level, from 103\(\mu\)A in the power-down state up to 8 mA when actively executing instructions. Likewise, the choice of radio transmission power affects current consumption considerably, from 3.7 mA at -20 dB to 21.5 mA at +10 dBm. However, in many of our applications the radio is almost always listening for incoming messages, which consumes 8 mA regardless of transmission activity.  
In our simulation, it is assumed that, the power supply for each mode is a constant 3V; when the node is sending messages, the CPU is in the Active state, LED lights up and radio transmission power is averagely at +4 dBm thus it consumes 12 mA; when the node is listening for messages, the CPU is in the Active state; when the node is receiving messages, the CPU is in the Active state and the radio current is 8 mA. When a node goes into sleep, the CPU is in standby state. The initial energy of each node is set to be the same. When the power assumption of one node exceeds the limit, the node is supposed to be disabled. To simplify the model for simulation, we do not consider the CPU cycle power consumption  
\begin{table}
\begin{tabular}{|l|l|} \hline Mode & Current \\ \hline
**CPU** & \\ Active & 8.0 mA \\ Power-down & 103\(\mu\)A \\ ADC Noise Reduce & 1.0 mA \\ Standby & 216\(\mu\)A \\ Extended Standby & 223\(\mu\)A \\ LEDS & 2.2 mA \\ MICA2 Sensor Board & 0.7 mA \\
**EEPROM access** & \\ Read & 6.2 mA \\ Read Time & 565\(\mu\)A \\ Write & 18.4 mA \\ Write Time & 12.9\(\mu\)A \\
**Radio** & \\ Rx & 8 mA \\ TX & 12 mA \\ \hline \end{tabular}
\end{table}
Table 1: Power Model of MICA2 Node With Sensor Board in WSNSimand consider the battery model a linear one. There are two main simulating parameters to be set, that is, the nodes number, N, and the simulating time, T. When the simulating starts, the nodes are randomly deployed in a square with density of 100 nodes per km\({}^{2}\) shown in Figure 2 and WSNSim will generate the sensor data in some random distribution according to different applications. The clock is timing, when a timer is fired, an event will occur and WSNSim will check the task queue to perform related operation. The power consumption is calculated and stored for each operation in each node. When the simulation finishes, the energy used in each node will be recorded into files for further analysis.