# Wireless Sensor Network Energy Model and Its Use in the Optimization of Routing Protocols
## 2 Description of the Energy Model
Therefore, the best option is when a node sends a packet to a channel that is free and an acknowledgment ACK is received. Then, \(P_{TX_{i}}=1\) and \(P_{RX_{i}}=1\). If the node receives the ACK, it does not retransmit the packet and \(P_{RTX_{i}}=0\). This switching operation is performed in two different stages: the node uses switching energy to change state, transmits the information, uses again switching energy, and receives the packet information. Transmission and receiving energies are considered by (10) and (11), respectively. For each packet transmitted, the node \(i\) executes the CSMA/CA algorithm. The corresponding energy consumed, \(E_{CSMA_{i}}\) is given by (13):  
\[ \begin{array}{ll}E_{CSMA_{i}}=&(T_{CSMA}\times I_{CSMA}\times V_{CSMA})\times \\ &(P_{TX_{i}}+P_{RTX_{i}}+N_{RT_{i}}),\end{array}  \tag{13}\]  
where \(N_{RT_{i}}\) is the number of times that the CSMA/CA algorithm goes back to calculate a delay from the time the channel was found to be busy. This is a random variable. That is, it takes a different value for each transmission. The \((P_{TX_{i}}+P_{RTX_{i}}+N_{RT_{i}})\) term implies that before each message transmission, the channel auditing process must be executed (CSMA/CA algorithm). In the best case, \(P_{TX_{i}}=1\) in the \((P_{TX_{i}}+P_{RTX_{i}}+N_{RT_{i}})\) term, because the channel was free. Then \(N_{RT_{i}}=0\), (there were no retries listening to the channel, i.e., CSMA retries), and the packet is transmitted successfully with \(P_{RTX_{i}}=0\) (without retransmissions). However, the network conditions are not always ideal and there will be collisions causing packet retransmissions and retries when listening to the channel. Then, the \(N_{RT_{i}}\) and \(P_{RTX_{i}}\) variables will exhibit non-zero values. Throughout the sampling time (\(T_{Sampling}\)), the node consumes energy from the microcontroller in active mode for this model. Therefore,  
\[E_{MC_{i}}=T_{Sampling}\times I_{MC}\times V_{MC}. \tag{14}\]  
Now, when the sampling time begins, all nodes turn on. Then, the initial energy consumed by the node \(i\) is \(E_{ON_{i}}=T_{ON}\times I_{ON}\times V_{ON}\). Finally, when the time has finished, node \(i\) turns off, consuming shutdown energy, so \(E_{OFF_{i}}=(T_{OFF}\times I_{OFF}\times V_{OFF})\). At the end of the sampling period, the node reports the total energy consumed by all the functions it performed during the network processes, which will be the local energy of the node. Thus,  
\[ \begin{array}{ll}EnergyNode_{i}=&E_{ON_{i}}+E_{MC_{i}}+E_{OFF_{i}}+\\ &E_{Switching_{i}}+E_{CSMA_{i}}+E_{TX_{i}}+E_{RX_{i}}.\end{array}  \tag{15}\]  
To obtain the total node energy to assess the global energy of the network, we add the total energy of each node when the sampling time has ended as shown in (16):  
\[Total_{E}\text{\emph{energy}}=\sum_{i=1}^{Total_{Nodes}}EnergyNode_{i}, \tag{16}\]  
where \(totalNodes\) is the total number of nodes. Equation (15) describes the actions performed by node \(i\) since it turns on (consuming initial energy \(E_{ON_{i}}\)), and becomes part of a network, until the moment it turns off. The most complex stage is when the node listens to the channel. This activity causes the node to decide whether to transmit packets. All packets sent (either transmitted or retransmitted) imply that the node must first listen to the channel. That is, the node executed the CSMA/CA algorithm using CSMA energy (\(E_{CSMA_{i}}\)). If the channel is free, the node consumes transmission energy (\(E_{TX_{i}}\)) to transmit the packet (\(P_{TX_{i}}\)). If the channel is busy, the node generates a retry variable (\(N_{RT_{i}}\)) because it has to execute the CSMA/CA algorithm again. After the node sends the packet, it receives an acknowledgment, ACK, using reception energy (\(E_{RX_{i}}\)) and receives the packet (\(P_{RX_{i}}\)). On the contrary, if the node does not receive an ACK, it retransmits the packet generated as a retransmission (\(P_{RTX_{i}}\)). For all activity changes, the node consumes switching energy (\(E_{Switching_{i}}\)).