# IoT Helper: A Lightweight and Extensible Framework for Fast-Prototyping IoT Architectures
## 3 System Architecture
### Data Model  
Communication between the embedded system and other devices differs depending on the type of interaction. Data and command channels physically separate messages exchanged by the systems. This brings significant advantages in terms of simplicity, scalability and performance.  
The command channel is the one used to send requests to sensors or actions to the actuators. Data format contains the following: (1) the command typology and (2) sensors/actuators involved. The format of a request is the following:  
/COMMAND_NAME/LIST_OF_SENSORS_ACTUATORS&TOKEN  
where  
COMMAND_NAME represents the requested action that we have already discussed, and the values are _read_, _repeatedRead, write_ and _timedWrite_;  
LIST_OF_SENSORS_ACTUATORS represents the name of sensors and actuators to which we want to send the action. Sensors or actuators are separated by the special character \"&.\" Moreover, the name used is the one used in the configuration step;* TOKEN represents a key to match different request-response pairs. Since communication is asynchronous, there is the need to correlate the response to the request. In real-life scenarios, multiple clients might send requests simultaneously, and since they will wait for the response on the same channel, they need to filter the response. For this reason, in the request, the client generates a unique (or random) token that will be included in the response.  
Commands cannot be mixed, i.e., send _read_ and _write_ operations cannot be combined at the same time. For example, we have the following commands:  
#1 /READ/I1&I2&TOKEN=T001;
#2 /WRITE/O1=1&O2=255&TOKEN=T002;
#3 /TIMEDWRITE/TIMER=100&O3=1&TOKEN=T018.  
Command #1 represents a reading example from two sensors (_I_1 and \(I\)2) associated with a unique token \(T001\). For example, \(I\)1 and \(I\)2 could be, respectively, temperature and humidity sensors. Command #2 represents a written example to two actuators (_O_1 and \(O\)2). For each actuator, we specify the value to send. With respect to digital actuators, the admitted values are zero or one (such as \(O\)1). For analog actuators, the admitted values depend on the actuators themselves. \(O\)2 is an example of an analog actuator, and we send a value of 255. Finally, command #3 represents a timedWrite operation on actuator \(O\)3. The operation is executed after 100 seconds. For each of the above commands, a token identifies the corresponding request generated from the client.  
After command execution, the response is published on the data channel. The response depends on the request type. If the command is a _read_ type, then the response contains raw data acquired by sensors. If the command is a _write_ type, then the response contains information about the received message.  
For example, the following represents the response to command #1.  
'''I1'': 23,  
'''L2': 0.67  
},  
''token'': ''T001'',  
''timestamp'': ''20210506T13:38:00''  
It contains the raw data from sensors \(I\)1 and \(I\)2. Raw data are wrapped in the block \"data.\" In addition, it contains the token related to the request and the time when the response is generated.  
By executing command #2, we can receive a response such as the following.  
''result'': 'SUCCESS'' },  
''token'': ''T002'',  
'timestamp'': ''20210506T13:39:41'' }