Wireless Sensors and IoT Platform for Intelligent HVAC Control

Energy consumption of buildings (residential and non-residential) represents approximately 40% of total world electricity consumption, with half of this energy consumed by HVAC systems. Model-Based Predictive Control (MBPC) is perhaps the technique most often proposed for HVAC control, since it offers an enormous potential for energy savings. Despite the large number of papers on this topic during the last few years, there are only a few reported applications of the use of MBPC for existing buildings, under normal occupancy conditions and, to the best of our knowledge, no commercial solution yet. A marketable solution has been recently presented by the authors, coined the IMBPC HVAC system. This paper describes the design, prototyping and validation of two components of this integrated system, the Self-Powered Wireless Sensors and the IOT platform developed. Results for the use of IMBPC in a real building under normal occupation demonstrate savings in the electricity bill while maintaining thermal comfort during the whole occupation schedule.


Introduction
Due to fast economic development affected by industrialization and globalization, energy consumption has been steadily increasing [1].The three main economic sectors that consume a significant amount of energy are industry, transportation and buildings, with buildings accounting for the largest proportion.For example, in the USA, primary energy consumption in buildings is around 40% of total energy consumption, with 35% of the primary energy and 45% of electricity being consumed by Heating, Ventilating and Air Conditioning (HVAC) systems [2].
Model-Based Predictive Control (MBPC) is the technique of HVAC control [3][4][5][6][7] that offers the largest potential for energy savings.Despite the large number of publications on this topic, only a few report MBPC applications for existing buildings under normal occupancy conditions; one of the first was a previous work by the authors [8].To the best of our knowledge, the first attempt towards a marketable MBPC HVAC solution was presented in our recent work [9].
Despite the large economic advantages of MBPC for HVAC control, predictive control requires the use of additional sensors, namely for measuring variables related to the room's thermal comfort, and possibly external weather variables.Additionally, an Internet of Things (IoT) platform is required to implement all the necessary operations.The main objective of this paper is to present the design, implementation and testing of Self-Powered Wireless Sensors (SPWS) specially designed for home energy management applications, as well as the IoT platform developed, and their use in a real application of the Intelligent Model-Based Predictive Control scheme [9].This paper is organized as follows: in Section 2, an overview of the author's proposal for MBPC HVAC control, coined Intelligent MBPC HVAC (IMBPC HVAC) is presented.Section 3 discusses the design, prototyping and validation of the SPWSs, and their characterization in terms of energy consumption and autonomy.The IoT platform is introduced in Section 4. Experimental results are given in Section 5. A discussion section concludes the paper.

Hardware
IMBPC requires information about the external weather and the inside climate of the rooms under control, as well as their forecast over a Prediction Horizon (PH).As such, it needs devices for acquiring the variables needed to characterize the weather and the climate.While the latter will be described in the following section, we shall concentrate here on the measurement and forecast of global solar radiation (SR), atmospheric air temperature (TA) and relative humidity (RH).
For this purpose, the authors designed and tested an intelligent weather station [10], which, besides being energy-autonomous, offering wireless communications based on the IEEE 802.15.4 standard and measuring the three variables mentioned earlier, provides the forecasts of these variables over a user-specified PH.The sampling time, as well as the prediction interval, are user-defined, with the latter being a multiple of the former.
Two forecasting methods are available in the intelligent weather station: a nearest neighbour (NEN) algorithm and an artificial neural network (ANN)-based approach.The former is essentially a pattern matching algorithm, which searches, among d full days, for the closest (in the Euclidean sense) n neighbours, which will be averaged to compute the predictions [11].The execution of the NEN is completely local to the device.The ANN-based approach uses Radial Basis Function Neural Networks (RBFNNs), whose design is done externally by a Multi-Objective Genetic Algorithm (MOGA) [12].
For more information on the design, operation and results of the intelligent weather station, the reader is invited to consult [10].

Software
The current version of IMBPC assumes the existence of a Building Management System (BMS), able to measure and control the HVAC equipment.The software is composed of three major blocks: an interface to the BMS, a data acquisition module responsible for communicating with the intelligent weather station, the SPWS, and with the BMS interface module, and a control module, to execute model predictions, the MBPC algorithm, and the communication of the control actions to the BMS interface.These interfaces and the data acquisition use a small IOT platform, described in Section 4. The details of the control algorithm, as well as other results by IMBPC HVAC achieved in real-time control can be seen in [9], and are briefly summarized here.
The IMPBC HVAC approach assumes the existence of schedules for each room under control.
Denoting one occupation period by t oc = t os t oe , t os being the start of occupation, t oe its end, and by t op a time prior to t os , where the HVAC is turned on to ensure thermal comfort since the beginning of the occupation period, and by k os , k oe and k op , the corresponding sample indices assuming a user-specified constant sampling interval, the sequence of reference temperatures, , to be applied to the HVAC is given as the solution of: min . (1) Appl.Sci.2018, 8, 370 3 of 31 In Equation (1), v PH denotes the set of allowable control action sequences; in this case the control actions will be reference temperatures in degrees Celsius, or the value 0 that denotes that the HVAC is off.In order to enable the smooth operation of the system, each control action can only deviate by 3 • C around the previous control action, i.e., u J[i] is an estimate of the economic cost at the ith sample, and Θ[j] denotes the thermal comfort at sample j, and k+PH ∑ i=k+1 J[i] the total economic cost over PH.This way, we are determining the control sequence that minimizes, at each sample instant, the economic cost over a PH, ensuring that the thermal comfort over this PH is ensured.According to the receding horizon principle, only the first value of the optimal sequence will be applied to the HVAC system.Equation ( 1) is solved by a modified version of the Branch and Bound algorithm [13], previously applied by the authors on an energy-efficient HVAC MBPC pilot system [8].As a note, the time format used in this work is the complete date, plus hours, minutes and seconds.
In order to solve Equation (1), we need forecasts of the economic cost of each control action, within PH.This can be easily obtained by translating the estimated energy spent, at each step, into economic costs, using the tariffs used by each contract [14].Although different methods were tested, the easiest method for estimating the energy, in each step, is assigning the value of 0 to the situations where the HVAC is off, and a constant value, different from 0, to each period where the HVAC is on.
During recent years, HVAC control has gradually changed from dealing with temperature regulation to being about occupants' thermal comfort [6,8,9,[15][16][17], mainly due to the fact that temperature is not the only factor affecting thermal comfort and that a constant temperature is not required for humans to achieve thermal comfort, and to the consequent potential for energy savings.
Although different indices can be used to characterize the thermal sensation, Fanger's Predictive Mean Vote (PMV) is still the most used.It predicts the mean response (in a statistical sense) of the thermal sensation of a large group of people exposed to certain thermal conditions for a long time.The value of the PMV index is a seven-point thermal sensation scale, between −3 (cold) and +3 (hot), 0 being neutral [18].The classical way in which the PMV index (denoted here as Θ) can be computed was detailed in [19] and is dependent on six variables: metabolic rate (M r ), clothing insulation (I cl ), inside air temperature (TA i ), inside air relative humidity (RH i ), air velocity (V ai ), and mean radiant temperature (T r ).As the standard computation of PMV involves the solution of a nonlinear equation, with a high, non-constant, computation time, we have proposed the use of a static RBFNN to approximate the PMV, for specified values of M r , I cl , and V ai " denoted as a context vector in [20], that achieves a constant computation time at a desired accuracy/speed-up tradeoff.
This way, assuming that the RBFNN Θ models are designed off-line for the context vectors adequate to a specific installation (using tabulated values for M r -according to the use of each room, for I cl -according to the season and the geographical location, and for V ai , obtained from the equipment's specifications), the PMV can be estimated as: where f Θ (.) denotes the static RBFNN PMV model, for the specific context C = {M r , I cl , V a i }.
The forecasts of Θ (denoted as Θ[k + j]), over PH, can also be obtained by the f Θ (.) model, provided the forecasts of TA i , RH i and T r over PH are available, i.e., The measurements of TA i and RH i are easily performed by the SPWS devices, discussed later on.Measurement of T r is not so simple.The mean radiant temperature can be defined as the uniform temperature of an imaginary enclosure in which radiant heat transfer from the human body equals the radiant heat transfer in the actual non-uniform enclosure [18].It can be estimated using different methods [18]:

•
From the plane radiant temperature in six opposite directions, weighted according to the projected area factors for a person; • Or, using a black globe thermometer, which was the method used in a previous work [8].
As the latter solution is completely unaesthetic, the former approach is used here, which means that the temperature of the enclosures needs to be measured by the SPWS devices.
Regarding the forecasts of the three variables, they are obtained by dynamic RBNNs, implementing Nonlinear Auto Regressive models with eXogeneous inputs (NARX).Specifically, where {v[k]} denotes a set of delayed values of a generic variable v at instant k, whose number and delays need to be determined, M[k] denotes measured values of the movement detection signal in each room, which must be obtained by the SPWS devices, and TR[k] denotes the reference temperature to be applied to the HVAC.The inclusion of movement detection in f TA i (.) and f T r (.), models the influence of occupancy in these two models (for more details please see [14]).Taking for example Equation ( 4), the inside air temperature TA i , at instant k, depends on delayed values of the same variable, and delayed values of the exogeneous variables inside relative humidity, external air temperature, solar radiation, HVAC reference temperature and movement.
The models above are also RBFNN models, whose design is achieved by a MOGA model design framework.The MOGA-based model design framework is composed of an evolutionary algorithm and a derivative-based algorithm.The evolutionary part searches the admissible space of the number of neurons and the number of inputs (which in this case are lags for the modelled and exogenous variables) for the RBFNN models.Before being evaluated by the genetic algorithm, each model has its parameters determined by a Levenberg-Marquardt algorithm [21,22], minimizing an error criterion that exploits the linear-nonlinear relationship of the RBF NN model parameters [23,24].For more details on the MOGA model identification framework, please see, for instance [12].Models (4) to (6) are iterated over PH to obtain the forecasts of these three variables.Notice that, dependent on the prediction step and the delays for each exogenous variable, forecasted variables may be used as inputs instead of measured variables.
The last predictive model that needs to be referenced is the one used for movement detection, denoted by f M (.), used to estimate the influence of occupation in Equations ( 4) and (6).Assuming the existence of schedules, the forecast of movement throughout PH at each instant will be a constant value, obtained as the exponential weighted average value of the movement signal, from the start of the schedule until the corresponding sample.
Figure 1 illustrates, schematically, the IMBPC HVAC approach.As can be seen, it needs measurement (thin lines) of weather variables (orange enclosure) and inside climate variables (blue enclosure).The intelligent weather station computes the forecasts (thick lines in dark blue, red and grey) of the weather variables over PH.The inside climate variables, as well as the movement signal, are acquired by the SPWS, and a local computer is used to obtain the forecasts of these variables (thick lines, blue, dark red, black and green).The forecast of the climate variables is applied to the static PMV model, to obtain the forecasts of Θ (thick, yellow).These will used as restrictions for the optimization problem (1), which will compute the optimal reference temperature sequence (thick brown line), that minimizes the economic cost of all admissible sequences, for the specified schedule, using for that the branch-and-bound algorithm.
brown line), that minimizes the economic cost of all admissible sequences, for the specified schedule, using for that the branch-and-bound algorithm.

