# River Water Quality Monitoring Using LoRa-Based IoT
## 3 IoT Technologies
### LoRa Modulation
The final bitrate calculation, \(R_{b}\), is calculated according to (4) below:  
\[R_{b}=SF*\frac{BW}{2^{SF}}*\frac{4}{4+CR}\;[\mathrm{bit/s}], \tag{4}\]  
where:  
* \(SF\) is the spreading factor [7...12];
* \(BW\) is the modulation bandwidth [Hz];
* \(CR\) is the code rate (number of redundant bits) [1...4]. There is an increase in bitrate for lower SF and higher BW; see Figure 6. And of course, if we increase the number of redundant bits (CR), the bitrate will also increase. The preamble is used to synchronize the receiver with the received data stream and begins with a sequence of \(n_{preamble}\) up-chirps, followed by two up-chirps that contain a  
Figure 6: Bitrate and spreading factor relationship (CR = 1). Figure 7: LoRa packet format (adapted from [18]). synchronization byte (sync word) and ends with two and a fourth down-chirps. The value of the sync word is to differentiate LoRa networks. In the case of LoRaWAN, this value is 0x34 [19]. The \(n_{preamble}\) size can vary between 6 and 65,535, but by default, on Semtech transceivers it is 8. The receiver begins the detection process, and this process occasionally restarts. For this reason, the length should be configured to be identical to the transmitter length. Where the length is not known, or can change/differ, the maximum length should be programmed on the receiver side. The preamble period, \(T_{preamble}\), can be calculated with (5). Figure 4:0  
where:  
* \(n_{preamble}\) is the number of programmed preamble symbols;
* \(T_{sym}\) is the symbol period [s]. Depending upon the chosen mode of operation, two types of header mode are available:  
* Explicit mode--This is the default mode of operation [20]. Here, the header provides information on the payload, namely payload length in bytes, forward error correction code rate and presence of an optional 16-bit CRC for the payload [20]. The header is transmitted with maximum error correction code (4/8) [20]. It also has its own CRC to allow the receiver to throw out invalid headers. * Implicit mode--In certain pictures/situations, where the payload, coding rate and CRC presence are fixed or known in advance, it may provide an advantage to reduce transmission time by calling for/using an understood header mode [20]. In this mode, the header is removed from the packet [20]. In this case, the payload length, error coding rate and presence of the payload CRC must be manually configured on both sides of the radio link [20]. The payload contains the data to transmit, which may or may not be followed by the CRC (two bytes) and can have a size of up to 255 bytes (including the CRC). Equation (6) calculates the number of symbols, \(pSymN\), in the payload. Figure 4:1  
where:  
* \(PL\) is the number of payload bytes;
* \(SF\) is the spreading factor [7...12];
* \(H\) = 0 when the header is enabled, and H = 1 when no header is present;
* \(DE\) = 1 when low data rate optimization is enabled, and DE = 0 when disabled;
* \(CR\) is the code rate (number of redundant bits) [1...4]. And the total duration of the LoRa packet, \(T_{packet}\), is given by Equation (7):  
Figure 4:2  
where:  
* \(T_{preamble}\) is the preamble period [s];
* \(pSymN\) is the number of symbols;
* \(T_{sym}\) is the symbol period [s]. As seen in Figure 8, the packet duration is directly proportional to the number of payload bytes and to the SF. \(T_{packet}\) also increases slightly to the highest CR values, as more additional redundancy bits are included. The packet duration, \(T_{packet}\), also means the Time on Air (\(ToA\)) and is the time a LoRa device is transmitting. To comply with legal requirements as to the time of occupancy of the channel (duty-cycle), there is a need to use the duration of \(ToA\) to calculate the time between successive transmissions, \(T_{TX\_off}\), by Equation (8). Figure 4:3  
where:  
* \(ToA\) is the Time on Air (equal to \(T_{packet}\)) [s];
* \(duty\_cycle\) is the channel occupancy time ratio.