## 2 System Design  
The system presented in this section is a WSN comprised of several SunSPOT [10] nodes, a product manufactured by Oracle. It is an outcome from the authors participation in the European research project \"Design, Monitoring, and Operation of Adaptive Networked Embedded Systems\" (DEMANES). It aims at improving the overall energy consumption of the network while keeping communication reliability and computational resources usage among acceptable boundaries. As mentioned previously, communication reliability and energy consumption are some of the WSN key aspects that could prevent it from being suitable for CPS based applications. The software modules deployed in the SunSPOT nodes are based on the control system design that is depicted in Figure 1 and fully described in [9]. It accomplishes a self-adaptive system through two feedback control loops as suggested by [PERSON] _et al._, in [11]. A primary feedback control loop consists of tasks _TM1_, _TR1_ and _TA1_ in Figure 1 and manages the node transmission power considering both its real and targeted number of neighbors. A secondary feedback control loop consists of tasks _TM2_ and _TR2_ in Figure 1 and manages the node targeted number of neighbors considering the battery level. The objectives of each task are:  
* _TM1_ is run periodically at a frequency discussed in the following sections. It calculates the node targeted number of neighbors \(ND_{R}\) by adding the WSN optimal value \(\overline{ND}\) and the change to be applied \(\Delta_{nd}\) estimated by _TR2_, based on the battery level. Then samples the real number of  
Figure 1: Control system design for self-adapting the Wireless Sensors Networks (WSN) nodes transmission power considering the number of neighbors and the battery level. neighbors _ND_ using the node run-time environment, calculates the difference (\(e_{ND}\)) between the real and the targeted number of neighbors and decides if the _TR1_ must be triggered. * _TR1_ decides the change to be applied on the node transmission power so that the real and the targeted number of neighbors of the node become equals or quite similar. _TR1_ decision is driven by _FDM1_. _FDM1_ is a decision making function based on fuzzy logic, depicted in Figure 2b and briefly explained below. Finally _TR1_ is executed when _TM1_ considers appropriate. * _TA1_ effectively establishes the node transmission power based on the _TR1_ output. It is always run once _TR1_ finishes. \(\overline{CR_{0}}\) in Figure 1 is the initial value for the node transmission power. The _TR1_ consecutive outputs are increments or decrements that _TA1_ adds up to get the desired transmission power as a deviation from \(\overline{CR_{0}}\). The last building block in _TA1_ guarantees that the transmission power will be a value supported by the node run-time environment. * _TM2_ is run periodically at a frequency discussed in the following sections. It samples the node real battery level \(E\) using the node run-time environment, computes \(e_{E}\) as the difference between the critical battery level \(\overline{E_{cr}}\) and the real battery level and triggers _TR2_. * _TR2_ decides the change (\(\Delta_{nd}\)) to be applied to the WSN optimal number of neighbors \(\overline{ND}\), thus influencing _TM1_. The decision making process is driven by _FDM2_, a decision making function based on fuzzy logic depicted in Figure 2b and briefly explained below. _FDM1_ and _FDM2_ functions represent the input-output relationship of single input-single output decision-making functions based on fuzzy logic. To model a WSN and the appropriate response to any possible failure or change in the WSN environment is overwhelming, and fuzzy-based solutions are likely to provide optimal and feasible achievements. In [12], several algorithms for controlling a WSN topology are compared and those based on fuzzy-logic show a better trade-off between feasibility and communication reliability. The design of the functions were introduced in [9].