Wireless Sensor Networks
As mentioned before, the climate variables, movement signal, walls temperature, and additionally the state (open/closed) of windows and doors is measured by a Wireless Sensor Network.In previous work this has been accomplished by the Tmote Sky WSN platform [23,25], connected to the required sensors.This platform, as well as most commercial off-the-shelf WSN (wireless sensor network) solutions, is not appropriate for this specific application due to several reasons: • economic: they are not cheap, in particular for large deployments; • redundancy: their general-purpose nature drove the design to include many unnecessary components for specific applications; • energy consumption: energy consumption would need too frequent battery replacement or hardwiring to the electric network; • maintenance: changing batteries in large installations is unfeasible; • engineering: a significant amount of work is required to integrate specific sensors; wiring for power restricts available placement locations; • ergonomic: the nodes are too large for integration with the required components.
In order to solve the above issues, the objective here is to design, implement and test WSN nodes in which:

Wireless Sensor Networks
As mentioned before, the climate variables, movement signal, walls temperature, and additionally the state (open/closed) of windows and doors is measured by a Wireless Sensor Network.In previous work this has been accomplished by the Tmote Sky WSN platform [23,25], connected to the required sensors.This platform, as well as most commercial off-the-shelf WSN (wireless sensor network) solutions, is not appropriate for this specific application due to several reasons: • economic: they are not cheap, in particular for large deployments; • redundancy: their general-purpose nature drove the design to include many unnecessary components for specific applications; • energy consumption: energy consumption would need too frequent battery replacement or hardwiring to the electric network; • maintenance: changing batteries in large installations is unfeasible; • engineering: a significant amount of work is required to integrate specific sensors; wiring for power restricts available placement locations; • ergonomic: the nodes are too large for integration with the required components.
In order to solve the above issues, the objective here is to design, implement and test WSN nodes in which:

•
to avoid wiring for power or having to periodically change batteries, energy should be harvested from the environment and stored in a battery; • to enable easy and aesthetically pleasant installations in larger types of spaces typically found in buildings, their size should be small; • to reduce the size and decrease the energy consumption, only the necessary components should be used, employing Ultra Low Power (ULP) components whenever possible; • to allow a viable and marketable product that promotes the energy efficiency of buildings, they should be cheap to produce.
Besides the advantage of being autonomous, these nodes permit installation in existing buildings and homes without requiring infrastructure changes and unpleasant, undesirable wiring.Three different types of devices were created (Receiver, Repeater and Transmitter).

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.
Appl.Sci.2018, 8, x FOR PEER REVIEW 6 of 31 • to avoid wiring for power or having to periodically change batteries, energy should be harvested from the environment and stored in a battery; • to enable easy and aesthetically pleasant installations in larger types of spaces typically found in buildings, their size should be small; • to reduce the size and decrease the energy consumption, only the necessary components should be used, employing Ultra Low Power (ULP) components whenever possible; • to allow a viable and marketable product that promotes the energy efficiency of buildings, they should be cheap to produce.
Besides the advantage of being autonomous, these nodes permit installation in existing buildings and homes without requiring infrastructure changes and unpleasant, undesirable wiring.Three different types of devices were created (Receiver, Repeater and Transmitter).

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; 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; • 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.

Transceiver
The RF transceiver is the component that requires more energy in the SPWS.It was chosen on the basis of some characteristics, the most important being the reception and transmission current consumptions, the transmission range, the requirements for integration with a microcontroller, and the price.The devices initially considered, presented in Table 1, are provided by different manufacturers and use different approaches, each denoted by a different background colour: radio Integrated Circuits (IC) (pink); System-on-Chip (SOC) with radio and microcontroller (white); integrated modules with a SOC, crystal, and antenna (green), and; integrated modules with an RF IC, crystal and antenna (no microcontroller) (yellow).
Figure 3 shows the current consumption (values obtained from the datasheets), when the radio frequency transceivers are employed with the maximum power transmission.
Appl.Sci.2018, 8, x FOR PEER REVIEW 7 of 31 • 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.

