# Firmware Updates over the Air via LoRa: Unicast and Broadcast Combination for Boosting Update Speed
## 4 Analytical Expression of the Total Update Time
### Only Unicast Method  
The gateway starts with the update of the first node: it sends the first chunk, waits for a valid ACK, then sends the second chunk, and so on. The process is repeated until the \(N^{\text{th}}\) node is updated.  
To correctly calculate the update time, the duty cycle must also be considered, as it affects every frame, including the ACKs. It works this way: let us assume that the duty cycle is \(d\) (a typical value for \(d\) is 1, which means a duty cycle of 1%). This means that when a node sends or receives a frame that occupies a certain Time on Air (\(T\!\!\alpha A\)), no frame will be sent during a time equivalent to:  
\[\left(\frac{100}{d}-1\right)\cdot ToA. \tag{1}\]  
As an example, if \(T\!\!\alpha A\) is 313 ms and \(d=1\), the nodes will wait 99 \(\times\) 313 ms = 30,987 s after being allowed to send a new message.  
Therefore, the total transmission time for sending a chunk to a node consists of the time spent during the failed attempts, plus the time required for the final successful transmission. Let \(p_{j}\) be the probability of node \(j\) not receiving a chunk correctly. If a chunk requires \(i\) transmissions, this means that it has failed \(i-1\) times (a failure happens with a probability \(p_{j}\)) and arrived one time (this happens with a probability \(1-p_{j}\)). So, the average number of times that a chunk will be sent to node \(j\) can be obtained as the next sum:  
\[\sum_{i=0}^{\infty}i\big{(}1-p_{j}\big{)}p_{j}^{\;\;i-1}=\big{(}1-p_{j}\big{)} \frac{1}{\big{(}1-p_{j}\big{)}^{2}}=\frac{1}{1-p_{j}}. \tag{2}\]  
The second term is a power series like \(\sum_{i=0}^{\infty}i\cdot p^{i-1}\), which converges for \(|p|<1\). In this case, the sum of the series is given by the formula \(S=1/(1-p)^{2}\). Therefore:  
\[\big{(}1-p_{j}\big{)}\sum_{i=0}^{\infty}ip_{j}^{\;\;i-1}=\big{(}1-p_{j}\big{)} \frac{1}{\big{(}1-p_{j}\big{)}^{2}}=\frac{1}{1-p_{j}}. \tag{3}\]  
This means that the number of unsuccessful transmissions before the final (successful) one will be:  
\[\frac{1}{1-p_{j}}-1=\frac{p_{j}}{1-p_{j}}. \tag{4}\]  
Let \(T\!\!\alpha A_{\text{ch}}\) be the transmission time of a chunk and \(T\!\!\alpha A_{\text{ack}}\) the transmission time of an ACK. Each unsuccessful transmission takes \(T\!\!\alpha\) plus the corresponding wait time. The time spent on the transmission of unsuccessful chunks to node \(j\) will be given by the product of the number of transmissions (4) and the time spent on each of them (1):  
\[\frac{p_{j}}{1-p_{j}}\cdot\bigg{[}T\!\!\alpha A_{\text{ch}}+\bigg{(}\frac{100 }{d}-1\bigg{)}\cdot ToA_{\text{ch}}\bigg{]}. \tag{5}\]The time spent by the final successful transmission has four components: first, the time for the transmission of the chunk (\(T\!\alpha A_{ch}\)); second, the wait time; third, the time on air of the ACK (\(T\!\alpha A_{ack}\)); and fourth, the wait time after the ACK:  
\[T\!oA_{ch}+\left(\frac{100}{d}-1\right)\cdot\!T\!oA_{ch}+T\!oA_{ack}+\left(\frac {100}{d}-1\right)\cdot\!T\!oA_{ack}. \tag{6}\]  
Therefore, the time spent sending \(M\) chunks to \(N\) nodes using the _only unicast_ method (denoted as \(t_{uni}\)) will be given by the expression:  
\[t_{uni}\ =\ M\cdot\!\frac{100}{d}\cdot\sum_{j=1}^{N}\left(\frac{1}{1-p_{j}} \cdot\!T\!oA_{ch}+T\!oA_{ACK}\right). \tag{7}\]