## 6 Implementation  
### PoCo and Communications  
PoCo has been implemented as an extension of Node-RED [21], an open source visual tool for data flow programming with a Web interface. Specifically, a set of nodes (PoCo components, communication and discovery) has been developed to be part of the Node-RED palette in order to address the requirements offered by the system. Each developed node has a specific function, such as the creation of a group of resources. The connection of these nodes comprises the behaviours that can be defined in App adaptivity, as shown in Figure 6.  
The communication between user applications and the PoCo has to be able to provide asynchronous communications since both components can send information asynchronously. Information can be dispatched from the PoCo to user applications continuously in groups or resources observations and sporadically when the CoAP network changes. User applications can also send asynchronous data with the RD discovered process and the location establishment. As a result, the communication channel has also to be bidirectional. Historically, applications that need bidirectional communication require different TCP connections, one for sending information  
Figure 7: User application screenshots with some defined behaviours defined in the PoCo. (**a**) A chart, real-time values and a group of lights; (**b**) Pop-up window for interact with a light group.  
and a new one for the reception. This entails the maintenance of multiple connections, mapping between each other and the abuse of HTTP polling for updates. WebSockets [39] was conceived as an alternative to HTTP polling providing two-way communication in a single TCP connection. In fact, WebSockets connections are done in the same ports as HTTP, nevertheless WebSockets and HTTP can only understand themselves in the handshake. Header and latency are usually smaller in WebSockets, thereby it is considered as a real-time communication channel. Moreover, WebSockets has also been integrated by default in most web browsers, the Web, and a large set of clients, so it opens the door to the integration of a large variety of clients and applications. Node-RED nodes have been developed in the PoCo to have a Websockets channel. The communication between user applications and the PoCo is encrypted leveraging the TLS/SSL support in WebSockets.  
The data format is another key challenge in the development of applications, since bizarre and random data formats carry out into large efforts of development, code difficult to maintain and a door opened to multiple issues. We have therefore chosen JSON--an open-standard and de facto format in a large amount of applications and development frameworks--as message format. A semantic has been defined for the message definition. All messages exchanged from PoCo to user applications contain an operation type and most of them, a location, which indicates the operation has to be done in user applications and the location where the event has taken place, respectively. Optional values can also be included, for example, a message status, the resource type of a resource, the value of a request and information for rendering components. An example of an message exchanged between the PoCo and user applications is presented in Figure 8, specifically an alert message of the change of a light actuator. The message is an alert operation in the location Room 1, indicated in the fields op and location respectively. Other fields indicate the message status and the resource type and URI of the component. Messages are sent once new behaviours have been created for user applications, with the observed data from resources and operation results.