Transceiver
The RF transceiver is the component that requires more energy in the SPWS.It was chosen on the basis of some characteristics, the most important being the reception and transmission current consumptions, the transmission range, the requirements for integration with a microcontroller, and the price.The devices initially considered, presented in Table 1, are provided by different manufacturers and use different approaches, each denoted by a different background colour: radio Integrated Circuits (IC) (pink); System-on-Chip (SOC) with radio and microcontroller (white); integrated modules with a SOC, crystal, and antenna (green), and; integrated modules with an RF IC, crystal and antenna (no microcontroller) (yellow).
Figure 3 shows the current consumption (values obtained from the datasheets), when the radio frequency transceivers are employed with the maximum power transmission.Table 1.List of RF (Radio-Frequency) devices considered for the prototype.Radio Integrated Circuits (IC) (pink); System-on-Chip (SOC) with radio and microcontroller (white); integrated modules with a SOC, crystal, and antenna (green), and; integrated modules with an RF IC, crystal and antenna (no microcontroller) (yellow).Due to their low consumptions, the Nordic (Nordic Semiconductors, Oslo, Norway) devices were considered in a first instance, but they were soon discarded as they were not 802.15.4 compliant.Considering the low-power consumption objective for the SPWS, other devices with current consumption above 28 mA were also excluded.The Microchip MRF24J40MA device was chosen among the remaining candidates, as it achieved a good compromise between price, current consumption, integration requirements, and transmission range.The current consumption in receiving mode was not deemed a decisive factor for this particular application because the receiver type of node is always connected to a computational system that powers it via USB port.

Atmel
The IMBPC HVAC and thermal control product considers the use of repeater nodes to minimize the probability of losing data packets.As such, acknowledgment frames to confirm the reception of packets with sensor data, are not required.Consequently, this enables using the 802.15.4 standard non-beacon mode, which contributes to the preservation of battery charge.
To a great extent, the selection of the MRF24J40MA was made by considering the easiness of integration and development with the Microchip XLP microcontroller family.This also helped with narrowing the microcontroller alternatives.

Microcontroller
The selection of the MRF24J40MA module limits the microcontroller selection to devices including a Serial Peripheral Interface (SPI).In this case, the family of Microchip PIC microcontrollers becomes a natural choice, given the set of hardware/software tools that allow fast and efficient development and integration of those microcontrollers and 802.15.4 modules.The selection was a PIC18F46J50, which is a small, low-cost, 8-bit microcontroller from the Microchip XLP family used in Microchip 802.15.4 evaluation and development kits.Furthermore, its use enables the opportunity to employ available programming libraries provided with the kits.It also has USB 2.0 integrated, a deep sleep mode, and 13 10-bit ADC channels with 10-bit resolution, among other features.Although this microcontroller includes an internal clock, for precision reasons an external 8 MHz quartz crystal oscillator is used in the SPWS.

Temperature and Relative Humidity Sensor
The Silicon Labs (Silicon Labs, Austin, TX, USA) Si7021; and Sensirion (Sensirion, Stafa, Switzerland) SHT2 sensors were considered for the measurement of air temperature and relative humidity: In both, the two variables are measured by the same device, allowing a decrease in the PCB (printed circuit board) size.Other factors taken into account in the selection were the accuracy and energy consumption.Among the two sensors the Si7021 was chosen, since it presented smaller energy consumption, and its design had already HVAC applications in mind.It uses an I 2 C bus for communication with the microcontroller, requiring only two pins besides VDD and GND: SCL (a serial clock line) and DATA (a serial data line).The digitized temperature and relative humidity values provided by the sensor must be converted to the corresponding units using Equations ( 7) and ( 8): where TA i ( • C) and RH i (%) are the air temperature and relative humidity given in degrees Celsius and percentage, respectively, and T s and RH s are the 16-bit words given by the device.The accuracy values for temperature and for relative humidity are ±0.4 • C and ±3%, respectively.With the goal of preserving the battery charge, the required computations are offloaded to the collector or storage nodes, which means the WSN transmits the 16-bit words given by the device.
To shorten the acquisition time and therefore decrease consumption energy, the VDD, DATA and SCL pins were implemented by means of general I/O pins programed in the microcontroller firmware.This enables using shorter I 2 C clock periods, therefore allowing faster operation that consequently requires less energy.

Room Activity Sensor
A Passive Infra-Red (PIR) motion sensor was used to detect movement in rooms.The Panasonic EKMC1601111 sensor was selected, as it presents a good compromise between size, current consumption (170 µA) and 30 s of warm-up time.This component is easily attached to the microcontroller, requiring a single pin to read the sensor output (high for movement, ground otherwise).
The room activity is then obtained as the fraction of samples for which the output pin is in a high state, in each minute.

Door/Window State Sensor
Magnetic reed switch sensors were employed to detect the state (open or closed) of windows and doors.Two devices were tested: Comus S1372 and Hamlin 59150-030.The latter was chosen due to its price and easiness of mounting on a surface.

Wall Temperature Sensor
As mentioned before, the MRT is estimated employing measurements of wall temperatures.A common PT1000 surface contact temperature sensor is used, which shows very good resistance linearity with temperature.A Wheatstone bridge and amplifier circuit (Texas Instruments INA126UA [28] instrumentation amplifier) was employed to scale its terminals differential voltage to the microcontroller's ADC input range.
The wall temperature is then obtained as: where R PT1000 is the sensor resistance sampled by the microcontroller's ADC, and R0 PT100 is a baseline resistance of 1000 Ohms, obtained by the PT1000 at 0 • C. To provide accuracy within 0.5 • C, all sensors were calibrated.Calibration was performed by means of the SHT25 sensor (accuracy within 0.4 • C), dipped in glycerin with PT1000 sensors.After recording a number of temperatures, linear regression was used to find the calibration factor to apply.
As for the Si7021 sensor, the WSN transmits the 10-bit word corresponding to the ADC quantization, leaving all the required computations to be done at the collector or storage nodes, therefore preserving the battery charge.

Light Sensor
The last sensor incorporated in the SPWS PCB was a N5AC-50108 photo-resistor from Low Power Radio Solutions (LPRS) [29].Accuracy was not a factor when selecting it, since the sensor is employed to enable an energy conservation strategy and not to provide accurate measurements.By detecting if the room is not illuminated, the SPWS firmware can implement a policy used when the room is not being used.In this case battery charge can be preserved, by interrupting the periodic sensor data transmission for a given amount of time.Such a policy may become of great relevance for the movement detection sensor, as it is the element that consumes the largest amount of energy.Despite its low resolution, the photo-resistor can also be used to measure illuminance within a given space, by calibrating the typical non-linear relation between illuminance and resistance with the parameters given in the sensor datasheet.As already mentioned, the power management circuit supports three modes of operation: powering from a USB; charging the battery while powering from the USB, or battery charging and powering.A Solems (Solems, Palaiseau, France) 10/072/048 Photovoltaic Panel (PV) built with amorphous substrate is used or energy harvesting.This PV is very appropriate for indoor operations, as it is able to convert light into current even in low-light environments (20-100 Lux).
The power supply must be constant at 3.3 volts, as the major components work at this voltage.A step-up boost converter or a step-down converter can be used to accomplish this, when using a solar panel.As the step-up boost converter needs a high current, and the use of a step-down converter allows for using a lithium battery with higher load capacity and lighter properties, the latter approach was employed.A block diagram of the SPWS power management circuit is shown in Figure 4.As already mentioned, the power management circuit supports three modes of operation: powering from a USB; charging the battery while powering from the USB, or battery charging and powering.A Solems (Solems, Palaiseau, France) 10/072/048 Photovoltaic Panel (PV) built with amorphous substrate is used or energy harvesting.This PV is very appropriate for indoor operations, as it is able to convert light into current even in low-light environments (20-100 Lux).
The power supply must be constant at 3.3 volts, as the major components work at this voltage.A step-up boost converter or a step-down converter can be used to accomplish this, when using a solar panel.As the step-up boost converter needs a high current, and the use of a step-down converter allows for using a lithium battery with higher load capacity and lighter properties, the latter approach was employed.A block diagram of the SPWS power management circuit is shown in Figure 4.The step-down 1 and 2 blocks are implemented by a Microchip MCP1700T-33 [30] and a Texas Instruments (Texas Instruments, Dallas, TX, USA) TPS79901 [31] low quiescent current voltage regulators, respectively.
A simple configuration with two jumpers (J1 and J2) is used to select the power management mode of operation.Powering from the USB is achieved by opening J1 and closing J2.In this case the power supply is regulated first by step-down 2 and then by step-down 1, which feeds the SPWS.By closing both jumpers, allows us to simultaneously charge the battery and power the SPWS.Finally, in the case that J1 is closed and J2 open, the third mode of operation is obtained, as the battery is connected to the input of the MCP1700 step-down, whose output is used to provide the voltage regulation for the SPWS circuit.To prevent battery current dissipation by the PV or by the step-down 2 component, the two diodes D1 and D2 are used.

