# Implementation of a Topology Independent MAC (TiMAC) Policy on a Low-Cost IoT System
## 4 The Proposed System
### Synchronization  
A significant factor in TDMA environments is the nodes' awareness of the time that a frame begins. In order to fulfill the above requirement in multi-hop environments, a (multi-hop) decentralized clock synchronization mechanism has to be implemented. Timestamping techniques that have been extensively employed in the literature by several proposed synchronization algorithms (e.g., [36; 37; 38]) are employed here. Moreover, in the current work, the considered synchronization mechanism has to take into account that the focus is on the implementation of TiMAC on low-cost devices; thus, the results given consider the devices' low-cost nature as well. In this sense, a long enough time period of 2000 ms is considered for nodes to synchronize their clocks. During this time period, starting at the beginning of each frame, nodes synchronize their clocks by transmitting the previously described _SYNC_ messages. The latter process goes as follows: a reference node transmits a _SYNC_ message to its neighbor nodes, thus informing them about the time remaining until the first time slot of the frame starts. Subsequently, every node that receives this message for the first time adjusts its clock accordingly and transmits a new _SYNC_ message to its neighbor nodes.  
Figure 5 depicts the considered synchronization mechanism between the selected reference node (\(r\)), and nodes \(u\) and \(v\), connected in chain topology (i.e., \(r\)-\(u\)-\(v\)). In the example depicted, at the beginning of the synchronization period (st), the reference node \(r\) waits for a certain time interval \(t_{dr}\) and then transmits its clock \(t_{0}=st-t_{dr}\) to node \(u\). When \(u\) receives the message, it subtracts the transmission time from \(t_{0}\) and changes its clock accordingly (i.e., \(c_{u}=t_{0}-t_{tx}\)). Subsequently, node \(u\) waits for a certain time interval (i.e., \(t_{du}\)) before transmitting its clock (i.e., \(t_{1}\)) to node \(v\). Following the same procedure and by the time node \(v\) receives the message, it (i) changes its clock (i.e., \(c_{u}=t_{1}-t_{tx}\)); (ii) waits for a certain amount of time (i.e., \(t_{dv}\)); and (iii) transmits its clock to the next-in-line node (if any). Apparently, node \(u\) may also receive node's _v SYNC_ message, but since one has already been received, this one will be ignored.  
Figure 4: The TDMA frame of the implemented MAC protocol. Each time slot (ts\({}_{i}\)) ends with the guard period (t\({}_{g}\)). The synchronization time (st) along with the frame guard period (t\({}_{fg}\)) are also depicted.  
Figure 5: Illustration of the synchronization mechanism within a synchronization period (st), among nodes \(r\), \(u\) and \(v\) connected in a chain topology. Nodes wait for a certain amount of time (i.e., \(t_{dr}\), \(t_{du}\) and \(t_{dv}\), respectively) before transmitting the time remaining until the first time slot (i.e., \(t_{0}\), \(t_{1}\) and \(t_{2}\), respectively). The internal clocks \(c_{u}\), \(c_{v}\) along with the transmission time \(t_{tx}\) are also depicted.