# Reducing Detrimental Communication Failure Impacts in Microgrids by Using Deep Learning Techniques
## 5 Communication Protocol and Latency
### Latency Experiment with Various Payload Sizes  
There are several elements that contribute to the overall end-to-end latency in a wireless communication system. They are processing/queuing latencies, MAC latencies and transmission latencies [41]. Among those, the transmission latencies depend on the size of the header(s) and payload of a specific communication frame. The latency measurements in this study are only focused on the effect of the size of the payload on the overall MQTT latency, more comprehensive MQTT latency measurements and analysis, and also including the effect of different MQTT QoS levels can be found in [2]. This is because it is required to work out what will happen when an enhanced message is being sent from the EMS that can be considerably larger than a normal message with a single payload, and finally to determine if the time on air (ToA) of the enhanced message is acceptable. Needless to say, if the enhanced message latencies become too large then the whole communication system will no longer be suitable for this particular application. An experimental testbed consisting of two PCs, where MQTT clients were created using python-paho package, and a mosquito MQTT broker was implemented to evaluate the effect of changing payload size on end-to end MQTT latency. In this test, different payloads consisting of 1, 10, 100, 1000, 2000, and 4000 numerical values (three digits) that each of them can represent measurements or references were tested. By comparing the transmit and receive timestamps, latency for a single transmission is calculated. An average value of ten iterations per each payload size produced a realistic estimation of overall latency for different cases. The results are presented in Table 4 and Figure 10.  
It can be observed from the results that for the cases of less than 1000 messages the latencies remain fairly constant with a value of approximately 150 milliseconds. Beyond this point, the latencies increase since the payloads need to be divided to a number of TCP segments. It should be noted that the maximum size of a TCP segment is limited to 1500 bytes including its IP and TCP headers [42]. The payload sizes and TCP segment counts of the MQTT frames are obtained by using Wireshark which is an open source and widely recognized network protocol analyzer. The following are key notes and findings regarding this experiment:  
* In order to measure the latencies the transmitter and receiver clocks should be synchronized. Since two separate PCs were utilized, using windows internet-time and synchronizing them to the same time-server seems to be a feasible option. However, in practice, this method did not provide sufficient synchronization accuracy, especially when measuring latency in the millisecond scale. Therefore, we synchronized our transition and reception timestamps to a network time protocol (NTP) server, specifically _\"pool.ntp.org\"_, in the python programming environment. * The fact that latency values are relatively unaffected for payloads containing less than 1000 numeric values is not unexpected. This is because the testbed WLAN physical protocol is IEEE 802.11n with a nominal link speed of 45 (Mbps). Comparing the scale of this bandwidth with the size of the experimental messages payloads proves the aforementioned fact. * The measured value of 150 milliseconds that was recorded for most of the packets was not related to transmission latencies (due to the tiny size of frames and abundant available bandwidth of the channel). Furthermore MAC latencies were also not present, therefore this shared value only represents processing and queuing latencies. \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Number of Data** & **1** & **10** & **100** & **1000** & **2000** & **4000** \\ \hline Latency (milliseconds) & 147 & 151 & 154 & 161 & 205 & 291 \\ Payload size (bytes) & 21 & 89 & 418 & 4017 & 8016 & 16,018 \\ TCP Segment count & 1 & 1 & 1 & 3 & 6 & 11 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Latency test results for various payload sizes.