# An IoT-Based Solution for Intelligent Farming +
## 3 IoT-Based Stack Architecture for Intelligent Farming Solutions
### WSM and M2M Components
Independently of the type of \(\upmu\)C considered, all respect a common structure that is represented in Figure 5. They start with a _Synchronization Window_ (SW), during which each beacon sends a synchronization message carrying its identification and information about the current type of \(\upmu\)C. This information is used by the remaining devices to synchronize with the network and allows the collection of RSSI information from multiple devices, crucial for the localization algorithm. Following the SW, there is a _Turn Around Window_ (TAW) for processing purposes, namely for acquiring and processing sensor data and preparing subsequent tasks. Finally, the _Variable Traffic-type Window_ (_VTW_) is where the actual communications do occur. More details about this communication scheme may be found in [22]. To enable the implementation of the aforementioned communication scheme, several messages were defined, composing our Message Transport (MT) module. Figure 6 illustrates the existing interactions between networking elements for C2B and B2B \(\upmu\)C. As explained before, independently of the \(\upmu\)C type, there exists a initial phase, the SW, where beacons broadcast _BeaconSynchro_ (BS) messages. During this window, all devices are awake and, upon receiving these messages, they are all able to identify the starting and type of the new \(\upmu\)C, triggering the necessary calculations in order to know if, when and what they should transmit. This allows constrained devices (i.e., collars) to enter in energy-saving modes right after finishing their tasks. After this initial phase, the exchanged messages depend on the type of the \(\upmu\)C. For the C2B case, the remainder of the \(\upmu\)C is devoted to the transmission of _Collar-to-Beacon_ (C2B) messages, one per collar and per time slot. Only beacons listen to these messages, being the remaining collars in power-saving modes. On the other hand, if the \(\upmu\)C is of type 3 (B2B), the messages exchanged are called _Beacon-to-Beacon_ (B2B) and are also transmitted in a time multiplexing way, being assigned to each beacon one or more time slots, accordingly to the maximum number of beacons and to the routing scheme defined. \begin{table}
\begin{tabular}{c c c} \hline \hline \(\upmu\)C Type—Name & **Purpose** & **MAC Policy** \\ \hline
1—Pairing Request (PR) & Device’s pairing & CSMA \\
2—Collar-to-Beacon (C2B) & Collar (mobile nodes) communications & TMDA \\
3—Beacon-to-Beacon (B2B) & Inter-beacon relay & TMDA \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Micro-cycles types currently defined [72]. Figure 5: Micro-cycles (\(\upmu\)C) structure [75]. To enable a certain level of network dynamism, particularly the insertion and removal of devices while the system is running, a Network Manager (NM) module is included. Additionally, since some sensors are coupled to animals and thus movable on uneven terrain, it is of crucial importance that the gateway monitors sensor communications and detects missing animals or malfunction devices, such that they can be excluded from the network. Figure 7 exemplifies the exchanged messages when a new collar needs to be registered on the network's system. As these events are sporadic, a specific CSMA-based \(\upmu\)C (PR), is reserved for this kind of events. The collar initializes a new registration procedure by sending a _Registration Request_ with information about the serial number of the collar and the identification of the animal (i.e., animal identification information present in their stomach bulb transponder (2016)). These requests are propagated through the entire network until reaching the gateway. The gateway validates the request and, if possible, sends a _Registration Reply_ with the network identification and the serial number that is propagated backwards to the collar. The Routing Manager establishes the active routing scheme (within the beacon infrastructure). Beacons act as routers and they establish adjacent relations with their neighbors, based on the signal intensity monitoring.