## 3 Wireless Sensor Networks
### System Design  
Two main strategies were employed to design low energy-consumption devices, possibly with a perpetual operation:  
* the circuit includes a power management stage that harvests, conditions and stores energy in a battery;
* during operation, the firmware shuts down unused components and sub-systems and, in periods with no action, takes the microcontroller into a deep-sleep state.  
A block diagram of an autonomous SPWS that harvests energy from the surrounding environment is shown in Figure 2. The energy related sub-system includes an energy transducer, an energy management circuit and a storage component, typically a battery. These blocks behave as a the power supply for the remaining circuitry of a wireless sensor: a radio transceiver, a microcontroller and the sensor.  
Mechanical, radiant, thermal, magnetic, or biochemical sources can be employed to harvest energy [25]. Considering the use of the SPWS in buildings, light is the form of energy employed and small size photovoltaic panels are used as the energy transducer. Since the harvested energy changes over time, the voltage level must be regulated. As there are periods when there is no light available, a capacitor or a battery is needed to store the energy, which can be employed later when needed [26; 27]. A 850 mAh lithium polymer battery is employed by the SPWS implemented.  
The energy management circuitry implements the functionalities of regulating voltage levels and selecting one of three modes of operation: powering from Universal Serial Bus (USB) port; a charging the battery while powering from the USB; or battery charging and powering.  
The SPWS circuit is developed around a Microchip (Microchip Technology Inc., Chandler, AZ, USA) XLP (eXtreme Low Power) microcontroller that supports sleep and deep-sleep states, enabling energy efficient design of the operational duty-cycle. The microcontroller is complemented by an IEEE 802.15.4 compatible transceiver to enable wireless transmission of data. Depending on the type of node, the microcontroller performs distinct tasks:  
* transmitter type: periodically reads sensor(s), communicates readings to the Radio-Frequency (RF) transceiver for transmission, and deep-sleeps until the next sampling time;  
Figure 2: Block diagram of an autonomous Self-Powered Wireless Sensors (SPWS) that extracts energy from the surrounding environment.  
receiver type: continuously receives datagrams from the RF transceiver, extracts the sensor data sent by a transmitter or repeater node, and sends it to an Ethernet connected device (a collector node) through the USB port;
* repeater type: continuously receives datagrams from the RF transceiver, changes the necessary addressing information, and communicates the new data packet for transmission by the RF transceiver.  
The SPWS can accommodate five different sensors that are low power digital integrated circuits or analogue devices that are powered for a very small time interval, ensuring consumption is compatible with the overall low power requirements.  
All the sensor data acquired by transmitter nodes at distinct parts of the buildings, has to be aggregated, processed and stored to become available to the HVAC MPC system. This is done by a collector node that employs a receiver node connected to a Raspberry (Raspberry Pi Foundation, Cambridge, UK) Pi model B+ computer via an USB Future Technology Devices International (FTDI) module. The collector node is connected to a common Ethernet or Wi-Fi network to transmit the WSN data to a database system for permanent storage, where it becomes available to the HVAC MPC system.  
In the following the components employed, their selection, and integration into the prototype are detailed.