# Home Automation System Based on Intelligent Transducer Enablers
## 5 HASITE: Self-Configuring Intelligent Transducer System
### Self-Configuration and Self-Registration Protocols  
The behavior of each ITN is modeled by the Finite State Machine (FSM) represented in Figure 5. From the moment an ITN is powered up, until it is ready to be accessed, it runs through the following states (note that the states named X-A represent the self-configuration phase, while the ones named X-B are related to the self-registration phase). * Self-configuration phase:
* 1-A Init (initialize) : configuration of the default values. The microcontroller reads from its internal memory values like the SSID and the password of the network it will connect to, and starts the FSM. * 2-A Connect AP: the connection to the configuration router is established. * 3-A Serve: the TCP server is started on the ITN to listen for incoming requests. * 4 Request Config: the configuration request is issued and sent to the home automation gateway. * 5-A Wait Response: the ITN awaits for a response that contains the configuration parameters. After receiving the configuration, the FSM writes it to the non-volatile memory of the ITN and restarts the ITN. * Self-registration phase:
* 1-B Init (initialize): configuration of the default values. In this state, the microcontroller reads the configuration previously received. * 2-B Connect AP: the connection to the default router is established. * 3-B Serve: the TCP server is started on the ITN to listen for incoming requests. * 6 Request Register: the ITN issues a register request and sends it to the home automation gateway. * 5-B Wait Response: after the home automation gateway registers the node, it sends an ACK message. In this moment, the ITN becomes available to the rest of the network. * 7 Listen: the ITN remains listening for incoming requests to serve and handle the transducer processing and communication operations. \begin{table}
\begin{tabular}{l c c c c c c c} \hline \hline
**Bytes** & **0–2** & **3–6** & **7** & **8** & **0–40** & **41–104** & **105–108** & **109–124** \\ \hline
**Data** & Sensor type & SN & Version & Status & SSID & Password & IP Gateway & IPv6 Reserved \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Memory division of the microcontroller EEPROM in bytes. Figure 5: Finite state machine implemented by an ITN. After States 4 and 6, the home automation gateway receives specific requests that contain the ITN identifier. Before sending a response, the home automation gateway queries its repository of local and/or remote ITEs searching for a match between the ITN identifier and the corresponding ITE. In case of finding a match, it registers the ITN in conjunction with its IP and a timestamp. This process is illustrated in the sequence diagram shown in Figure 6, which represents the exchange of messages between an ITN, the home automation gateway and the ITEs' repository. When the ITN is in State 7, the API is able to list it, allowing remote users to obtain all of the information about the node (its IP and the information associated with the ITE) and to carry out modifications on certain fields (e.g., descriptive name, location, calibration), as well as to interact with the ITN transducers. Using the API, any authorized application can get data from the sensors or perform actions on the actuators of the ITN. It is important to note that the FSM previously described has been simplified for the sake of clarity, meaning that any ITN connected to the network could be added to the system without any confirmation. More secure options are supported, it being only necessary to configure the system for a required confirmation before adding a node to the network. Two additional mechanisms are defined by using the ITN unique Identifier (ID):  
* Dynamic request: When the home automation gateway receives a configuration or a register request message, it sends a message to every client that is using the API. If there are no clients connected, the request is stored and sent in the next connection.