# Communication Protocol Design for IoT-Enabled Energy Management in a Smart Microgrid
## 3 Information Exchange between HEMSs
### k Odd, \(\ell\) Even  
In this case, during the first time slot, the \(\bar{k}\)th HEMS (\(\bar{k}\in\mathcal{K},k\leq\bar{k}\leq\ell\) and \(\bar{k}\mod 2\
eq 0\)) transmit and the \(\bar{\ell}\)th HEMS (\(\bar{\ell}\in\mathcal{K},k\leq\bar{\ell}\leq\ell\) and \(\bar{\ell}\mod 2=0\)) receives the messages, as in (1), and estimates them as \(\hat{u}_{\bar{\ell}-1}\) and \(\hat{u}_{\bar{\ell}+1}\). On the other hand, in the second time slot, the \(\bar{\ell}\)th HEMS (\(\bar{\ell}\in\mathcal{K},k\leq\bar{\ell}\leq\ell\) and \(\bar{\ell}\mod 2=0\)) transmits and the \(\bar{k}\)th HEMS (\(k\in\mathcal{K},k\leq\bar{k}\leq\ell\) and \(\bar{k}\mod 2\
eq 0\)) receives as follows:  
\[v_{\bar{k}}= \begin{array}{cc}h_{\bar{k}-1,\bar{k}}u_{\bar{k}-1}+n_{\bar{k}}& \text{if}&\bar{k}=1\\ h_{\bar{k}-1,\bar{k}}u_{\bar{k}-1}+h_{\bar{k}+1,\bar{k}}u_{\bar{k}+1}+n_{\bar{ k}}&\text{if}&\bar{k}\
eq 1\end{array}  \tag{5}\]  
The received signals are estimated as \(\hat{u}_{\bar{k}-1}\) and \(\hat{u}_{\bar{k}+1}\). In the third time slot, the \(\bar{\ell}\)th HEMS forwards the sum of the decoded signals from the first time slot to the \(\bar{k}\)th HEMS, where the received sum of signals is given by (2). The \(\bar{k}\)th HEMS then decodes \(\hat{V}_{\bar{k},k+2}\) and \(\hat{V}_{\bar{k},\bar{k}-2}\) as an estimate of the corresponding sum of the signals. After this, the \(\bar{k}\)th HEMS computes \(\hat{V}_{\bar{k},\bar{k}+2}\oplus u_{\bar{k}}\) and \(\hat{V}_{\bar{k},\bar{k}+2}\oplus u_{\bar{k}}\) to obtain the signals from the \((\bar{k}-2)\)th and \((\bar{k}+2)\)th HEMSs. Similarly, during time slot 4, the HEMSs indexed by \(\bar{k}\) compute the sum of the decoded signals from time slot 2 and forward that to the HEMSs indexed by \(\bar{\ell}\). Thus, the \(\bar{\ell}\)th HEMSs receive the signal as follows:  
\[v_{\bar{\ell}}= \begin{array}{cc}h_{\bar{\ell}+1,\bar{\ell}}(\hat{u}_{\bar{ \ell}}+\hat{u}_{\bar{\ell}+2})+n_{\bar{\ell}}&\text{if}&\bar{\ell}=K\\ h_{\bar{\ell}-1,\bar{\ell}}(\hat{u}_{\bar{\ell}-2}+\hat{u}_{\bar{\ell}})+h_{ \bar{\ell}+1,\bar{\ell}}(\hat{u}_{\bar{\ell}}+\hat{u}_{\bar{\ell}+2})+n_{\bar{ \ell}}&\text{if}&\bar{\ell}\
eq K\end{array}  \tag{6}\]  
The \(\bar{\ell}\)th HEMS then decodes \(\hat{V}_{\bar{\ell},\bar{k}+2}\) and \(\hat{V}_{\bar{\ell},\bar{k}-2}\) as an estimate of \(\hat{u}_{\bar{\ell}}\oplus\hat{x}_{\ell+2}\) and \(\hat{u}_{\bar{\ell}}\oplus\hat{x}_{\ell-2}\), respectively. After this, the \(\ell\)th HEMS cancels its own message to obtain the \((\ell-2)\)th and \((\ell+2)\)th HEMSs' signals. The process continues until the \((\frac{|\ell-k|+1}{2}+1)\)th time slot. After that, the \((\frac{|\ell-k|+1}{2})\)th HEMS obtains the signal of the \(k\)th and \((\ell-1)\)th HEMSs. On the other hand, the \((\frac{|\ell-k|+1}{2}+1)\)th HEMS obtains the signal of the \((k+1)\)th and \(\ell\)th HEMSs. Then, during the \((\frac{|\ell-k|+1}{2}+2)\)th time slot, the \((\frac{|\ell-k|+1}{2}+1)\)th HEMS forwards the sum of the received signals to the two adjacent HEMSs. In effect, the \((\frac{|\ell-k|+1}{2}+1)\)th HEMS now receives  
\[v_{\frac{|\ell-k|+1}{2}+1}=h_{\frac{|\ell-k|+1}{2}+1,\frac{|\ell-k|+1}{2}}(\hat {u}_{\bar{k}}+\hat{u}_{\ell-1})+n_{\frac{|\ell-k|+1}{2}+1} \tag{7}\]  
Similarly, during the \((\frac{|\ell-k|+1}{2}+3)\)th time slot, the \((\frac{|\ell-k|+1}{2}+1)\)th HEMS forwards the sum of the signals and the \((\frac{|\ell-k|+1}{2})\)th HEMS receives  
\[v_{\frac{|\ell-k|+1}{2}+1}=h_{\frac{|\ell-k|+1}{2}+1}(\hat{u}_{\bar{k}+1}+\hat {u}_{\ell})+n_{\frac{|\ell-k|+1}{2}} \tag{8}\]After these two time slots, the \((\frac{|\ell-k|+1}{2})\)th HEMS decodes \(\hat{V}_{k+1,\ell}\) as an estimate of \(\hat{u}_{k+1}\oplus\hat{u}_{\ell}\). Since the \((\frac{|\ell-k|+1}{2})\)th HEMS already knows \((k+1)\)th HEMS's signal, it can cancel the known information to extract the \(\ell\)th HEMS's signal. Similarly, the \((\frac{|\ell-k|+1}{2}+1)\)th HEMS can decode \(\hat{V}_{k,\ell-1}\) and then utilise the \((\ell-1)\)th HEMS's signal to obtain the message from the \(k\)th HEMS.