# A TDMA-Based Access Protocol for Dense Networks with Moving Nodes for IoT Applications
## 3 Algorithm Description
### Operation of the Proposed Algorithm
```
1:Input:\(N\), Load, EOS, ToA, \(p\), \(WuB_{CH->ED}\) and \(WuB_{ED->CH}\)
2:while\(j\leq EOS\)do PHASE1
3:foreach\(ED\in N\)do
4:\(ED\) initiates a GPS measurement
5:ifrand (1,10) \(>p\)then
6:\(ED\) has not a packet for the \(j^{th}\) cycle
7:\(ED\) does not calculate SF
8:else
9:\(ED\) has a packet for the \(j^{th}\) cycle
10:\(ED\) announces its calculated SF
11:endif
12:endfor
13:\(Latency_{ED->CH}\gets WuB_{ED->CH}\times N\) PHASE II
14:forach\(ED\in N\)do
15:if\(ED\) has a packet for the \(j^{th}\) cycle then
16:\(list\leftarrow[ED,slot_{SF},SF_{initial},slot_{SF+1},SF_{new}]\)
17:\(gtss\gets list\)
18:else
19:continue
20:endif
21:endfor
22:while\(k<LEN_{gtss}\)do
23:\(TimeToSendPacket\leftarrow(gtss[k][1]\times(ToAS_{Finitial}+GT))-(ToAS_{Finitial}+GT)\)
24:update \(x\), \(y\) position for current ED
25: calculate \(SF_{new}\)
26:if\(SFinitial<SFnew\)then
27:if there is a dead slot situation then
28:\(Latency_{ED->SN}\leftarrow(gtss[k][newslot]\times(ToAS_{FNnew}+GT))\)
29:else
30:\(Latency_{ED->SN}\leftarrow(gtss[k][3]\times(ToAS_{FNnew}+GT))\)
31:endif
32:\(Latency_{ED->SN}\leftarrow(gtss[k][1]\times(ToAS_{FNnew}+GT))\)
33:endif
34:endif
35:endwhile
36:\(MAX_{Latency_{ED->SN}}\)
37:endwhile Output:\(Meanatalatency\gets ToA_{12}+WuB_{CH->ED}+Latency_{ED->CH}+Latency_{ED->SN}\)
```  
**Algorithm 1** MOTILO Algorithm  
MOTILO is mainly an enhanced migration of the system model of [6] for a protocol with moving nodes, tested also under dense node formations. Having said that, and similar to the model of [6], SN initiates the communication procedure by requesting the data from the nodes through the CH. Thus, SN sends a LoRa message to the CH and the latter broadcasts a WuR message to the EDs in order to acquire their intention of transmission, in other words, to probe if they have data to send. While in [6] the WuR is used as a trigger to start the transmission of the EDs' data, in MOTILO the WuR is used to construct the transmission map by broadcasting the EDs' position translated to the initial SF zone. Upon reception of this broadcast message, every ED initiates a GPS measurement and responds with a WuR broadcast message, announcing the calculated SF according to its position (lines 2-11 in Algorithm 1), in case it has data to transmit, under a simple transmission policy: according to its node ID inside the cluster, every nodes calculates its transmission slot (TS) by multiplying its ID with the WuR signal duration:  
\[TS(i)=i*WuR \tag{1}\]  
As a consequence, every ED has to wait for its transmission slot even if the previous nodes do not have data to transmit as there is no other way to be informed about other nodes' intentions. This is the first phase of the proposed communication protocol. In this phase, we are informed about the transmission intentions of every node, and is critical in order to schedule all the transmissions. Adding this latency, which is not present in the work of [PERSON] [6], MOTILO is able to eliminate empty slots. Therefore, phase one is in other words an empty-slot sieve. Subsequently, at the end of the previous protocol phase (phase one), all nodes are aware of others transmission schedule and each node is able to construct the global transmission slot schedule (variable \(gtss\) in line 16 of Algorithm 1) in what is called phase two (lines 14-26 in Algorithm 1). Opposed to the base work of [6], as the nodes in our communication system are moving, MOTILO, acting as a forecast system, reserves an additional slot (\(slot_{SF+1}\)) in a higher SF zone (\(SF_{new}\)) from the one reported from every node in phase one. This is performed in order to minimize the consequences of nodes that will change their position and the initially reported SF will be out of range, resulting in a lost packet or even two lost packets as their transmission may interfere with the transmission of another node. To do so, for every occupied transmission slot, one additional is reserved beforehand in the higher SF schedule.