## 1 Introduction
However, AmI applications are composed of different heterogeneous devices, and although many context situations can be similar (as movement detection in the smartphones), these contexts could not be obtained in the same way. For instance, due to the structure of a house, an application can consider seven movement detectors while another one only considers four detectors. Thus, these kinds of applications have a common core asset and a variable part, so it can greatly benefit from Software Product Lines (SPLs) engineering [18], since it is specifically focused on variability modelling. Then, we propose to use FamiWare [19], a family of context-aware middleware built using SPL. In such a way, both complex contexts acquired by heterogeneous devices and the communication of context information among those devices of the AmI system are handled by FamiWare in a transparent way. On the other hand, we propose to use models to specify the context information for WSNs by using the UML common language. Specifically, we base on the ContextUML metamodel [20], an UML-based modeling language for model-driven context-aware services development, which provides a flexible design of context-aware services. It separates the modeling of context and context-awareness from service components by making easier both development and maintenance of these services. Then, in this work we present a model-driven process to build context-aware applications based on FamiWare. The contexts for these applications will be specified using ContextUML, and by means of the defined mapping between ContextUML and FamiWare a new augmented version of the FamiWare family with the incorporation of new contexts will be automatically created. Then, taking as input the specific requirements of the system about every device, the network (e.g., number of devices) and the necessities of the application (e.g., security) we will obtain automatically the FamiWare code ready-to-install for every device of the system. Therefore, the main contributions of our work are the following:  
* We take advantage of separating the modeling of context and context-awareness in order to: (i) specify contexts using the ContextUML metamodel; and (ii) make a mapping that automatically transforms the ContextUML elements into elements of FamiWare. * We define a common architecture easy to reuse for the monitoring and the context-awareness services of FamiWare. We implement these services for three different devices of the middleware family. Concretely, two kinds of sensor devices (MicaZ with TinyOS, and Sun SPOT) and Android-based smartphones and tablets. * We design a model-driven configuration process that automatically incorporate new contexts to the FamiWare family and generate context-aware versions of the middleware for every application. * We generate automatically the code of customized versions of context-aware FamiWare for the three different platforms previously mentioned. The remainder of the paper is organized as follows: Section 2 motivates our proposal presenting the main problems to be solved and how our approach tackles them. In Section 3, we describe the context acquisition and analysis processes in FamiWare. In Section 4, the mapping from ContextUML to FamiWare is defined and illustrated with an AAL case study. Section 5 presents both the implementation of the monitoring and context-aware services in the augmented version of FamiWare, and the code generation process. In Section 6, the evaluation of our approach is detailed. Section 7 compares our approach to related works. Finally, Section 8 outlines some concluding remarks.