## 4 Foundations of HWSNs
### Nodes Basic Roles  
In a broad sense, the concept of node in a HWSN is the same as with almost any communication network; _i.e._, a physical device that interacts with others through a communication interface. However, these nodes can play one or more roles. Every role can be seen as a function or process with an input and an output data interface, as shown in Equation (3). Typically, the process receives the data input, processes it and produces an output; _i.e._, similar to a filter in the pipe-and-filters architectural pattern [30]:  
\[\text{role}::=<\text{input, process, output}> \tag{3}\]  
If a node plays more than one role, the services provided through these roles can be played in an independent way, or they can be organized through a pipeline or workflow. For instance, a smartphone is a node that can play the role of \"sensor\" since it can capture images using its camera. It can also play the role of \"processor\" because it has computing capability of performing specific tasks. Theseservices can be provided independently of one another. However, if the smartphone should provide a people presence awareness service (_i.e._, a complex service), the system must connect these two roles in a workflow indicating that such a service considers two steps: capturing a picture and trying to identify known people in it through face recognition as shown in the following services definitions:  
\[\text{presence\_awareness}::=<\text{s\_picture\_capture}\mid\text{p\_face\_recognition}> \tag{4}\]  
\[\text{s\_picture\_capture}::=<\text{null, take\_picture\_pa, picture}> \tag{5}\]  
\[\text{p\_face\_recognition}::=<\text{picture, picture\_recognition\_pa, bool}> \tag{6}\]  
The s_picture_capture service does not have a formal input and the output is a picture as defined in Equation (5); the prefix \"s_\" indicates that such an operation is a sensing activity (_i.e._, a role played by the node). The p_face_recognition service takes the output of the previous service and delivers a true or false depending on the results of the recognition process as defined in Equation (6). The prefix \"p_\" indicates that such a service is a processing operation (_i.e._, other role). If the operation specified in the definition does not have a prefix, it means that it is atomic and has a particular implementation on the device performing the action. Provided that every role is a process that can be seen as a filter in a pipeline (Figure 1), both the input and the output for each filter can be active or passive. A filter with an active input means that such a process is aware of the arrival of an input data to process it. Contrarily, the input is passive if the process is triggered only after a direct invocation done by the next filter in the sequence or by an external source. Something similar happens with the outputs of each filter. A filter with an active output delivers the process results to the next filter in the pipeline or to the target entity. However, if the output is passive, the filter stores the result in a buffer or keeps it until the next filter in the pipeline asks for such data. Clearly, the information flow in these structures depends on properly coordinating the input/output behavior of the filters in the pipeline. In our example, the output of the first filter is active and the input of the second one is passive; it could also be in vice versa. In another case, the information does not flow between filters or can produce information collision. The suffix in the operation name indicates the behavior that the filter adopts when processing an input and an output; _i.e._, the suffix \"_pa\" shown in Equations (5) and (6), and also in Figure 1 indicates a passive behavior for the filters. The behavior of complex services, _i.e._, those created through the integration of other services is automatically determined by the behavior of the first and the last filters in the workflow; therefore these attributes do not need to be specified for these processes.