# LoRa Enabled Smart Inverters for Microgrid Scenarios with Widespread Elements
## 5 LoRa Enabled Smart Inverters
### LoRa Latency Test  
To demonstrate the latency charactristics of LoRa, a test has been performed by using two Pycom/Lopy4 transceivers (one transmitter and one receiver, Figure 6) described as the following:  
1. The devices' real-time clocks (RTC) are synchronized by obtaining the time from the same network time protocol (NTP) server. (Denmark--dk.pool.ntp.org, accessed on 3 September 2021). 2. A timestamp is created on the transmitter just before the transmission is initiated. Therefore, the ToA, which is basically the transmission time, is included in the latency computation. This timestamp is sent as the actual payload of the Tx frames. 3. The receiver is coded in a way that another timestamp is created immediately after the transmitted frame is received. In this way, on the receiver side, both transmission and reception timestamps are available and have been stored for post-processing. The experiment is repeated for all the SFs. At each step, 500 frames are sent every 4 s with the payload size of 20 bytes, and the results are presented in detail as boxplots in Figure 7. In addition, a comparative illustration is provided in Figure 8 that demonstrates the effect of adding SFs on LoRa transmission latencies. Figure 5: Comparison between LoRaWAN and NB-IoT characteristics. Figure 6: Pycom/Lopy4 microppython enabled microcontroller and 868 MHz antenna, used to create LoRa nodes. Figure 7: LoRa Latency statistical illustration. It should be noted that, since only two devices have been implemented and no other activities were identified in the local 868 MHz bands at the time of the experiment, these recorded latency values are relatively idealistic estimations. In other words, apart from small computation and processing delays, the recorded latency values represent the LoRa frames ToA for different spreading factors. It is useful to compare the latency results with theoretical packets ToA. According to references [75; 76] a LoRa frame ToA consists of two elements, preamble ToA and payload ToA, which are calculated as follows:  
\[\textit{PreambleToA}=(PRS+4.25)\frac{1}{SymbolRate}\quad(sec) \tag{7}\]  
\[\textit{PayloadToA}=(8+max(celi(\frac{8 PLB-4 SF+28+16 CRC}{4 SF})( CodingRate+4),0))\frac{1}{SymbolRate}\quad(sec) \tag{8}\]  
where PRS defines the number of preamble symbols that is 8 in this case, PLB is the number of payload bytes which is fixed on 20, SF is the spreading factor, and CRC is the cyclic redundancy check indicator and set to zero, The configured coding rate is set to 4.8. By using Equations (7) and (8) and also Equation (5), the theoretical LoRa frames ToA values are calculated and compared with the latency results in Table 2. Same as before, the LoRa configured bandwidth is 125 kHz. As can be observed, the theoretical ToA values are less than the recorded latency for all SFs. This is due to computation delays at both microprocessor transmitters. However, further analysis is required to investigate this phenomenon that will be conducted in a future study by the authors. In addition, the ToA and overall latency strongly depend on the bandwidth that the LoRa channel is using. As mentioned before, there are three standard possibilities of 125 kHz, 250 kHz, or 500 kHz. As final latency remarks, it should be noted that in large-scale deployments communication nodes compete to access the wireless medium by the use of their MAC protocols. This medium (band) can not necessarily accommodate all awaiting transmissions in every instant, which is one of the major causes of delays in wireless communication systems and is called medium access delays. Furthermore, low-power devices are designed to \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline  & **SF7** & **SF8** & **SF9** & **SF10** & **SF11** & **SF12** \\ \hline Theoretical ToA & 0.046 & 0.086 & 0.162 & 0.304 & 0.583 & 1.102 \\ AVE Measured Latency & 0.062 & 0.127 & 0.200 & 0.386 & 0.752 & 1.365 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Average measured delays for SF 7–12. Figure 8: Average measured latency values for LoRa transmission.