## 3 SAgic-IoT Platform Description
### Proposed Dissemination Protocol  
For the design of the dissemination protocol, we considered two critical issues: energy and reliability. Energy is the most important issue when designing dissemination protocols for IoT, where the application demands continuous information from the network field. For the design of the dissemination protocol: (I) we defined a static network architecture based on clusters; (II) the gateway node has no energy constraints; (III) the gateway node is not within the range of each sensor node, so a multi-hop transmission is needed; and (IV) heterogeneous sensors are implemented in each node.  
Our protocol defines three types of nodes: end-node, routing, and gateway. End-node nodes gather data from the sensors but cannot retransmit data to other sensor nodes. Routing nodes are responsible for collecting and retransmitting data from different sensor nodes. They also maintain a routing table that allows nodes to choose the best route for data transmission. Finally, the gateway node is the central node that receives all the gathered data from different sensor nodes and sends it to the Internet. Figure 7 shows the state diagram for the protocol.  
Our protocol defines data and controls messages. The protocol starts when a sensor node switches on. Each sensor node starts in the gateway node and sends a control message (_Register.request_) requesting its inclusion on the IoT network. The gateway node registers the new node and sends it the response (_Register.response_), where indicated, the type of node in the network (sensor or routing node), according to the number of hops the message takes to reach the gateway node. If the sensor node is an end node, it gathers data from different sensors, sends them to the gateway node, and changes its status to sleep to save energy. If the sensor node is a routing node, the node is also responsible for retransmitting the data from other sensors, so the sensor nodes wake up using a timer or a routing transmission request. The sensor node changes its status from disconnected to setup status when it receives the response. Afterward, the sensor and gateway nodes exchange messages  
Figure 6: ESP32-CAM module used for plant monitoring.  
Figure 7: States diagram for SAGric-IoT.  
(_setup.request_, and _setup.response_) to establish the gathering time for each sensor. At that moment, a sensor node is ready to begin the data gathering, so its status changes to the _gathering status_. In this status, the sensor nodes get sensor values, structure them into frames, and send them to the gateway node. When a sensor node gathers data from the different sensors, it sends a new message to the gateway node. SAgric-IoT uses the MAC data frame defined by IEEE 802.15.4 to build the message (Figure 8).  
The message contains frame control fields, destination address fields (in our case, we used 16-bit destination addresses), a data field where the data from the different sensors are included, and a checksum field to check that the message is not corrupted. This frame is sent to the gateway node through the _data.transmit_ message. When the sensor node finishes sending data, it changes its status to _Sleeping status_ (_Sleep.on_) to save energy for an established period. All sensors in the node and the microcontroller are off, and the node is considered a sleep node. When the sleeping time finishes, the sensor node wakes up and starts another data-gathering session from the sensors, or when the gateway node sends a request for information on data from the sensors. After the node gathers data and sends it to the gateway node, it goes to sleep again to save the battery (_Sleep.on_).