Prototyping SPWS
Before the production of the final SPWS, both the hardware and software were prototyped.This section details how the partial prototypes were implemented, and shows the final SPWS design.

Hardware
To validate the design options, a first prototype was built with discrete components, consisting of two breadboards.The first breadboard included all the components needed for packet transmission and the other one with all the sensors and the auxiliary components.
Following these preliminary circuit validation and functional tests, a PCB prototype was implemented as shown in Figure 5.The step-down 1 and 2 blocks are implemented by a Microchip MCP1700T-33 [30] and a Texas Instruments (Texas Instruments, Dallas, TX, USA) TPS79901 [31] low quiescent current voltage regulators, respectively.
A simple configuration with two jumpers (J1 and J2) is used to select the power management mode of operation.Powering from the USB is achieved by opening J1 and closing J2.In this case the power supply is regulated first by step-down 2 and then by step-down 1, which feeds the SPWS.By closing both jumpers, allows us to simultaneously charge the battery and power the SPWS.Finally, in the case that J1 is closed and J2 open, the third mode of operation is obtained, as the battery is connected to the input of the MCP1700 step-down, whose output is used to provide the voltage regulation for the SPWS circuit.To prevent battery current dissipation by the PV or by the step-down 2 component, the two diodes D1 and D2 are used.

Prototyping SPWS
Before the production of the final SPWS, both the hardware and software were prototyped.This section details how the partial prototypes were implemented, and shows the final SPWS design.

Hardware
To validate the design options, a first prototype was built with discrete components, consisting of two breadboards.The first breadboard included all the components needed for packet transmission and the other one with all the sensors and the auxiliary components.
Following these preliminary circuit validation and functional tests, a PCB prototype was implemented as shown in Figure 5.The RF transceiver module may be easily identified by the red circuit, and the microcontroller, crystal, USB port, as well as connectors for the battery and photovoltaic panel, are easily identifiable.The board measures 50 × 37 mm.
To accommodate the printed circuit board and the battery, as well as the sensors, an enclosure was modelled and printed in a 3D printer.Figure 6 illustrates the design that was followed.It includes many small holes for air circulation, mounting points for the sensors and PV panel, and an access point for the USB connector.The RF transceiver module may be easily identified by the red circuit, and the microcontroller, crystal, USB port, as well as connectors for the battery and photovoltaic panel, are easily identifiable.The board measures 50 × 37 mm.
To accommodate the printed circuit board and the battery, as well as the sensors, an enclosure was modelled and printed in a 3D printer.Figure 6 illustrates the design that was followed.It includes many small holes for air circulation, mounting points for the sensors and PV panel, and an access point for the USB connector.The RF transceiver module may be easily identified by the red circuit, and the microcontroller, crystal, USB port, as well as connectors for the battery and photovoltaic panel, are easily identifiable.The board measures 50 × 37 mm.
To accommodate the printed circuit board and the battery, as well as the sensors, an enclosure was modelled and printed in a 3D printer.Figure 6 illustrates the design that was followed.It includes many small holes for air circulation, mounting points for the sensors and PV panel, and an access point for the USB connector.Figure 7 shows an open SPWS, with the battery and the PCB, and in the right side a sensor mounted on a wall is shown, where the LDR is visible in the lower part of the enclosure.

Software
For developing and debugging software for the family of Microchip microcontrollers the MPLAB X IDE application is recommended.It was used to implement three firmware versions, one for each type of node: transmitter; receiver and repeater.
To minimize the energy consumption, the transmitter device uses the following sequence of actions: sets the microcontroller initial configuration; acquires the sensors values; configures the SPI pins; turns on the MRF24J40MA module and configures the radio (Personal Area Network (PAN), Channel, and Source); loads the MRF24J40 radio registry with data to transmit; transmits the data; waits for the TX interrupt pin; switches off the RF module; and puts the device in deep sleep mode.
On the receiver node, the sequence of operations is: sets the microcontroller initial configuration; sets USART communication; configures the microcontroller SPI pins; configures the MRF24J40 radio; executes the following cycle waiting for transmitter's data: activates the RX interrupt pin; reads the MRF24J40 data; sends data to the repeater collector; and turns ON the interrupts.Figure 7 shows an open SPWS, with the battery and the PCB, and in the right side a sensor mounted on a wall is shown, where the LDR is visible in the lower part of the enclosure.

Software
For developing and debugging software for the family of Microchip microcontrollers the MPLAB X IDE application is recommended.It was used to implement three firmware versions, one for each type of node: transmitter; receiver and repeater.
To minimize the energy consumption, the transmitter device uses the following sequence of actions: sets the microcontroller initial configuration; acquires the sensors values; configures the SPI pins; turns on the MRF24J40MA module and configures the radio (Personal Area Network (PAN), Channel, and Source); loads the MRF24J40 radio registry with data to transmit; transmits the data; waits for the TX interrupt pin; switches off the RF module; and puts the device in deep sleep mode.
On the receiver node, the sequence of operations is: sets the microcontroller initial configuration; sets USART communication; configures the microcontroller SPI pins; configures the MRF24J40 radio; executes the following cycle waiting for transmitter's data: activates the RX interrupt pin; reads the MRF24J40 data; sends data to the repeater collector; and turns ON the interrupts.

Software
For developing and debugging software for the family of Microchip microcontrollers the MPLAB X IDE application is recommended.It was used to implement three firmware versions, one for each type of node: transmitter; receiver and repeater.
To minimize the energy consumption, the transmitter device uses the following sequence of actions: sets the microcontroller initial configuration; acquires the sensors values; configures the SPI pins; turns on the MRF24J40MA module and configures the radio (Personal Area Network (PAN), Channel, and Source); loads the MRF24J40 radio registry with data to transmit; transmits the data; waits for the TX interrupt pin; switches off the RF module; and puts the device in deep sleep mode.
On the receiver node, the sequence of operations is: sets the microcontroller initial configuration; sets USART communication; configures the microcontroller SPI pins; configures the MRF24J40 radio; executes the following cycle waiting for transmitter's data: activates the RX interrupt pin; reads the MRF24J40 data; sends data to the repeater collector; and turns ON the interrupts.
Finally, the repeater node executes the following operation: sets the microcontroller initial configuration; configures SPI pins; turns on the MRF24J40MA module; configures the MRF24J40 radio; executes the following cycle waiting for transmitter's data: activates the RX interrupt pin; reads the MRF24J40 data; loads the MRF24J40 radio registry with data to transmit; transmits the data; and waits on the TX interrupt pin.
As already mentioned, all information is sent using the format provided by the digital sensors or the ADC, to decrease the transmission energy consumption.Conversion to physical variables units is performed on the repeater device.

