## 2 Distributed Control and IoT Architectures in Smart Environments
### The Role of IoT in Smart Environments  
The literature review on the IoT area, such as well as its technological origin, is multidisciplinary. Many advances were necessary to make IoT, such as we know now, possible: from the hardware, to build ever smaller and smarter devices, passing through the communication technologies which allow wider covering distances and less energy consumption, the cloud computing, the storage of big amount of data, and the software industry. IoT covers an extremely comprehensive area and can be applied in many sectors. From a pillar in Industry 4.0 to the way we take care of elderly people, IoT has been infiltrating in everyday life becoming an ubiquitous and pervading technology. The use of IoT devices and applications in smart environments is nowadays a widespread practice. In smart homes, for instance, ubiquitous technologies are used to deal with the comfort, the healthcare, the safety, the security, and the energy conservation in dwellings [23]. Concerning energy savings, it must be noted that the monitoring of water and electricity consumption represents one of the main Key Performance Indicator (KPI) of energy efficiency in buildings [24], thus making this measurement step, essential. When it comes to smart buildings, additional functions are usually implemented, by including the monitoring of shared areas and facility equipment, such as elevators, toilets, patios, parking, etc. In the case of smart environments there are also concerns about the management of security, transportation, and other public services, thus calling for proper IoT architecture to support these kind of functionality. In particular, considering wider areas such as smart campuses, the employed IoT system must provide some LPWAN connectivity, which can deal with these demands [25; 26; 27; 28; 29; 30]. Finally, in the context of smart cities, the goals can be more ambitious and reach more people, by aiming at sustainability, improving the life conditions of the population, and encouraging the creation of a creative economy [31; 32; 33]. As IoT is used for more and more purposes, several isolated implementations appear and, along with the lack of interoperability, the need for standardization also arises. A relevant effort was made by the academic community to propose reference architectures for IoT applications, and many solutions were proposed. A survey of these proposals can be found in [34]. Some of them clearly show, in terms of functional views, the features and services that should compose an IoT environment. Services such as device management, security, and communication can be seen as independent in terms of technology [35], thus giving designers many possibilities in terms of implementation of individual services. Figure 2 shows the possible views of an IoT architecture. The simplest view is where every IoT application is composed by smart objects equipped with processing power and Internet connection, a middleware, and a user interface (see Figure 2 central view). All these components are part of the IoT architecture, although the middleware concentrates most of the functionalities. A smart applications can be built in many ways. A recommended reference architecture is described in [36]. The leftmost view of Figure 2 represents the typical implementation of an IoT system, where smart devices are interconnected through wired and wireless networks. In this kind of network, devices are typically responsible for sensing and pre-processing the raw data before communicating with a gateway, which provides connection with a higher level network. The rightmost view of Figure 2 represents the IoT Service Platform and Enabler, which contains all the software applications which implement the main functionalities of the IoT platform, including the Application Programming Interfaces (APIs - visibles in the first view of Figure 2), such as well as additional features, such as security, availability, etc.