# Context-Aware Wireless Sensor Networks for Smart Building Energy Management System
## 4 Proposed EMS for SEEB
### WSN Network Packet Delivery Evaluation
#### 4.5.3 Signal Power Test and Distance Measurement
\[n_{i}=(A+RSSI)/\!-\!(10^{*}log(D)) \tag{2}\]  
A given RSSI value does not mean a specific distance because indoor conditions differ from one building to another. Hence, we will use distance measurement equations with specific parameters of the building. For this reason, we measured the actual distance and the RSSI value between each pair of nodes; then, we calculated the variable \(n\), which was the environmental condition. This variable \(n\) was used during the node positioning inside the building. For more accurate data, we considered three different communication scenarios. First, both nodes are at the same room. Second, the nodes are in different rooms. Third, both nodes are in the hall. Fourth, one node is in a room while the other one is in the hall. To compute \(n\), we used Equation (2) [19]. Table 7 illustrates the results of calculating the \(n\) value and the RSSI value, and the actual distance. When we measure the distance between two nodes A and B, a specific \(n_{i}\) was used (Table 7). For example, to measure the distance between Router3 and sensor node in Room003 (look at Figure 4), the value of \(n_{4}\) was used. The next Table 8 presents the result of applying Equations (1) and (2) on data in Table 6. This table also shows the actual distance versus the distance measured using Equation (1). The actual distance does not match the distance calculated based on the RSSI value. However, these measurements will help us during the positioning of nodes for good connectivity between WSN nodes in large-scale implementation. The next step was to measure the RSSI value from each sensor node to the gateway. Figure 9 shows the RSSI value in dBm of each sensor node for 10 min. It shows that the RSSI value decreases as the distance between the sensor node and the gateway increases. The experiments showed that the signal between two XBee S2C nodes is still detected when the distance is 60 m, almost 63 m, which is the value declared in the XBee manufacturer's datasheet. \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Nodes Location** & **RSSI** & **A** & \
\begin{tabular}{c} **Real** \\ **Distance** \\ \end{tabular} &
\begin{tabular}{c} **Value of** \\ \(n_{i}\) \\ \end{tabular} \\ \hline Inside a room (\(n_{1}\)) & \(-55\) & 40 dbm & 5 m & 2.17 \\ \hline In the hall (\(n_{2}\)) & \(-50\) & 40 dbm & 5 m & 1.44 \\ \hline From room to & \(-63\) & 40 dbm & 5 m & 3.33 \\ \hline From room to the & \(-60\) & 40 dbm & 5 m & 2.80 \\ \hline \hline \end{tabular}
\end{table} 
Table 7: The value of n in different scenarios. However, to send real data (temperature, humidity, and motion), the distance should be between 9 to 45 m depending on the intermediate space conditions between the sender and the receiver. The next Figure 9 presents the distance measurement compared to RSSI value. The RSSI goes down as the distance between the node and the gateway increases. The received signal strength is converted to RSSI, which is the ratio of the received power \(P_{r}\) to the reference power \(P_{ref}\) by the following Equation (3) [19]:  
\[\text{RSSI}=10^{*}\text{log}(P_{r}/P_{ref}) \tag{3}\]  
The ratio of the received power \(Pr\) can be expressed as follows [19]:  
\[P_{r}=P_{t}{}^{*}G_{t}{}^{*}G_{r}(\lambda/4^{*}\pi^{*}d) \tag{4}\]  
The parameters \(G_{t}\) and \(G_{r}\) are the gain of the transmitter and gain of the receiver. \(\lambda\) is the wavelength, and \(d\) is the distance between transmitter and receiver. The sensor network design and their performance evaluation presented in this section play a key role in the effective deployment of a sensor network that is energy efficient and operating effectively to provide data about the building's context. This information is then processed by the context-aware energy management system implemented at the building level. First, we will discuss the methodology we followed to model the context in buildings and then the implementation strategy using Finite State Machine, then present the real building implementation evaluation.