SPWS Validation
In a first step, the SPWS devices were tested in terms of packet loss.It was verified that within the expected range of communication, the reception was almost perfect, making a more detailed analysis unnecessary for the purpose being considered.Additionally, the door and windows state detection as well as the PIR motion detection were checked for correct functionality, having shown correct operation.Another validation was made in terms of the temperature and relative humidity data acquired by various SPWSs, by relating it to data acquired by the Tmote Sky-based sensors that were employed in previous work.
The Tmote Sky-based sensors, previously used, were enclosed in a large box with plenty of air circulation.The size of the box is clearly too large, therefore it is not acceptable for an MPC-based HVAC and thermal comfort product.9) and relative humidity (Figure 10) inside a room in a period of 24 h.
Analysing Figure 9, there is clearly an offset of around 1.5 • C between the two different devices, although the trend is the same among the two types of devices.A possible explanation lies in the fact that the Tmote temperature conversion equation depends on the power supply employed and, as the factor for 3.3 V power supply was not available in the SHT11 datasheet, the 3 V factor was employed.It should also be noted that, in another experiment, the SI7021 sensor employed in the SPWS was compared to the new Sensirion SHT25 sensor.Very similar measurements were obtained, in accordance with the accuracy specified in the data sheets.
Among the SPWS devices good measurement agreement was obtained.It should also be noticed that no significant difference is obtained between the measurements made by sensors inside (device 3) or outside (device 1) the box, validating the air circulation in the sensor area of the PCB.Finally, the repeater node executes the following operation: sets the microcontroller initial configuration; configures SPI pins; turns on the MRF24J40MA module; configures the MRF24J40 radio; executes the following cycle waiting for transmitter's data: activates the RX interrupt pin; reads the MRF24J40 data; loads the MRF24J40 radio registry with data to transmit; transmits the data; and waits on the TX interrupt pin.
As already mentioned, all information is sent using the format provided by the digital sensors or the ADC, to decrease the transmission energy consumption.Conversion to physical variables units is performed on the repeater device.

SPWS Validation
In a first step, the SPWS devices were tested in terms of packet loss.It was verified that within the expected range of communication, the reception was almost perfect, making a more detailed analysis unnecessary for the purpose being considered.Additionally, the door and windows state detection as well as the PIR motion detection were checked for correct functionality, having shown correct operation.Another validation was made in terms of the temperature and relative humidity data acquired by various SPWSs, by relating it to data acquired by the Tmote Sky-based sensors that were employed in previous work.
The Tmote Sky-based sensors, previously used, were enclosed in a large box with plenty of air circulation.The size of the box is clearly too large, therefore it is not acceptable for an MPC-based HVAC and thermal comfort product.Figure 8 9) and relative humidity (Figure 10) inside a room in a period of 24 h.
Analysing Figure 9, there is clearly an offset of around 1.5 °C between the two different devices, although the trend is the same among the two types of devices.A possible explanation lies in the fact that the Tmote temperature conversion equation depends on the power supply employed and, as the factor for 3.3 V power supply was not available in the SHT11 datasheet, the 3 V factor was employed.It should also be noted that, in another experiment, the SI7021 sensor employed in the SPWS was compared to the new Sensirion SHT25 sensor.Very similar measurements were obtained, in accordance with the accuracy specified in the data sheets.
Among the SPWS devices good measurement agreement was obtained.It should also be noticed that no significant difference is obtained between the measurements made by sensors inside (device 3) or outside (device 1) the box, validating the air circulation in the sensor area of the PCB.
For relative humidity (Figure 10), only slight differences for the sensors inside the boxes are obtained, perhaps due to the boxes isolation, a similar trend being achieved among all sensors.The maximum offset among the SPWS devices is around 4%, perfectly within the accuracy margin specified for the sensor.This means that also for relative humidity, the sensor developed may be used inside the box to provide reliable relative humidity measurements.

Energy Harvesting and SPWS Perpetual Operation
For a battery powered device that employs energy harvesting with the objective of obtaining perpetual autonomous operation, there is one rule that must be satisfied, in average, within a given period of time: the amount of energy harvested must be larger than the energy consumed.Several tests were conducted to determine the conditions in which this rule is satisfied for the SPWS transmitter nodes.

Energy Harvesting and SPWS Perpetual Operation
For a battery powered device that employs energy harvesting with the objective of obtaining perpetual autonomous operation, there is one rule that must be satisfied, in average, within a given period of time: the amount of energy harvested must be larger than the energy consumed.Several tests were conducted to determine the conditions in which this rule is satisfied for the SPWS transmitter nodes.For relative humidity (Figure 10), only slight differences for the sensors inside the boxes are obtained, perhaps due to the boxes isolation, a similar trend being achieved among all sensors.The maximum offset among the SPWS devices is around 4%, perfectly within the accuracy margin specified for the sensor.This means that also for relative humidity, the sensor developed may be used inside the box to provide reliable relative humidity measurements.

Energy Harvesting and SPWS Perpetual Operation
For a battery powered device that employs energy harvesting with the objective of obtaining perpetual autonomous operation, there is one rule that must be satisfied, in average, within a given period of time: the amount of energy harvested must be larger than the energy consumed.Several tests were conducted to determine the conditions in which this rule is satisfied for the SPWS transmitter nodes.

Average Energy Harvested
It was first determined the average current produced by the PV panel employed, under a range from 500 to at least 2500 Lux, typically found in room buildings.Ten equal panels were subject to different illuminance levels (637, 1493, 1998 and 2492 Lux) and the average instantaneous currents produced are shown in Figure 11; the average values are represented by the thicker line and were 185.3, 264.2, 321.6 and 382 µA.Assuming that this is maintained during only 8 h per day, the average production for the illuminance values considered will decrease to 61.It was first determined the average current produced by the PV panel employed, under a range from 500 to at least 2500 Lux, typically found in room buildings.Ten equal panels were subject to different illuminance levels (637, 1493, 1998 and 2492 Lux) and the average instantaneous currents produced are shown in Figure 11; the average values are represented by the thicker line and were 185.3, 264.2, 321.6 and 382 µA.Assuming that this is maintained during only 8 h per day, the average production for the illuminance values considered will decrease to 61.8, 88.1, 107.2 and 127.3 µA.

SPWS Energy Consumption
For the next battery of tests, a fully integrated SPWS, as shown in Figure 7 (right), was employed, with the PV panel removed to guarantee that the current used was coming only from the battery.The calculations shown subsequently were based on an application note available from Jennic Company [32].For all sensors, except for the room activity sensor, as soon as the radio transmits a packet, the microcontroller enters deep sleep mode, and the current drawn becomes constant, equal to 7 µA.The tests employed duty cycles of 34 and 135 s.As an example, the current consumed during the active part of the duty cycle of a doors/windows state sensor is presented in Figure 12.

SPWS Energy Consumption
For the next battery of tests, a fully integrated SPWS, as shown in Figure 7 (right), was employed, with the PV panel removed to guarantee that the current used was coming only from the battery.The calculations shown subsequently were based on an application note available from Jennic Company [32].For all sensors, except for the room activity sensor, as soon as the radio transmits a packet, the microcontroller enters deep sleep mode, and the current drawn becomes constant, equal to 7 µA.The tests employed duty cycles of 34 and 135 s.As an example, the current consumed during the active part of the duty cycle of a doors/windows state sensor is presented in Figure 12.
The boxes aside the instants marked with a square show the consumption at instants that are used to divide the graph into sections.Assuming a constant current in each section, the average power consumption during a given section can be obtained as: where I sec is the current of the section concerned, t sec is the section duration, and t total is the total time of a whole duty cycle.The consumption profiles are similar for all the sensors except for the room activity sensor.As this sensor has to be powered during its 30 s warm-up delay, it draws more current during the deep-sleep period.This way, the existence or absence of movement will cause different consumption during this period.Movement is measured at 2.1 s intervals during 30 interrupts and on the 30th, transmission is done.

