Abstract
Keywords
Introduction
Traditionally, research efforts in Internet of Things (IoT) have been addressed to support data-collection applications, overlooking the need for actuation and smart behavior. The main challenge these data-collection applications have to face is how to deal with data-source heterogeneity. Two main approaches can be identified in the literature and the market, namely, the use of the Cloud and the use of gateways. Cloud-based applications delegate the management of IoT networks and data to remote servers. Under this perspective, the Cloud typically assembles a set of repositories in which sensors have published their values. These data are, afterward, retrieved and processed to take a centralized decision. Such architecture enables the interoperability between different IoT networks only at the Cloud level without any direct communication between the information source and those that use it. The use of gateways, as technology translators, is also a common solution, although as stated in Tao et al., 1 the conversion among protocols also entails an important overload that affects performance.
The acting side of IoT systems has been traditionally overlooked, mainly due to the inherent complexity of supporting interoperability among IoT objects. A review of the state of the art for IoT interoperability support brings about solutions classified into the following four groups: 2 standards, 3 reference architectures and frameworks,4–7 protocols and mediatype standards,8–10 and definition languages and ontologies11,12 The work of Tayur and Suchithra 2 concludes that interoperability has to be addressed at the application layer by combining the aforementioned techniques.
From our point of view, acting in IoT does not solely depend on enabling interoperability at the application layer but, additionally, on the capability to understand the context and the objects that populate it. To this end, we point out the need for two enabling elements: (1) a model that captures the semantics of the system and human behavior and (2) the capability to automatically compose or reconfigure service functionality.
Regarding the need for semantic models, the most complex ones are those involving humans. We cannot obviate that modeling human behavior is far from being a trivial task due to the inherent complexity of human aspects such as cognition, psychological preferences, or emotions.
13
The main reason behind this complexity lays in the unstructured and large-scale characteristic of the knowledge that rules human behavior. Our approach to tackle this complexity consists in using the
Regarding the capability to automatically compose or reconfigure services, it is our believe that the service semantics has to be decoupled from the service itself and its programming interfaces in order to be modeled and stored as knowledge about the service. By decoupling services from their semantics, service composition and reconfiguration can be automated and therefore delegated to a standardized computation system. In contrast to traditional approaches used for service composition, such as web services, in our approach the programmer does not have to explicitly state how services can be composed. On the contrary, this information is implicit in its semantic description, from which an advanced inference mechanism can derive how services can be composed to offer a composite functionality. This is a disruptive approach to service elicitation since the information about how services can be composed is not handcrafted by the programmer or service designer. On the contrary, it is inferred from the service description. Moreover, the composition or reconfiguration process is normally motivated by an arisen need. In this sense, our approach is also disruptive because this
The main contribution of this article is the proposal of an architecture for IoT that explicitly targets acting and smart behavior. The proposed architecture provides support for seamlessly integrating heterogeneous devices and technologies and for understanding and reacting to ongoing context situations. These capabilities will be grounded in a novel modeling approach that combines human behavior and a novel IoT information model. In addition, the proposed architecture faces the technology heterogeneity issue proposing a virtual protocol that supports communication among different technology domains. To demonstrate the acting and smart behavior capabilities of the proposed architecture, we have evaluated the platform performance in a testbed scenario in which different use cases have been carried out. The testbed has considered the deployment of different sensors and actuators and the retrofitting of already-deployed appliances to incorporate communication and acting capabilities. The IoT system considered in this testbed scenario is aimed at improving the well-being conditions of its inhabitants and the energy efficiency of the building, all that following a low-cost approach.
This article will be organized as follows. First, the “Previous works” section reviews previous solutions for Smart Homes, especially those provided by the market, paying special attention at how those solutions target the problem of understanding and acting in IoT. The “A three-stage process for service composition and reconfiguration” section describes the lexical approach we propose for service composition and reconfiguration. The “Proposed architecture” section describes the insights of our proposal, describing the different layers comprising the architecture. The experimental “Evaluation” section describes the hardware prototypes that have been designed and deployed in the testbed scenario. Finally, the “Conclusion” section summarizes the main ideas withdrawn from this work.
Previous works
The introduction of IoT paradigm and the proliferation of ubiquitous Wireless Sensor Network (WSN) have enabled machine to machine (M2M) connectivity in the Smart Home. Hui et al. 18 identify the major requirements for building Smart Home systems in which multiple people interact with the environment. The device heterogeneity is, once again, pointed out as the main challenge to be addressed. The long list of network protocols and data structures currently in use makes it difficult to integrate different solutions.
The analysis of the state-of-the-art solutions for device heterogeneity brings about the following approaches. A Server Centralized Architecture (SCA) is proposed by Xuemei and Gang 19 as a solution to connect devices in the home space, using to this end a home gateway. SCA addresses the incompatibility issues that arise when trying to communicate protocols like 6LoWPAN, Bluetooth LE, ZigBee or Z-Wave. The proposed solution consists in a hub server in which these protocols have been implemented. That same approach has been followed by some companies like Wink (https://www.wink.com/) or Samsung Smartthings Hub (https://www.samsung.com/us/smart-home/how-it-works/). The use of gateways, despite being a widely employed solution, leads to incompatibility issues when trying to integrate devices that implement protocols different from the ones initially considered by the manufacturer. On the contrary, open-source automation platforms like OpenHab (https://www.openhab.org/), Home Assistant (https://home-assistant.io/), or Domoticz (http://www.domoticz.com/) are specifically aimed at facing this problem. These platforms are supported in open-hardware devices such as Raspberry Pi, which enables the control and automation of different technologies in Smart Homes.
The increasing complexity of services and devices has called for new paradigms that assure aspects such as scalability, interoperability and reliability. The service-oriented architecture (SOA) is one of these approaches intended to provide a number of software services re-mapped in a typical Software-as-a-Service (SaaS) cloud architecture for reshaping home services and applications. Moreover, these architectures have, traditionally, paid great attention at the automation of the composition task.
The Cloud Computing paradigm has gained attention as a solution to address interoperability among different vendor devices, easing the process of interconnecting different services and therefore leveraging the expansion of smart environments. The use of the Cloud also provides a new solution to integrate on-board network modules in home devices which connect the devices to Internet, simplifying the process of mapping, encapsulating and composing the services that provide. There are some solutions such as Apple Homekit (https://www.apple.com/es/ios/home/), Samsung Smartthings (https://www.samsung.com/us/smart-home/smartthings/), or Google Home (https://developers.google.com/actions/smarthome/), which provide a platform to integrate different vendors devices to control them through cloud infrastructures. Some platforms such as Ambient OS (https://www.essential.com/home) or Amazon Alexa (https://developer.amazon.com/alexa/smart-home) provide a framework for developers, in order to integrate speech recognition and natural language understanding (NLU) capabilities to simplify the user interactions with the devices.
The device integration capabilities are restricted by the cloud platforms because they have a limited number of calls defined through an API which communicate the user operations with the devices. Despite the SOA approach, the service composability does not work properly in cloud platforms due to the lack of uniform treatment of services.
Interconnecting heterogeneous devices and services provided by different vendors and providing seamless interoperations across the available platforms still remain a big challenge. Tao et al. 1 describe a multi-layer cloud architecture model and an ontology-based security framework to integrate the different common cloud-based platforms using ontologies to address data, knowledge, and application heterogeneity in the available devices.
The IoT paradigm is generating an unprecedented volume and variety of data and although the Cloud computing has many advantages, it requires a high bandwidth to exchange the vast amount of data between the devices and the Cloud infrastructure. This leads to increase the latency in the time response of services and spreading the data to other locations different from the source. It is in this point where the Edge-computing paradigm has the aim to push computation on acquired data away from the core of data centers and get closer to the data sources.
Projects such as iSapiens 20 propose a platform which implements the Edge-computing paradigm through both the exploitation of the agent metaphor and a distributed network of computing nodes directly scattered in the smart environment. The current vision of Smart Homes is focused on the management and control of devices. Nevertheless, the raw data produced by those devices do not provide any meaningful value. It is in this situation where the context-aware computing brings value by deducing knowledge and providing better understanding of raw data. The work of Lalanda et al. 21 and Rahman et al. 22 takes advantage of the Edge-computing and pervasive applications to propose context-aware platforms to provide a reasoner in charge of deducing knowledge and dealing with the environment by using context management. The design of these platforms is based on a service component model or OSGi specification that describes a modular system and a service platform for the Java programming language. Frameworks such as Apache Felix or Eclipse SmartHome provide the necessary tools for building Smart Home solutions based on the principles of modularity, component orientation, and service orientation. L Smirek et al. 23 evaluate the Eclipse SmartHome framework to address backend technologies and personalized user interfaces in a Smart Home. These solutions, despite being very convenient for basic service composition, lack the flexibility demanded by the IoT vision.
A three-stage process for service composition and reconfiguration
The architecture proposed in this article is mainly intended to support actuation and smart behavior in IoT. To this endeavor, it should be equipped with the appropriate mechanisms for enabling service composition and reconfiguration while assuring high-flexibility and low coupling in the process. These requirements are imposed because the composition or reconfiguration process has to be automatically driven and accomplished and, therefore, no human intervention has to be required before, during, or after the composition or reconfiguration process.
The proposed approach consists in a three-stage process in which the semantic, syntactic, and lexical compatibility is verified before accomplishing the composition or reconfiguration process. Whereas the lexical compatibility concerns about providing the programmatic support for service composition and reconfiguration, the syntactic compatibility concerns about the assurance that the data provided and consumed by the bound services match in the expected format and content. Finally, the semantic compatibility concerns about the functionality provided by the bound services.
One of the main characteristics of the spaces envisioned by the IoT paradigm is that they tend to be driven by events. In this sense, most of the IoT objects populating these spaces are intended to capture the reality into messages or events. IoT objects are eventually intended to perceive the activities that are taking place and, consequently, react to them. The mechanisms therefore provided for supporting composition and reconfiguration capabilities count on the premise that services implement an event-driven approach. This is totally compliant with what sensor services are expected to do, as known: wait for an event to take place and then notify its occurrence in a reactive way.
It is important to highlight that most of the services considered in our architecture follow this reactive-system approach. Nonetheless, other approaches can be considered and supported by the architecture with the only difference that those that do not comply with the reactive approach are not considered for automatic composition or reconfiguration.
The mechanism proposed here for service composition and reconfiguration is eventually based on the idea that events can be

Physical and virtual sensor services.
Service composition or reconfiguration is based on the capability to build this service pipeline, whose triggering is determined by the occurrence of a given event. As it can be observed from the example outlined in Figure 1, it is essential that effects of events can be propagated in a transitive manner without having to propagate the stimulus itself. Only by supporting this transitiveness, services can be automatically composed or reconfigure without affecting its normal behavior. This approach for composition and reconfiguration also assures that there is no difference, not even in the way they are used, between services provided by physical sensors and those pipelines, resembling virtual ones.
There are, however, some important requirements that need to be satisfied in order to enable the automatic generation of service pipelines, as known:
A mechanism to support the pipeline links, in terms of programming interfaces and event-propagation support.
A mechanism to verify the syntactic compatibility of services to be linked.
A mechanism to determine the semantic compatibility of services.
The following subsections address each of these requirements.
Support for service binding: lexical compatibility
Figure 1 depicts the way how service composition and reconfiguration are carried out by establishing a pipeline of services linked by unidirectional messages, propagated all along the pipeline. The service pipeline is supported on the fact that every service points to its next element in the pipeline using, to this end, the service-reference address. Additional support is required for the binding process so that the following requirements can be met:
No human intervention should be required in the process of configuring a service to send (in a one-way fashion) the results it produces to the next service in the pipeline.
It should support on-runtime configuration, meaning that there is no need for a predefined list of possible connections.
Bindings can be modified any time.
One service can be bound to more than one consumer: One-to-n relations are supported and made transparent for the pipeline builder, known here as the
To address these requirements, we propose that all services that can, eventually, be part of a reconfiguration or composition work, implement a common interface. This interface, named
Despite its simplicity, the implementation of this interface assures that any service can be bound, automatically (without human intervention), to other services. It is important to recall that the binding process
It is the role of the

Process of linking two services.
This mechanism assures that any service can be part, eventually, of a service pipeline as long as it implements the
There will be situations in which the information provided by one service can be of interest to more than one services. For example, more than one services can be interested in the information provided by temperature sensor. The mechanism described in Figure 2 cannot be used, as it is, because it is limited to having just one consumer. Binding service
An additional mechanisms for supporting this one-to-n connection is therefore required. To this end, we propose the implementation of the traditional solution to this problem, as it is an event-propagation mechanism based on communication channels. Figure 3 describes this process. As it can be observed, there is an intermediary service, referred here as the

Process of linking one service to several ones.
The
Compatibility at the syntax level
The second stage of the composition or reconfiguration process verifies that the service pipeline is valid in terms of the syntactic correctness of the unidirectional messages used as linking elements. The
Despite the fact that at first, this can be considered a simple type-checking problem, the need for checking other aspects rather than just types calls for more advanced mechanisms. For example, in the same case depicted by Figure 1, consider that the motion algorithm consumes images in
The paradigm of design by contract (DbC) or contract programming provides the means to state and verify these type of constraint checking. Languages like Ada provide native support for DbC. However, these are programming languages and not service or interface description languages so this would not be totally appropriate. In fact, the interface description language employed, at the middleware level, is not expressive enough to support the statement of these types of constraints. This is not, however, a particular problem of the employed language; on the contrary, the most commonly used description languages (WSDL, 24 IDL, 25 Protocol buffers 26 ) suffer from this limitation. This calls for a way to enhance service descriptions so that the correctness, at the syntax level, of the service binding can be automatically assured.
Therefore, following a DbC approach, and due to the limited expressiveness of the service description languages, we propose to model these type of restrictions at the knowledge-base level, in which the flexibility provided by the description language is enough to capture the clauses of contract.
According to the semantic model described in more detail in the next section, the
Following the Scone semantics, both
The scheduler, in charge of deciding the services comprising the pipeline, will just have to verify that provided and required capabilities, if any, match for the bound services.
Apart from the capability-matching checking, it is also necessary to verify that the services to be bound are compliant in terms of provided and required interfaces. From the middleware perspective, since all services implement the
This is the most flexible way to support service binding, given that the service semantics is moved to the knowledge base where more advanced verification works can be carried out.
This is an addressing-agnostic approach that decouples the type of address from the referred service. In this work, indeed, two addressing schemes are employed: one based on the middleware built-in proxy representation and other based on the addresses used by our protocol for Inter-Domain Messaging (IDM).
It is important to highlight that the alternative to the use of a common and
Compatibility at the semantic level
The simplification of the service-binding and type-verification process is a requirement for the service composition and reconfiguration task to be automatically carried out in an unsupervised manner. This simplification has been achieved, as described in this section, by migrating all the service semantics to a level in which higher expressive power and advanced reasoning mechanisms can be supported.
We propose the use of Scone (https://github.com/sfahlman/scone), an open-source knowledge-based system written in Common Lisp. It implements efficient search algorithms, based on the marker-passing algorithm proposed by Fahlman, 27 mainly intended to provide answers in reasonable time, even when the answers are not optimal. Scone supports a higher order logic language very convenient for describing the domain-specific and context knowledge as well as the insights of IoT services, in terms of the actions and events they are related to and the interfaces they implement, require, or use.
The following code listing shows the flexibility and expressiveness of the considered description language. The
The x-is-the-y-of-z function is used in Scone to state a certain role of a given concept. In this case, it states that the used-interface of the MotionService is the EventSinkInterface, meaning that the
Actions and events are also two essential concepts for a complete description of a service. In this case, a tertiary relationship is employed to describe that the
Finally, certain services also provide or require a capability, or a set of them. For example, in the following code listing, the
This means that a service, as the following one, requiring a
The semantic compatibility of two services to be bound is determined considering the following aspects:
The interfaces that one of them provides and that the other uses have to be compatible.
The capabilities that one of them requires and that the other one provides should also be compatible.
The compatibility of interfaces and capabilities is something more elaborated than a simple verification of the equality of source and target. Scone employs a semantic-network approach, which means that properties inherit from general types to specific ones. This is very powerful because semantic compatibility offers more possibilities for service composition and reconfiguration than forcing strict semantic equality. Moreover, Scone provides native support for semantic compatibility checking offering functions such as
Proposed architecture
This article proposes an architecture for IoT-based Smart Homes that specifically targets support for actuation and smart behavior. Two capabilities are identified as enablers for this endeavor, namely
The capability to automatically understand ongoing situations and the available means for undertaking responses. This capability is mainly based on information about the services deployed in the context, and the knowledge about
The capability to seamlessly integrate, compose, and reconfigure IoT objects. This capability relies on a mechanism for managing the underlying heterogeneity, by providing an abstraction layer upon which objects can communicate to each other in a symmetrical way.
Figure 4 outlines the different elements that comprise the proposed architecture, organized in layers. At the bottom layer, we can identify the SOA. Current systems for IoT involve services implementing different computational models, like the Edge, Fog, or Cloud Computing. It is important to highlight that all these services have to be equally treated, independently of their implementation details. An abstraction layer is provided by IDM to homogenize the underlying heterogeneity. On top of this there is the middleware layer, built upon a general-purpose object-oriented middleware, whose core functionalities have been extended with advanced capabilities. The most important aspect of this layer is the implementation it does of the semantic model proposed at the

Proposed architecture.
Service layer
Services are located at the bottom layer of the proposed architecture, as the most basic building blocks. As it can be observed from Figure 4, all services are equally considered independently on the underlying communication technology they employ or the computational model they implement. This represents a disruptive approach in the sense that the proposed architecture assures a symmetrical treatment to services independently on how or where they are being deployed or implemented. To be more precise, in any IoT system, we can identify the following service types:
Those provided at the Edge-computing level, generally implemented in IoT devices. This implies that the device and the service it provides are totally coupled. Among some of the most important features of these services, one can highlight their low latency, since the data source and target are directly connected, or the high privacy level they provide since there is no need for data transportation.
Those provided at the Fog-computing level generally implemented as application gateways or hubs. We refer here to services that perform some data aggregation, manipulation, or any type of interaction that cannot be carried out at the Edge level. For example, the Fog approach is suitable for some video-processing applications, highly demanding in terms of required resources.
Those provided at the Cloud-computing level which, by the way, are the most widely spread. Some applications are offered at the Cloud level for cost-efficiency purposes (do it once and provide it to many users) or for resource optimization (specially for machine learning applications which demand large datasets for training purposes, for example), exploiting the most relevant advantages of this computing model.
Whereas traditional SOA has considered services at the same level (the Edge, Fog, or Cloud), our proposal does not make that distinction and pursues service homogenization, independently on the computational approach they follow. Leveraging automatic service composition or reconfiguration is the motivation behind this homogenization effort. The fact that all services can be equally treated enables a computation entity, as it is the scheduler in our case, to automatically compose or reconfigure services, in an unsupervised manner.
Providing for this transparency is especially important when we are dealing with Edge services because, as it has already been mentioned, they are usually highly coupled to the underlying communication technology. Nonetheless, IoT devices tend to be constrained in terms of memory or processing capabilities which typically lead to the unfeasibility to implement the full TCP/IP stack. In fact, sometimes it is not desirable, nor even possible, to replace specific-purposes protocols with a standard one. Therefore, relying on TCP/IP for communication purposes is not always a choice.
We propose a novel approach for homogenization purposes consisting of a virtual network protocol for inter-domain messaging, which enables every IoT object, or
The importance of catering for these two aims can be more easily understood from the following example. Imagine one has a WiFi appliance (i.e. a lamp) in the living room, and this person is also wearing a BlueTooth SmartBand. It would therefore be very handy if the lamp functions (switch on and off) could be controlled by different tapping patterns in the SmartBand. Despite being a very basic problem, it perfectly illustrates the type of challenges arisen due to technology heterogeneity. Different solutions can be proposed to articulate this application:
One may implement a WiFi/BL bridge and translate messages between both devices. This is a fast solution but not the best one because it is highly coupled to the specific devices and therefore very difficult to port elsewhere.
One could also make both devices to use TCP/IP, the de-facto standard. It cannot be obviated that we are dealing with constrained devices in which a full implementation of the stack (usually big) is not feasible.
One could use a Cloud server so that the SmartBand may send messages to the Cloud, whereas the lamp may be a listener for incoming messages.
Option number 3 is probably the most accepted solution for the considered scenario. However, it cannot be overlooked that the use of the Cloud is very well suited when data aggregation is required to obtain the
The most sensible solution therefore involves the SmartBand
A very important aspect of IDM is that every resource on the IoT network (every sensor or actuator) is an object. Its main implication is that if a single device (hardware) holds more than one resource, an individual object will be allocated for each resource. This approach is suitable for constrained nodes as objects can be simple.
It can be assumed that any end device (either sensor or actuator) provides an interface (understood as a set of well-known operations). The role of the IDM protocol is to transport the invocation messages from the client to the end device. These end devices can be referred as objects. The term is inherent to the current implementation of IDM which is based on an object-oriented middleware (ZeroC Ice (https://zeroc.com/)). However, the use of this term is not totally accurate since they are closer to an SOA than to an object-oriented one.
The main objective of IDM, as it has been already stated, is to support the intercommunication between network technologies that are, a priori, incompatibles. The use of the name domain stems from the fact that in the IDM infrastructure all the devices that share a technology and addressing scheme are seen as a single entity (a domain). Thus, the entire public Internet is a single IDM domain.
The router does not change the messages it forwards at all. For example, you can receive a message from an RS-485 device on one of its interfaces and forward it to a device on a Bluetooth network. That is a key point, the IDM router has no status, does not create device delegates or proxies, does not transform addresses, only forwards complete messages between its interfaces.
This is possible because the IDM message remains unaltered from its creation at the client to its arrival at the target object. IDM routers only change their encapsulation, in a similar way to an IP router. Obviously, the router needs to have an interface in every domain it interconnects, but the specific details of that network’s technology are hidden from the rest. Unlike a conventional network protocol such as IPv6, IDM addresses refer to objects rather than nodes (a node can hold several objects). These two features allow the IDM message to be encapsulated even on the LAN’s link protocol, regardless of the “local” network protocol.
Regarding the services offered at the Fog and Cloud level, it is necessary to provide an adapter that enables the communication between the middleware layer and the service itself. For example, a Cloud service that provides a speech-recognition system, like IBM Watson, offering a REST interface (HTTP), has to be adapted to provide the middleware protocol. Regarding the Fog services, it has to be taken into account that most of them are not third-party services and they are therefore provided by the platform itself. This means that there is no need for adapters since they will normally use the underlying middleware technology.
The information model for the middleware
The proposed architecture is using, at the middleware layer, a general-purpose object-oriented middleware as it is ZeroC Ice. ZeroC Ice is a remote-procedure-call-based middleware developed by the USA company ZeroC (https://zeroc.com/products/ice). The interfaces of any service developed in ZeroC Ice have to be defined in the interface definition language, known as
ZeroC Ice also comes with a complete set of tools and services to deal with recurrent issues in distributed systems (IceStorm, IceBox, IceGrid, etc.). These core services provide support for event propagation, deployment, platform or node management, and so on. We have extended these core services with some capabilities that support the service deployment process and, eventually, the tasks involved in composing services. The middleware has been enhanced with the following services:
These services cater for service composition and reconfiguration, at a very basic level, by providing efficient mechanisms for managing the interconnection of services and their information exchange. It cannot be obviated that the process of automatic service composition and reconfiguration has to deal with more complex challenges, for which the three-stage process has been designed to. Recall that this process deals with compatibility issues at the lexical, syntactic, and semantic level. The role played by the
We can categorize the provided interfaces into two sets: the data-centric interfaces and the message-centric interfaces. The
All these interfaces have two common parameters:
Semanticware layer
The term
Continuing with the middleware analogy and similar to the role played by the programming interfaces, the semanticware is supported on a semantic model that identifies the concept and relationships that are relevant for the system. This model is depicted in Figure 5.

A semantic model for service composition and reconfiguration.
The ultimate goal of the semanticware is to support automatic service composition and reconfiguration. For this reason, a mechanism for service description has to be devised so that not only their functionality is captured, but also the way how they should be used. Figure 5 illustrates the concepts and relationships that have been identified to this end.
The

Syntactic matching in service composition.
It is the role of the
Algorithm 1 describes the process we have devised to select a sequence of services whose combined functionality cater for a given need. The algorithm is intended to validate the syntactic and semantic compatibility of the selected services as well as, eventually, undertake the binding process, in an automatic manner.
plan-for
The algorithm is provided with an event the system is interested in causing. The algorithm returns an ordered list of services to be sequentially bound. Figure 7 summarizes the proposed algorithm. As it can be observed, the scheduler is built using the semantic model concepts as they are the

Scheduler service pipeline construction process.
According to the theory of actions proposed in K Bach,
31
Actions are not events but instances of a certain relation, the relation of bringing about (or making happen), whose terms are agents and events.
As for events, the same author states the following assumption: I assume that events exist in space and time and that they enter into causal relations as causes and as effects.
The semantic model we propose complies with this theory and makes this distinction by considering that
The semantic model is captured in the knowledge base where the different actions and events are described in terms of the context
The following code listing shows how the action of
The before and after context are identified by the
Awareness layer
Mental states or mental qualities, as referred by McCarthy, 14 deals with how to represent information regarding beliefs, knowledge, free will, intentions, consciousness, ability, or wants, which represent essential aspects of the human rationality. In his work, Bratman proposed the BDI (Belief, Desire, and Intentions) model for human practical reasoning, as an explanation for the human rationality exhibiting goal-driven behaviors.
Unsatisfied goals is what motivates people to devise plans that lead to goal satisfaction, achievement, or maintenance, and therefore, the emulation of intelligent behavior should inexorably be linked to an appropriate representation of the mental events involved in emulating goal-driven behaviors.
Moreover, context-awareness is one of the main requirements for enabling Smart Spaces, since the only way of wisely and proactively or actively reacting to context events is by understanding what is going on in the environment. The events or actions that take place in the context are noticed by means of the sensing devices and services deployed in the environment. Therefore, the only trace evidencing the occurrence of an event is the sensing values captured by any of these IoT objects. Ascribing those values to the effects of an event or an action is the only possible way of interpretation. The accuracy in understanding context situations depends on how extensively and thoroughly preconditions and effects of events and actions have been described.
The Smart Home paradigm relies on its ability to notice the situations that are taking place as well as its ability to generate appropriate responses to undergoing scenarios. However, on what basis does an environment conclude that a certain action is the most appropriate one? Smart Home systems, as humans, count on a set of goals to drive their behavior toward the achievement, maintenance, or desired performance of such environmental goals. In this respect, unsatisfied or deviated goals is what encourages Smart Home systems to devise the most appropriate way to return to or to achieve the desired state. Rather than using hard-coded responses to whatever circumstances that might arise in the environment, it is more feasible to simply dictate the environmental goals that the system is engaged in maintaining or achieving, and try to discern among the available actions, which of them seem more suitable in reducing the distance to the unsatisfied goals.
The way to reduce the distance between the current situation and a targeted one is by devising a plan, here understood as a course of actions. Action planning is intended to consecutively apply changes to an initial state so as to transform it into the goal state. The world states notion of the action planning is very similar to that of situation proposed by McCarthy, and therefore, can be modeled by means of the possible-worlds theory. The occurrence of a given event or action produces changes in the current state of the world. Under incomplete information and reasoning by default, we can expect the world to be in a finite set of states. Action planning, therefore, consists in successively applying changes to the world state to get a glimpse of the future world state.
Plans can be therefore understood as the behavioral responses generated by the Smart Home system whenever unsatisfied goals arise. The device dynamism and heterogeneity that characterize these environments makes it unfeasible to statically determine how those plans should be undertaken. On the contrary, plans should be automatically devised grounded on the knowledge of the devices and services, or IoT objects, available at a given moment.
The BDI model of agency proposed by Bratman 32 seems to be a compelling approach to cope with the demands involved in dealing with the identification and management of ongoing situations. To this end, the proposed architecture resorts to a set of software agents in charge of supervising the events to detect unsatisfied or deviated goals. As a result of this detection, plans will be launched to restore the desired state. The goal-driven agents have been built upon the semantic and the middleware layers, meaning that the communication aspects are totally transparent to the agents whereas the knowledge is available at the Scone knowledge base. These BDI agents understand “beliefs” as the properties that an agent considers to be true, “goals” as the properties that an agent desires to be true, and finally “plans” as the actions that lead an agent to a desired goal. These basic instances define what is known as the agent’s mental state.
The agent’s beliefs in combination with contextual information (held in the Scone knowledge base) are what lead the agent’s behavior toward the goals that the agent desires to achieve or maintain. Interaction between agents, the knowledge base, services and devices is based on the fact that all of them share the same semantic model.
Consider, for instance, the situation in which a person is in front of an office, looking for his or her key or access card, realizing that he or she has forgotten it at home. The system should devise a way to grant access to this person, knowing that he or she is authorized to access that space. The following mental state is held by the agent supervising the context:
Evaluation
The proposed IoT platform for Smart Homes has been deployed for evaluation purposes in the Institute of Information Technologies and Systems (ITSI). This building belongs to the University of Castilla–La Mancha and hosts around 50 people working in different research groups. Two scenarios are considered for evaluation purposes. One scenario is devoted to demonstrate the service composition capabilities, in the context of access control, whereas the other one is intended to demonstrate the reconfiguration capabilities, in the context of room temperature control. The scenario has been equipped with low-cost devices that avoid expensive and closed commercial solutions.
Like every morning, Bob gets to his office at 8:00 a.m.:
Scenario 1
Standing in front of the door, he checks out his pockets looking for his badge. After a few seconds, he realizes he left it in the car. By then, the smart environment supervisor detects the unusual circumstance of Bob standing at the door and asks him whether he needs something. Bob asks the system to
This scenario is intended to demonstrate the system capabilities to understand ongoing context situations and react to them. Despite the fact that this is a predefined scenario, no
Scenario 2
As he enters his office, his smartwatch
Testbed description and hardware prototypes
Temperature control is an important aspect to be considered when attempting to improve the well-being of users and energy efficiency in Smart Buildings. Nowadays the market of HVAC systems is dominated by a number of traditional manufacturers offering proprietary hardware and software solutions. For such systems, the integration with open IoT platforms is still far from being a reality.
Buildings, such as the ITSI, typically include a centralized HVAC system with a proprietary configuration software. From the end user point of view, the only interaction is with a simple console in each room, with buttons that allow switching on and off the heating and changing the temperature set-point. In the hardware prototype developed in the Smart Office, the console has been retrofitted adding an IoT node with WiFi connectivity. This node is able to interact with the console by means of optocouplers acting as solid-state relays that allow bypassing the button contact. In this way, the console can be operated both manually (i.e. pressing the buttons) and by means of the IoT node outputs that electrically emulate the action of pressing the buttons. Retrofitting allows the integration of existing products with IoT platforms. 33 Nevertheless, this solutions should also pursue the compliance with existing safety and quality regulations.
The WiFi node, implemented for temperature control of the Smart Office environment, uses a low-cost NodeMCU device (http://www.nodemcu.com/index_en.html), which is based on the compact and low-power Espressif ESP8266 WiFi and MCU chipset (http://espressif.com/en/products/hardware/esp8266ex/overview). To interface the node with the HVAC console, a circuit has been designed to integrate the required optocouplers. An image of the temperature control node connected the HVAC console is shown in Figure 8. Details of the NodeMCU and the designed shield that incorporates the optocouplers can be seen in Figure 9.

IoT node for temperature control.

Details of the NodeMCU device and the designed shield to interface the HVAC console.
The integration of the temperature control system in the proposed IoT platform for Smart Homes enhances the possibilities in terms of comfort and efficiency management. The designed node is able to control the on-off, temperature increase, and temperature decrease buttons. Moreover, it is able to monitor the state of the heating system (on-off) that is indicated with a green LED in the console. One of the advantages of the developed temperature control node is that, thanks to the integration with the IoT platform proposed in this article, it can be linked to one or various temperature sensors distributed in the space. Furthermore, the temperature set-point can be established by several users. These two features enable the possibility of advanced control strategies, in which the feedback temperature signal and the set-point values can be obtained as by performing some processing and calculations considering the measurements of several sensors and the comfort of several users. An example to illustrate this could be a scenario in which
The feedback temperature is obtained by calculating the mean temperature of the sensors located in areas where the presence of user is detected.
The set-point is obtained calculating the mode (i.e. the value that appears more often) among the values configured by the users.
Another valuable advantage of the proposed temperature control system is the ease to perform data logging for pattern extraction and energy estimation.
In addition, to talk about smart building, it is essential to automatically control and manage the people that access or leave the premises. In fact, many of the services provided in a smart building depend on knowing how many people are there inside the building and where are they located in (i.e. smart evacuation protocols, smart lighting services, and smart meeting management). One of the most common solution is based on the use of radio frequency identification (RFID) readers, deployed at the entrance of the different rooms to be controlled. Every user has a badge that grants or denies access to every room. Figure 10 shows a RFID reader at the entrance of the testbed office.

Camera, microphone, and RFID card reader deployed at the door frame.
Similarly, the use of CCTV (close-circuit television) cameras is commonly extended for surveillance purposes. We have also equipped our testbed with a low-cost camera FOSCAM C1.
To validate our capability to seamlessly communicate objects employing different communication technologies, several prototypes have been specifically designed to this end. These prototypes, as the one shown in Figure 12, therefore demonstrate the IDM capability to homogenize IoT objects. Despite their heterogeneous communication and architecture details, these objects are considered virtually equal inside an IDM infrastructure. Moreover, the door lock has been retrofitted with an electric door lock, as it can be observed in Figure 11 labeled as

Door configuration.
Finally, the testbed area has also been equipped with some additional sensors (presence, temperature, microphone, light, etc.). Whereas the HVAC console, camera, microphone, and door actuator employ WiFi, we have built a sensor board prototype, as shown in Figure 12, that includes, among some, a presence and a temperature sensor over a ZigBee (Arduino FIO + XBee) and RS-485 domains. Every domain has its own IDM router. The IDM routers for the ZigBee and RS-485 domains run on a Raspberry Pi, whereas the router for the WiFi domain runs on a conventional PC. Figure 13 outlines the considered topology.

Moth XBee including a presence and a temperature sensor.

Logic topology of the considered scenario.
Experimental results
Both case scenarios described at the beginning of this section have been reproduced in the testbed environment (the ITSI building), using the hardware and network topology previously described. Recall that each of the considered scenarios has targeted a different goal: case scenario 1 pursues the validation of the composition capabilities, whereas case scenario 2 is intended to demonstrate its capability to manually and automatically reconfigure services.
Figure 14 summarizes the scheduler trace yielded in the process of building the service pipeline to cater for the user’s issued command. The event

Scheduler result for scenario 1.
Figure 14 encloses in frames each of the scheduler iterations. For this particular case, the scheduler is launched five times, one for each event that has to be caused. The result of the scheduling process is the list (or pipeline) of services that has to be bound.
Figure 15 depicts the sequence diagram that results from binding the service pipeline generated by the scheduler.

Sequence diagram of the service pipeline for scenario 1.
The service reconfiguration process is simpler than the composition one mainly due to the fact that the scheduler is provided with events for which there exists a single service that causes it. There is no need to recursively look for alternatives, as in the composition case. Figure 16 summarizes the scheduler trace. As it can be observed, it is simpler than the one for case scenario 1.

Scheduler result for scenario 2.
The scheduler is queried about how to cause the event of
The sequence diagram from case scenario 2 is depicted in Figure 17. As the user enters the room, the system looks for services that can provide a measure of the room temperature. Based on that temperature and knowing the comfort temperature established for that user, the

Sequence diagram of the service pipeline for scenario 2.
Conclusion
This article proposes an architecture for IoT-based Smart Home that focuses in enabling capabilities for automatic service composition and reconfiguration. This architecture is novel in the three-stage process it proposes for the service composition and reconfiguration. An additional contribution of this work consists in how semantic is treated. A common-sense reasoning approach is proposed to capture the semantics of IoT objects and services. This semantic knowledge has demonstrated more flexible and advanced capabilities for the composition and reconfiguration process, to eventually cater for unsatisfied goals or arisen needs. This capability is what turns a normal environment into a
To demonstrate the performance of the proposed architecture, a testbed scenario has been set up. Different rooms of a working building have been retrofitted with low-cost devices to turn them into IoT objects such as doors or HVAC systems. Two case scenarios have been devised to evaluate the response capabilities of a smart system. Results yield that this approach supposes a low-cost and flexible mechanism for turning homes into smart homes.
