# An Adaptive Data Rate Algorithm for Power-Constrained End Devices in Long Range Networks
## 5 Adaptive Data Rate Algorithm Design
### ED Optional Parameter Acquisition Algorithm Based on Link State  
The ED optional parameter acquisition algorithm based on the link state determines the selectable data rate for the current ED based on the link state score. Every time the ED sends 20 data packets, it is considered a statistical window, during which the values of SNR, RSSI, and PRR are recorded. The link state score is calculated according to the link state evaluation method described in Section 3. The inputs to the algorithm include the ED's current data rate, transmission power combination, and link state score. First, the calculation methods for SNR margin \(SNR_{m\arg{in}}\) and link budget \(LM\) are clarified. The formulas are given as Equation (40). \[\left\{ \begin{array}{l}SNR_{margin}=SNR_{avg}-SNR_{\min}-M_{1}\\ LM=RSSI_{avg}-\text{Sensitivity}-M_{2}\end{array} \right. \tag{40}\]  
where \(SNR_{avg}\) and \(RSSI_{avg}\) represent the average SNR and RSSI of the received packets within the window, respectively; \(SNR_{\min}\) represents the minimum demodulation SNR for the current ED's SF, with the corresponding relationship between SF and minimum demodulation SNR shown in Table 7; Sensitivity represents the receiver sensitivity under the ED's current communication parameters; and \(M_{1}\) and \(M_{2}\) represent the extra margins for two margins. The calculations for \(M_{1}\) and \(M_{2}\) are given as Equation (41). \[\left\{ \begin{array}{l}M_{1}=10(1-\text{Score})\\ M_{2}=30-20\cdot\text{Score}\end{array} \right. \tag{41}\]  
where \(Score\in[0,1]\) represents the current ED's link state score, which measures the reliability and stability of the communication. When the link state score is low, both \(M_{1}\) and \(M_{2}\) take larger values, as the link stability is poor and adjustments to the data rate should be more conservative. Conversely, when the link state score is high, both \(M_{1}\) and \(M_{2}\) take smaller values. Table 8 provides the description of each parameter in Algorithm 1. The detailed process of the ED optional parameter acquisition algorithm based on link state awareness is shown in Algorithm 1. Figure 9: Overall flowchart of the ADR algorithm. ```
Input:\(SF_{tourn}\), \(BW_{tourn}\), \(TP_{tourn}\), score, \(SNR_{targ}\), \(RSSI_{targ}\), \(node_{num}\) Output:\(node_{num}\), \(TP\), list(SF), list(BW) \(M_{1}=10(1-score)\), \(M_{2}=30-20\cdot score\) \(SF_{temp}=SF_{tourn}\), \(BW_{temp}=BW_{tourn}\), \(TP_{temp}=TP_{tourn}\), list(SF) = [], list(BW) = [] \(SNR_{margin}=SNR_{agg}-SNR_{min}-M_{1}\), \(LM=RSSI_{agg}-\text{Sensitivity}-M_{2}\) \(N_{step}=\text{int}\Big{(}\frac{SNR_{margin}}{2.5}\Big{)}\) if\(N_{step}>0\)then while\(N_{step}>0\) and \(SF_{temp}>SF_{min}\)do \(SF_{temp}=SF_{tourn}-1\), \(LM=LM-2.5\) dB, \(N_{step}=N_{step}-1\) endwhile while\(N_{step}>0\) and \(TP_{temp}>TP_{min}\)do \(TP_{temp}=TP_{new}-3\) dB, \(LM=LM-3\) dB, \(N_{step}=N_{step}-1\) endwhile else if\(N_{step}<0\)then while\(N_{step}<0\) and \(TP_{temp}<TP_{max}\)do \(TP_{temp}=TP_{new}+3\) dB, \(LM=LM+3\) dB, \(N_{step}=N_{step}+1\) endwhile while while\(N_{step}<0\) and \(SF_{temp}<SF_{max}\)do \(SF_{temp}=SF_{tourn}+1\), \(LM=LM+2.5\) dB, \(N_{step}=N_{step}+1\) endwhile endif endif if\(LM>0\)then while\(LM-3\) dB \(>0\) and \(BW_{temp}<BW_{max}\)do \(BW_{temp}=BW\times 2\), \(LM=LM-3\) dB endwhile else while\(LM+3\) dB \(<0\) and \(BW_{temp}>BW_{min}\)do \(BW_{temp}=BW/2\), \(LM=LM+3\) dB endwhile endif while\(BW_{temp}>BW_{min}\)do  append \(BW_{temp}\) to list(BW), \(BW_{temp}=BW_{temp}/2\) endwhile return:\(node_{num}\), \(TP\), list(BW), list(SF)
```  
**Algorithm 1** End device optional parameter acquisition algorithm based on link state. Algorithm 1 outlines the basic steps of the ED optional parameter acquisition algorithm based on link state. The specific process is as follows: First, based on the obtained SNR margin, the sufficiency of link resources is determined.