SPWS Energy Consumption
For the next battery of tests, a fully integrated SPWS, as shown in Figure 7 (right), was employed, with the PV panel removed to guarantee that the current used was coming only from the battery.The calculations shown subsequently were based on an application note available from Jennic Company [32].For all sensors, except for the room activity sensor, as soon as the radio transmits a packet, the microcontroller enters deep sleep mode, and the current drawn becomes constant, equal to 7 µA.The tests employed duty cycles of 34 and 135 s.As an example, the current consumed during the active part of the duty cycle of a doors/windows state sensor is presented in Figure 12.To compensate for the insufficient data resolution at low values, and the fluctuation in each section, an upper bound value was determined for each section.This means that the consumption values assume a worst case scenario.By using this assumption and the calculations shown above, the average current consumption for each transmitter type SPWS over a duty cycle is presented in Table 2.The activity detection sensor is the one demanding more energy, followed by the temperature and relative humidity sensor, the wall temperature sensor, and finally the doors/windows state sensor.By using the battery capacity (850 mAh), the sensor life time can be estimated.For the wall temperature and door/window sensors, using simple calculations harvested (850 mAh/18.9µA ≈ 44,270.8h ≈ 1844.6 days ≈ 5.1 years), we conclude that it can operate approximately during five years without the PV panel.Using similar calculations, we can estimate that life time of the temperature and relative humidity sensor is approximately three years, whereas the motion detection sensor achieves 112 days with permanent movement, or 224 days with no movement.As indicated before, a photo resistor was added to the SPWS to enable a software policy aiming to decrease the activity sensor use in periods that the rooms are not being used, and consequently the energy consumed.

Battery Charging in Research Room
In a subsequent test, the Solems PV panel was connected to the lithium polymer battery.The current supplied to the battery was measured with an ammeter and the room illuminance by an Avago Technologies APDS-9007 sensor [33].The charging circuit is this way a closed loop containing the PV panel, a diode, the ammeter and the battery, all connected in series in this order.The relation between current and illuminance is given by: where I OUT is the current measured at the sensor output and L is the corresponding illuminance.
A ground floor working room, with 6 by 3 by 3 m was used to measure the panel output current, shown in Figure 13, and the illuminance, shown in Figure 14, for a 24-h summer period.The room has a window facing north that receives shading by a number of pine trees, and very small windows facing south near the ceiling.
The test was executed on the 2 June 2015, and started at 14:46:32, in broad daylight.Analysing both figures it can be noticed that the highest peak occurs at around 15:36:00, with 110 µA for 900 Lux.From 20:40 until 6:30, due to the absence of light, the panel output is zero.Due to the opening or closing of the window shutter, four periods where a sudden large increase or decrease occurs can be identified.A pair of these occurrences occurs at lunchtime, when the current is generated using the small illuminance entering the small windows facing south.
The average current presented in Figure 13 was 27.4 µA, corresponding to an average illuminance value of 198.8 Lux.Even with this very low and not recommended illuminance level, the majority of the sensors are able to operate perpetually.Only the air temperature and relative humidity with a sampling time of 34 s and the activity sensor, without the energy-saving policy, would not achieve that goal.The test was executed on the 2 June 2015, and started at 14:46:32, in broad daylight.Analysing both figures it can be noticed that the highest peak occurs at around 15:36:00, with 110 µA for 900 Lux.From 20:40 until 6:30, due to the absence of light, the panel output is zero.Due to the opening or closing of the window shutter, four periods where a sudden large increase or decrease occurs can be identified.A pair of these occurrences occurs at lunchtime, when the current is generated using the small illuminance entering the small windows facing south.Panel output current (µA)   The average current presented in Figure 13 was 27.4 µA, corresponding to an average illuminance value of 198.8 Lux.Even with this very low and not recommended illuminance level, the majority of the sensors are able to operate perpetually.Only the air temperature and relative humidity with a sampling time of 34 s and the activity sensor, without the energy-saving policy, would not achieve that goal.

IoT Platform
An IoT Platform should maintain a list of devices and key metadata information about them in order to offer data streams for IoT applications.It should also be possible to configure these devices, change operational settings, upgrade their software remotely, querying the status and support reporting of any error conditions.According to Saverio Romeo, Principal Analyst at Beecham Research, there are more than 300 IoT platforms today [34].We decided not to use one of these platforms, but to improve an existing one [8], as it already had facilities to implement model predictions and predictive control.

Interface with the BMS
The first problem was to derive an interface to the existing BMS, which was a Schneider TAC Vista 4. The BMS connects to the HVAC systems by a LonWorks communication bus.The existent TAC Vista license supports only DDE client communication, and not an OPC interface, as modern BMS do.This way, the interface implemented used DDE services, but is easily configurable to use an OPC server.To acquire data from the BMS and to write data in the BMS, two DDE objects, a data acquisition and a control objects were implemented in Python, as message queue servers.Subsequently, this interface involved to a Gateway [35], available commercially.It has multiple input interfaces: Radio (Xbee-802.15.4,Microchip-802.15.4,Xbee-ZigBee, Xbee-ZigBee Pro, Xbee-868, Wi-Fi, Bluetooth 4.0 or Pro, LoraWan, Lora 868), Ethernet (SNMP, ModBus), and outputs messages to message queues, Json or FTP servers, whether by Ethernet or 3 G/4 G.

The Platform
The IoT platform considers different types of objects: maps (pdf or png files, with zoom capability), locations (objects that can be referenced by a GPS system), entities (groups of sensors and/or actuators), sensors (uniquely identified devices that can measure a specific variable, which have a specified type and properties), sensor units and symbols, users and groups, alerts with types and schedules, and units of time.Sensor values are stored in the table sensor values, actuator values in control values, and predicted values in the table predicted values.Different prediction methods are available, which have to be configured according to the model type (static mappings, NAR or NARX models, and corresponding lags).The structure of the database is shown in Figure 15.Regarding the communication structure, a message queue system is employed.Basically, for a data acquisition operation, the origin client tries to send the message (in this case the values acquired) to a central server.If it is not working, the system stores the message in a data file.Whenever it is possible to send acquired data, it is sent to the central server, and subsequently all previous messages that could not be sent and have been stored.The same system is used to transmit logs and alerts.It should be noted that, together with the content and the identification of the origin, the messages also contain the time stamp when the content was generated.

Web Application
A web application was developed to use the IoT system, and it will be briefly shown here.Figure 16 shows the panel to introduce a new sensor type.

Web Application
A web application was developed to use the IoT system, and it will be briefly shown here.Figure 16 shows the panel to introduce a new sensor type.Having defined a type, sensors of that type can be added, as illustrated in Figure 17.Having defined a type, sensors of that type can be added, as illustrated in Figure 17.Having sensors stored in the system, you can group them into an entity (Figure 18) and define alerts (Figure 19).Having sensors stored in the system, you can group them into an entity (Figure 18) and define alerts (Figure 19).Having sensors stored in the system, you can group them into an entity (Figure 18) and define alerts (Figure 19).Maps can be incorporated into the platform (Figure 20), and entities (in this case air conditioners and a weather station) added to maps (Figure 21).Maps can be incorporated into the platform (Figure 20), and entities (in this case air conditioners and a weather station) added to maps (Figure 21).Maps can be incorporated into the platform (Figure 20), and entities (in this case air conditioners and a weather station) added to maps (Figure 21).The status of every active (in green) entity can be visualized in real time, as is shown in Figure 22.You can display historical values of user-specified sensors, from specified entities and maps, or download them (Figure 23).The status of every active (in green) entity can be visualized in real time, as is shown in Figure 22.You can display historical values of user-specified sensors, from specified entities and maps, or download them (Figure 23).The status of every active (in green) entity can be visualized in real time, as is shown in Figure 22.You can display historical values of user-specified sensors, from specified entities and maps, or download them (Figure 23).

