## 1 Introduction  
The usage of Wireless Sensor Network (WSN) technology is nowadays increasing because there are more and more ubiquitous applications that benefit from it. Traditionally, sensor devices have been used to monitor and analyze information about the environment, such as in agriculture [1] or earthquake detection [2]. However, currently they are being used for more dynamic systems, such as those with the purpose of helping humans in daily tasks in Ambient Intelligence (AmI) environments [3,4]. Typical AmI systems are Ambient Assisted Living (AAL; [[http://www.aal-europe.eu](http://www.aal-europe.eu)]([http://www.aal-europe.eu](http://www.aal-europe.eu))) applications, which provide user-dependent services (such as position location and movement tracking) for elderly and disabled people to enhance their quality of life in their own home by increasing their autonomy and self-confidence. Emergency or unusual situations inducing changes may appear dynamically in AmI applications. Therefore, they have to be capable of handling those changing situations, commonly called _context changes_, detected by means of sensors. Usually, this context information is very complex, because it is made up of data composition coming from variable sensors or other devices. For example, a context related to the daily habits of a user could be composed of a lot of information, such as his/her presence in different areas of the house at certain times, and the frequency and intensity of movement. To gather contexts, these systems should allow cooperation among heterogeneous sensors or devices, which may even represent the same information using different kinds of data (e.g., different units for temperature). Thus, although WSNs provide a very rich set of information, current proposals to gather and analyze this heterogeneous information in applications are tedious and require significant implementation efforts. The development of WSNs software today is tackled by a code-and-fix process that relies solely on the primitive constructs provided by the operating system and the developer skills, without much consideration for maintenance and reuse [5]. Therefore, it would be ideal to be able to provide application developers with a programming abstraction based on methodologies and techniques promoted by software engineering to specify and manage context information for improving the development process and fostering the effectiveness of WSNs in the Future Internet Society. Context-aware computing [6] is a paradigm of software engineering that covers all the topics related to the building of systems which are sensitive to their context (location, identity, time and activity) by adapting their behavior at runtime according to the changing conditions of the environment, device states, and user preferences or privileges [7]. Thus, context-awareness is the ability to detect and handle context changes. The importance of context-awareness has been recognized beyond its original scope of pervasive and ubiquitous computing [8]. Specifically, context information plays an important role in systems with the technology of WSNs, such as AmI systems, to control the reaction of systems depending on certain situations, to find people with similar interests, and so on. Then, it is essential to manage context information in systems using sensors by reducing human effort in human-computer interaction to make decisions and adapt to a changing environment. However, current programmingtechnology offers only very weak support for developing context-aware applications, and new research is urgently needed to develop innovative Context-Oriented Programming (COP) mechanisms [9]. On the one hand, recent research efforts have tackled the context management in WSNs at middleware level instead of application level [10, 11, 12, 13, 14, 15, 16, 17] in order to provide reusable solutions for different applications.