Results
The hardware and software components of the IMBPC HVAC system were designed and implemented by researchers of the University of Algarve, in a partnership with the spin-off company EasySensing, Intelligent Systems (Faro, Portugal), and an HVAC installation and maintenance company, Rolear, Ltd. (Faro, Portugal).
Having available the components, the IMBPC HVAC system was installed in building 7 of the Gambelas Campus of the University of Algarve, located in Faro, Portugal.Figure 24 shows an overview of the experimental setup used.
As can be seen, the rooms under remote monitoring/control SPWS devices incorporated measuring the activity (movement), state of windows/doors, air temperature and relative humidity, and mean radiant temperature (walls temperature).An intelligent weather station provided the measurement and forecasts of the solar radiation and air temperature and relative humidity.The Mitsubishi Variable Refrigerant Flow (VRV) systems (PUHY-250YMF-C external units and PEFY-P63VMM internal units) are controlled and monitored by a TAC Vista BMS, which executes in a dedicated PC.The IoT platform, including the execution of the predictive models and the

Results
The hardware and software components of the IMBPC HVAC system were designed and implemented by researchers of the University of Algarve, in a partnership with the spin-off company EasySensing, Intelligent Systems (Faro, Portugal), and an HVAC installation and maintenance company, Rolear, Ltd. (Faro, Portugal).
Having available the components, the IMBPC HVAC system was installed in building 7 of the Gambelas Campus of the University of Algarve, located in Faro, Portugal.Figure 24 shows an overview of the experimental setup used.
As can be seen, the rooms under remote monitoring/control SPWS devices incorporated measuring the activity (movement), state of windows/doors, air temperature and relative humidity, and mean radiant temperature (walls temperature).An intelligent weather station provided the measurement and forecasts of the solar radiation and air temperature and relative humidity.The Mitsubishi Variable Refrigerant Flow (VRV) systems (PUHY-250YMF-C external units and PEFY-P63VMM internal units) are controlled and monitored by a TAC Vista BMS, which executes in a dedicated PC.The IoT platform, including the execution of the predictive models and the predictive control loop are executed in another PC, in our laboratory, located in a different building of the campus.Rolear technicians installed the IMBPC system in one week of work, starting on 14 May 2015.The intelligent weather station (see Figure 25) was installed on the terrace of the building, and the SPWS devices (see Figure 26) in adjacent Rooms 2.12, 2.11 and 2.13 of the building.Rolear technicians installed the IMBPC system in one week of work, starting on 14 May 2015.The intelligent weather station (see Figure 25) was installed on the terrace of the building, and the SPWS devices (see Figure 26) in adjacent Rooms 2.12, 2.11 and 2.13 of the building.
As the rooms were nearby, no SPWS transmitter was need.Afterwards, the central node, the interface to the BMS and the IoT platform were installed.All systems were tested, making sure that all components had the correct behaviour.Data were acquired in the period between 14 May 2015 00:05:00 + 01:00 and 6 June 2015 12:00:00 + 01:00, corresponding to 23 days and 6768 samples).The atmospheric data were collected by the intelligent weather station, the room data were obtained using the SPWS devices, and the HVAC data were obtained using the BMS interface software.After the data acquisition period, the predictive models were designed.
The experiments took place at the end of June, when the rooms were used for exams rather than for regular classes.Three adjacent rooms were employed.Room 2.12 was under IMBPC HVAC control, while Rooms 2.11 and 2.13 were under normal control.Rooms 2.12 and 2.13 have the same area, while Room 2.11 has an area double that of the others, possessing two air conditioners.
Both experiments, which took place on different days, assumed two schedules, from 9 h to 13 h 5 m, and between 16 h to 18 h 5 m.Table 3 shows the energy (in kWh) spent in the three rooms, for the 4 occupation periods.In this table, the term Priors denotes the time where the HVAC is operating before the start of all occupations (i.e., in the periods t op t oe ), in order to maintain thermal comfort within the scheduled occupation.The column labelled Schedules denotes the energy spent for the four scheduled periods, and the last column denotes the total energy spent.Notice that in Tables 3 and 4 the values assigned for Room 2.11 are the sum of the corresponding values for each air conditioner.Rolear technicians installed the IMBPC system in one week of work, starting on 14 May 2015.The intelligent weather station (see Figure 25) was installed on the terrace of the building, and the SPWS devices (see Figure 26) in adjacent Rooms 2.12, 2.11 and 2.13 of the building.As the rooms were nearby, no SPWS transmitter was need.Afterwards, the central node, the interface to the BMS and the IoT platform were installed.All systems were tested, making sure that all components had the correct behaviour.Data were acquired in the period between 14 May 2015 00:05:00 + 01:00 and 6 June 2015 12:00:00 + 01:00, corresponding to 23 days and 6768 samples).The atmospheric data were collected by the intelligent weather station, the room data were obtained using the SPWS devices, and the HVAC data were obtained using the BMS interface software.After the data acquisition period, the predictive models were designed.
The experiments took place at the end of June, when the rooms were used for exams rather than  As can be seen, due to the fact that the IMBPC tries to maintain thermal comfort during the occupation periods, more energy is spent by this approach.As we are considering four scheduled occupations, the energy spent in the prior periods is much larger than a unique, larger period, would use.Note also that there is a significant savings of energy within the occupation periods.In terms of costs, as shown in Table 4, the situation changes.Room 2.12 has a lower total cost than the other rooms.This is due to the intelligent use of the tariffs, as the optimal reference temperature sequences are obtained by minimizing the cost and not the energy.
If, however, we analyse the percentage of time with PMV violation during the four schedules (Table 5), it is clear that while Rooms 2.11 and 2.13 do not offer thermal comfort for a considerable period of the occupation time, the same was not the case with Room 2.12.Note also that Room 2.11 is in thermal discomfort for a longer period than Room 2.13.We realized afterwards that one of the air conditioners in this room was not operating well, which also contributes to the smaller energy and cost obtained for that room (if we divide those values by two), in comparison with Room 2.13.Finally, Figure 26 shows the evolution of several variables of Room 2.12, for the second experiment.As can be seen, the one-step-ahead forecast of the weather and climate variables is excellent, which is also translated in the PMV.It is also noticeable that the quality of the forecast of the movement signal is completely different from the forecasts achieved for the other variables, although it follows the trend of the measured variable.During the occupation periods the room is in thermal comfort (PMV equal or lower than 0.5).To achieve that, the AC needs to operate during short periods (the prior time) before the start of both occupations.
More real-time results can be seen in [9].

Discussion
The use of IoT technologies is changing the way our cities are viewed and managed [36], how industry operates [37], and how we design modern healthcare systems [38].IoT will also reshape the HVAC industry, allowing real-time monitoring through the use of smart sensors, enabling remote diagnostics and predictive maintenance, real-time control, incorporating user-preferences, system adaptation for upcoming situations, increased efficiency and possible replacements of traditional Building Management Systems.
In this paper, SPWS devices and an IOT platform, which were designed as part of a complete HVAC Predictive Control solution, have been detailed.As shown, the devices are small, allowing for seamless integration in buildings' energy efficiency applications, as well as easy to set up and install, cheap compared to available alternatives, providing alerts for diagnostics and, most importantly, allowing perpetual autonomous operation under reasonable and common lighting conditions in buildings and homes.The availability of the IoT platform enabled an easy installation of the data acquisition system and the interfaces, also providing the means for real-time operation.
The use of these hardware and software components of an IMBPC HVAC system makes the complete approach marketable in terms of price as well as installation and maintenance.In the same way as the IoT gateways, improved versions of the SPWS [39] and of the IoT platform [40] are now available on the market, and are being used for other smart home applications, such as intelligent optimal scheduling of an electric storage system in a real household with a PV installation.
Although this was not the focus of the paper, it was also shown that the Intelligent Model-Based Predictive Control scheme achieves important economic savings while maintaining thermal comfort during the whole scheduled occupation period.
IMBPC uses for thermal comfort the PMV index [19].Although this is the most used thermal comfort index, some authors question its predictive accuracy of actual thermal sensation.For instance, in [41] it is concluded that PMV produces errors, particularly in field settings.The author concludes that errors in the measurement of the physical variables do not seriously compromise the PMV model, but the setting values used for clothing insulation and the activity level can be considerably problematic for the accuracy of the PMV model.The authors of [42] conclude that, for buildings with air conditioning, as is the case here, the PMV model shows a trend of overprediction, regardless of the weather zone and season.They also suggest that the two parameters mentioned before, clothing insulation and activity level, need to be re-examined for better interpretation of thermal comfort.Future improvements in the estimation of these two parameters will be accommodated in the IMBPC scheme.

Figure 2 .
Figure 2. Block diagram of an autonomous Self-Powered Wireless Sensors (SPWS) that extracts energy from the surrounding environment.

Figure 2 .
Figure 2. Block diagram of an autonomous Self-Powered Wireless Sensors (SPWS) that extracts energy from the surrounding environment.

Figure 4 .
Figure 4. Block diagram of the SPWS power management circuit.SPWSN: Self-Powered Wireless Sensor Network; USB: Universal Serial Bus.

Figure 4 .
Figure 4. Block diagram of the SPWS power management circuit.SPWSN: Self-Powered Wireless Sensor Network; USB: Universal Serial Bus.

Figure 5 .
Figure 5.Both sides of the SPWS PCB prototype.PCB: printed circuit board.

Figure 5 .
Figure 5.Both sides of the SPWS PCB prototype.PCB: printed circuit board.

Figure 6 .
Figure 6.3D design of the SPWS enclosure.(A) Top view showing the circuit and battery box with holes for air circulation and for the USB connector, as well as the box lid where the PV panel is mounted; (B,C) views of the bottom part of the lid where the LDR and PIR sensors are mounted; (D) detail of the top view of the box interior showing where the PT1000 is mounted in such a way that it will be in contact with the SPWS mounting surface.PV: Photovoltaic Panel; LDR: Light Dependent Resistor; PIR: Passive Infrared Sensor.

Figure 7 .
Figure 7. Left: an open SPWS showing the PCB, battery and PV panel; Right: a SPWS mounted on a wall.

Figure 6 .
Figure 6.3D design of the SPWS enclosure.(A) Top view showing the circuit and battery box with holes for air circulation and for the USB connector, as well as the box lid where the PV panel is mounted; (B,C) views of the bottom part of the lid where the LDR and PIR sensors are mounted; (D) detail of the top view of the box interior showing where the PT1000 is mounted in such a way that it will be in contact with the SPWS mounting surface.PV: Photovoltaic Panel; LDR: Light Dependent Resistor; PIR: Passive Infrared Sensor.

Figure 7
Figure7shows an open SPWS, with the battery and the PCB, and in the right side a sensor mounted on a wall is shown, where the LDR is visible in the lower part of the enclosure.

31 Figure 6 .
Figure 6.3D design of the SPWS enclosure.(A) Top view showing the circuit and battery box with holes for air circulation and for the USB connector, as well as the box lid where the PV panel is mounted; (B,C) views of the bottom part of the lid where the LDR and PIR sensors are mounted; (D) detail of the top view of the box interior showing where the PT1000 is mounted in such a way that it will be in contact with the SPWS mounting surface.PV: Photovoltaic Panel; LDR: Light Dependent Resistor; PIR: Passive Infrared Sensor.

Figure 7 .
Figure 7. Left: an open SPWS showing the PCB, battery and PV panel; Right: a SPWS mounted on a wall.

Figure 7 .
Figure 7. Left: an open SPWS showing the PCB, battery and PV panel; Right: a SPWS mounted on a wall.
Figure 8 shows SPWS devices and Tmote sensors, under different enclosures.The numbers within red squares are the identifiers of the following sensors and configurations: 46-Tmote inside an open box; 43-Tmote inside a closed box; 1-SPWS outside the box; 3-SPWS inside the designed enclosure; 45-Tmote outside the box; 44-Tmote inside an open box, 2-SPWS device placed in the same box.The devices measured the air temperature (Figure shows SPWS devices and Tmote sensors, under different enclosures.The numbers within red squares are the identifiers of the following sensors and configurations: 46-Tmote inside an open box; 43-Tmote inside a closed box; 1-SPWS outside the box; 3-SPWS inside the designed enclosure; 45-Tmote outside the box; 44-Tmote inside an open box, 2-SPWS device placed in the same box.The devices measured the air temperature (Figure

Figure 9 .
Figure 9. Air temperature recorded by the Tmotes and the SPWS.

Figure 10 .
Figure 10.Relative humidity recorded by Tmote Sky devices and the SPWSs developed.

Figure 9 .
Figure 9. Air temperature recorded by the Tmotes and the SPWS.

Figure 10 .
Figure 10.Relative humidity recorded by Tmote Sky devices and the SPWSs developed.

Figure 10 .
Figure 10.Relative humidity recorded by Tmote Sky devices and the SPWSs developed.

Figure 12 .
Figure 12.Current drawn from the SPWS battery during the active part (reading the sensor and transmitting the result) of the door/windows state sensor duty cycle.Figure 12. Current drawn from the SPWS battery during the active part (reading the sensor and transmitting the result) of the door/windows state sensor duty cycle.

Figure 12 .
Figure 12.Current drawn from the SPWS battery during the active part (reading the sensor and transmitting the result) of the door/windows state sensor duty cycle.Figure 12. Current drawn from the SPWS battery during the active part (reading the sensor and transmitting the result) of the door/windows state sensor duty cycle.

Figure 13 .
Figure 13.Current charged to the battery, over the 24-h period. 0

Figure 13 .
Figure 13.Current charged to the battery, over the 24-h period.

Figure 13 .
Figure 13.Current charged to the battery, over the 24-h period.

Figure 15 .
Figure 15.Structure of the database.Figure 15.Structure of the database.

Figure 15 .
Figure 15.Structure of the database.Figure 15.Structure of the database.

Figure 16 .
Figure 16.Adding a new sensor type.

Figure 16 .
Figure 16.Adding a new sensor type.

Figure 17 .
Figure 17.Adding a new sensor.

Figure 18 .
Figure 18.Adding a new entity.

Figure 17 .
Figure 17.Adding a new sensor.

Figure 18 .
Figure 18.Adding a new entity.Figure 18. Adding a new entity.

Figure 18 .
Figure 18.Adding a new entity.Figure 18. Adding a new entity.

Figure 20 .
Figure 20.Adding a new map.

Figure 20 .
Figure 20.Adding a new map.

Figure 20 .
Figure 20.Adding a new map.

Figure 22 .
Figure 22.Status of an entity.

Figure 22 .
Figure 22.Status of an entity.

Figure 22 .
Figure 22.Status of an entity.
Appl.Sci.2018, 8, x FOR PEER REVIEW 26 of 31 predictive control loop are executed in another PC, in our laboratory, located in a different building of the campus.

Figure 24 .
Figure 24.Overview of the experimental setup.TCP: Transmission Control Protocol; IP: Internet Protocol.

Figure 25 .
Figure 25.Installation of the intelligent weather station.

Figure 24 .
Figure 24.Overview of the experimental setup.TCP: Transmission Control Protocol; IP: Internet Protocol.

Figure 24 .
Figure 24.Overview of the experimental setup.TCP: Transmission Control Protocol; IP: Internet Protocol.

Figure 25 .
Figure 25.Installation of the intelligent weather station.Figure 25.Installation of the intelligent weather station.

Figure 25 .Figure 26 .
Figure 25.Installation of the intelligent weather station.Figure 25.Installation of the intelligent weather station.Appl.Sci.2018, 8, x FOR PEER REVIEW 27 of 31

Table 2 .
Average current consumption of SPWSs over three different duty cycles.SPWS: Self-Powered Wireless Sensors.

Table 3 .
Energy (in kWh) for each room, during the four schedules.

Table 4 .
Economic cost (in €) for each room during the four schedules.

Table 5 .
Percentage of time with PMV violation for each room during the four schedules.