Utilization-Weighted Algorithm for LoRaWAN Capacity Improvement for Local Smart Dairy Farms in Ratchaburi Province of Thailand

This paper presents Long Range Wide Area Network (LoRaWAN) scalability improvement using the Utilization Weighted (UW) spreading factor (SF) assignment algorithm that was logically designed to equalize SFs usage based on the M/D/1 queuing model. The test area containing dairy farms housing approximately 1,200 cows in Photharam district, Ratchaburi province of Thailand, was selected to simulate the proposed algorithm and evaluate its performance. The suburban Hata path loss model was chosen as a reference to incorporate the actual network environment into the simulation. It is then carefully optimized by factoring in the empirical path loss data collected in a 12-kilometer radius of the gateway location and then applying the parameters adjustment (PA) tuning method that proved to provide lower root mean square errors (RSMEs) than the RMSE tuning method. Two key performance indicators, including packet received rate (PRR) and energy consumption, were compared between the UW algorithm and the Min-airtime or traditional method. The simulation was focused on the 2-kilometer radius wherein most dairy farms reside. It was found that the UW algorithm provided higher PRR without jeopardizing the energy consumption comparing to the traditional LoRaWAN, due to the more equalization of SFs employment. The maximum improvement of PRR was around 43.90%, while the energy consumption level was maintained at approximately 113 J per day per node.


I. INTRODUCTION
Internet of Things (IoT) is one of the key technology enablers for digital transformation that currently raises global awareness. The adoption of IoT has proved to mitigate unresolved issues found in the traditional way of work and to help adopters foresee opportunities for their businesses and better quality of living. Numerous IoT solutions have been implemented in various contexts and scenarios such as smart agriculture, smart manufacturing, smart health care, smart living, etc.
In the context of agriculture, IoT has played an essential role in transforming traditional and manual farming into fully connected and automated farming. Future smart farms will integrate all functional components such as smart water irrigation, auto smart soil fertilizing, connected tractors, pesticide drones, livestock monitoring, etc., into one sizeable adaptive platform that utilizes data wisely for their maximum benefits.
To achieve end-to-end and cost-effective connectivity for smart agriculture, Low Power Wide Area Network (LPWAN) technologies that offer wireless connection over wide area coverage with low power consumption and low cost are the most suitable technologies [1]. Currently, three leading LPWAN technologies are Long Range Wide Area Network (LoRaWAN) [2], Narrow Band IoT (NB-IoT) [3], and Sigfox [4]. All of them operate in the unlicensed spectrum, but LoRaWAN is the only one that offers an open standard protocol that allows individual users to develop their private network.
Technically, all LPWAN technologies are designed to serve a massive number of connected devices. However, in real practice, human error and environmental factors such as terrains, buildings, structures, and the weather could hamper the effectiveness of data transmission and eventually impact the network capacity and thus scalability.
Our research initiative was real-time detections of signs of estrus in dairy cows using the LoRaWAN based smart detectors. The private LoRa network was implemented at a local dairy farm in Photharam district in Thailand's Ratchaburi province to provide connectivity. Nonetheless, to support thousands of cows in the area mixed of residential buildings and farmlands such as this district, scalability of LoRaWAN became our main concerned issue.
LoRaWAN employs the Additive Links On-line Hawaii Area (ALOHA) protocol for the uplink communication, allowing devices to transmit packets freely without checking the channel availability as the channel communication mechanism [5]. Although the duty cycle is deployed to regulate time usage to reduce collisions, previous studies indicated that LoRaWAN still has low network capacity, particularly in a high-density network [1,6].
For traditional LoRaWAN, each node is assigned with a spreading factor (SF) that has Received Signal Strength Indicator (RSSI) greater than the sensitivity of gateway and can provide minimum airtime, so-called the Min-airtime method. However, the study showed that the traditional technique is still insufficient to support the connection of thousands of IoT nodes [1]. Thus, several SF proportion management techniques were also proposed to enhance network capacity.
The simple technique is to simply equalize the number of nodes in each SF group [7]. However, although the technique can reduce collision probability compared to the traditional LoRaWAN, it is still unsuitable for a highly loaded network since higher SF packets tend to have a higher probability of collision. Thus, the airtime equalization was then pursued [7][8][9] with the concept of equalizing node airtimes in each SF group, resulting in a lighter load for the higher SFs group. However, the mentioned techniques only considered the same time interval between packets for all SFs.
Unlike other prior techniques, Utilization-Weighted (UW) [10] is an interesting algorithm that can provide an optimal number of SFs for both the same and various uplink time intervals among SFs. This method serves the duty cycle limitation of the industrial scientific and medical (ISM) radio bands defined for LoRaWAN. For example, the lower SF devices can send messages with higher data rates and shorter time intervals between uplinks. Thus, the UW algorithm may as well be an effective approach to improve network capacity.
This paper proposes applying the Utilization-Weighted (UW) SF assignment algorithm for LoRaWAN to achieve IoT system implementation for dairy farms in Photharam district, Ratchaburi province of Thailand. First, we demonstrated the planning of LoRaWAN at the actual test site. In order to obtain a network environment similar to that of the actual test site, the Hata path loss model [11] was employed and tuned using actual data collected on-site. Then, the performance of the UW algorithm-based LoRaWAN is evaluated through the simulation. It was then compared with the Min-airtime, the traditional LoRaWAN algorithm, in terms of Packet Received Rate (PRR) or a ratio of successful transmitted packets over sent packets and node's energy consumption.
The remainder of the paper is divided into 5 main sections. Section II is the introduction of the LoRaWAN. The UW algorithm and how it can improve the network capacity will be explained in section III. Network planning and path loss model optimization for the test site is later described in section IV. The performance evaluation of the UW algorithm when simulating a deployment of a largescale sensors network in the test site is presented in section V. Finally, the conclusions are provided in section VI.

II. LoRaWAN INTRODUCTION
LoRaWAN is a Low Power Wide Area Network (LPWAN) technology. Two main layers of LoRaWAN are physical and media access control (MAC).
First, LoRa uses the chirp spread spectrum (CSS) as its modulation scheme for the physical layer. Bit rates of LoRa signals depend on setting parameters such as spreading factor (SF), transmission power (Pt), and bandwidth (BW). If the devices transmit signals with different chirp rates, the signal will be orthogonal or not collide with each other. For example, with regards to SF setting, transmitting same size packets with different SFs will lead to different times on air as referring to where s T is symbol time (second).
The MAC layer is built on top of the LoRa physical layer to enhance communication management and security. For communication protocol, the LoRaWAN uses ALOHA, which is a random-access protocol for its uplinks. Furthermore, to reduce collisions, LoRaWAN also introduces the duty cycle policy to limit the airtime of each node. In this context, the node should not use that channel for , off i T , [12] which can be calculated from (2), after the transmission. , where j D is duty cycle of the channel (percent), i AT is time-on-air (ToA) of a packet sent by a node with SFi (second), and i is a value between 1 and 6 for SF7 to SF12, respectively.

III. UTILIZATION-WEIGHTED (UW) ALGORITHM
Utilization-weighted (UW) algorithm is one of the SF assignment algorithms [10]. This technique was designed based on the M/D/1 queuing model, which was adopted for the uplink of a LoRaWAN class A device and a single gateway [13]. For the M/D/1 queuing model, packets are received with the Poisson arrival rate λ and serving with the fixed service rate, μ. The service rate, i  , of each SF is defined as the duty cycle over the transmission time as where j D is duty cycle of the physical channel (percent), i AT is total transmission time on air of a packet sent by a node with SF i (second), i is a value between 1 and 6 for SF7 to SF12 respectively, and j is a value between 1 and c for c channels.
The arrival rate i  for a node can be calculated by 1 where i P is time interval between two uplink packet generations (second).
Then, a link utilization of a node, i  , or busy ratio of the channel for each SF can be calculated as However, to balance the utilization of the virtual channels or SFs to avoid channel overload, the utilizations of each SF group are equalized by deploying where i n is the number of nodes holding the SF in group i. We define the weight, wi, for the number of nodes of each SF as an inverse of the utilization, as shown in (7). Thus, the factor will distribute the loads from higher loaded channels to lower loaded channels.
Then, the optimal number of nodes for each SF can be calculated by ( ) where N is the total number of assigned nodes.

end for
From Algorithm 1, N is defined as the total number of nodes to be implemented in a network. SFinit stores initial SF, while SFopt vector stores optimal SF for each node, a [1 × N]. Noopt vector stores the number of nodes for each SF after optimization, a [1 × M]. For the number of the virtual channels, M is equal to 6 since SF can be configured from SF7 to SF12.
The steps for the deployment of the UW algorithm can be explained as follows. First, the SF will be assigned as same as the traditional LoRaWAN method based on RSSI. More specifically, the node will be first configured with the lowest possible SF that has the gateway sensitivity lower than the node's RSSI. However, the optimal number of nodes for each SF group or Noopt will later be managed by following the calculation in (8) or i n equalizing virtual channels' usage. Finally, in order to avoid packet loss, the node will be reassigned with higher SF only.
To preliminarily evaluate the performance of UW algorithm, we compared it with the traditional LoRaWAN algorithm or Min-airtime algorithm by using the same default network environment. Both algorithms were compiled by using LoRaSIM [1]. Table I shows simulation  parameters. As shown in Fig. 1, the UW SF assignment algorithm did outperform the Min-airtime algorithm. The PRR of the UW algorithm is significantly higher than the Min-airtime algorithm for all cases. The greatest PRR improvement of the UW algorithm over the Min-airtime algorithm is approximately 34%, 36%, and 35% for 120, 600, and 1,200 nodes, respectively.

IV. LoRaWAN PLANNING FOR THE TEST SITE
This section presents the LoRaWAN planning for the test site in Photharam district in Ratchaburi province of Thailand. First, the suburban type of the popular Hata path loss model was selected as the reference path loss model since it closely resembles our test site environment. It was then optimized to better represent the actual path loss in the site using two tuning methods: RSME and parameter adjustments. Finally, the comparison was made, and the better one was employed in the network performance evaluation reported in section V.

B. PATH LOSS MODEL OPTIMIZATION FOR THE TEST SITE
In this section, the Hata path loss model that is our reference model used in this research is briefly described. We then performed and compared Root Mean Square Error (RMSE) and model parameters adjustment (PA) tuning methods based on actual collected path loss data to optimize the path loss model specifically for the test site environment. Hata [11] is one of the empirical propagation models to predict path loss or amount of signal power reduction from transmitter to receiver. THIS MODEL WAS DESIGNED FOR the OPERATING Frequency from 150 to 1,500 MHz. This path loss prediction model can be used for diverse environments such as urban, suburban, and rural areas. The standard equation for Hata model is shown in equation (9).
For small or medium sized cities: For suburban and rural areas, () r ah is the same as for small and medium-sized cities. The model also defines correction factors (C) used for urban, suburban, and rural areas. They are as following: Small and medium cities: 0 C = Suburban:

2) TUNING METHODS
The propagation model might not always be accurate for real practices due to its discrepancy from the actual environment. In this situation, tuning methods are commonly used to increase path loss accuracy. Several methods have been proposed to tune the path loss model [14][15][16][17]. The most popular method is the root mean square error (RMSE), or the so-called RMSE based method [14][15]. This approach tunes the models by adding or subtracting RMSE to the standard model. The RMSE can be calculated by where RMSE is a root mean square error between measured and predicted values, Lm(i) is a measured path loss value, Lp(i) is a predicted path loss value from the standard path loss, and i is a focused location.
The other technique is the least square method used to determine the optimal corrections [14][15][16][17]. In this paper, we call this method as model parameters adjustment (PA). In the case of the Hata model, the tuning coefficients can be calculated by applying the following approach.
From [16][17], the basic formula of predicted path loss is shown in terms of J and K coefficients as For fixed heights of transmitter and receiver, the coefficients of the distance between the transmitter and receiver will be tuned to increase the prediction accuracy by adding 1 K and 2 K values from Mostly, 1 K and 2 K values can be calculated by using the linear least square method [18]. Even though the least square method is more complex than the RMSE-based method, previous studies showed that the technique could provide better prediction accuracy [14][15].

3) PATH LOSS MODEL OPTIMIZATION FOR THE TEST SITE
In order to optimize the path loss model for the test site, actual path loss characteristics around the test site are needed. The drive test was then performed around Centermilk farm to measure and collect Receive Signal Strength Indicator (RSSI) data and determine signal coverage. We used Kerlink Wirnet station, an outdoor grade LoRa gateway with Semtech SX1301 chip as a receiver (Rx). It was installed 10 meters above the ground in the Centermilk farm area. We built a transmitter (Tx) node using the Arduino UNO R3 controller embedded with LoRa SX1276 chip. The Tx node was attached at 1.5 meters high on the top of the drive test car. To investigate the maximum coverage, we considered the farthest signal range by selecting the largest SF of 12 or SF12. The other significant parameters were set following the standard of LoRaWAN AS923 band and are summarized in Table II. Test radial paths were set up every 30 degrees around the gateway, a total of 12 paths. We ran the drive test to record the RSSI data every 500 meters along each path. Data were collected until the Tx-Rx connection was lost. After we obtained the results from field measurements, we converted the RSSI from the measurement (RSSIm) to path loss since propagation models are in the form of signal power reduction. The path loss from measurement (Lm) (in dBm) can be acquired from where Pt is transmitting power (dBm), Gt is transmitter antenna gain (dB), Gr is receiver antenna gain (dB), i is a focused location. From table II, the measured path loss then becomes The Hata suburban model was considered our reference prediction model since the test site is suburban. Thus, the theoretical path loss of the Hata suburban model (PLHata) can be calculated by substituting (10), (11), (12), and (14) into (9). The accuracy of the Hata suburban model was considered in terms of RMSE. We can see from Table III that RMSE values obtained from the reference Hata model are between 10.88-27.90 dB. Since the acceptable range of RMSE should be between 10-15 dB for the suburban case [19], we then further tuned the standard suburban Hata model using RMSE and PA-based methods. We tuned each path separately, considering that path-specific corrections would provide a more suitable model for our environment and setup. The path loss of RMSE and PA-based methods can be calculated from (18) and (19), respectively. The RMSE values from both tuned models were used to compare the performances of both tuning techniques, as also shown in Table III.
The tuned model of the RMSE-based method is acquired by adding or subtracting the RMSE values to the standard suburban model from Table IV for each path. On the other hand, the PA tuned model can be obtained by substituting the standard Hata suburban model, K1 and K2 into (20). The optimal tuned K1 and K2 for each path are also indicated in Table IV.

C. NETWORK COVERAGE PREDICTION
After we obtained the optimal path loss model of the test site, we further explored and planned the network capacity for the area. For the optimal path loss model, the tuning parameters from Table IV were added to the equations of the Hata suburban model. We simulated the LoRaWAN class A network using LoRaSIM [1] as the LoRa simulator and followed the sensitivities of the gateway from [20]. We determined coverage prediction based on RSSI and path loss equation in (22). Since the RSSI must be higher than the sensitivity to avoid packet loss, when we substituted the lowest sensitivity of gateway, which is -139.50 dBm for SF12 with BW 125 kHz and the settings in Table I into (22), the maximum path loss became 162.50 dB. Then, we calculated the maximum distance using path loss model equations by substituting maximum path loss and K1 and K2 into (20) for each path, as shown in Fig. 3. It is important to note that the apparent offset at path 12 was caused by the obstruction of a milk processing plant.
We set the single gateway at the coordinate (0,0) for our simulation and randomly generated the nodes only within the highlighted sectors according to the survey shown in Fig. 2. Also, we chose the number of nodes as 1,200 nodes for our first setup since the number of dairy cows in the area is approximately 1,200 cows. However, to explore the network capacity for farmland expansion, we deployed the setups with nodes up to 6,000 nodes. We randomly set the time interval between uplinks for inter-arrival time, based on the exponential distribution, which is frequently used to model the expected time between an event. Note that, the mean of , off i T was limited by the duty cycle. In the case of LoRaWAN in Thailand, the duty cycle is limited to 1%, which means that a node can only send data for a total of 36 seconds in 1 hour. In other words, simulation setup with , off i T will provide the nodes with the maximum usage per day and lead to the understanding of the maximum capacity of the network. Other simulation parameters are defined as shown in Table V

V. PERFORMANCE EVALUATION OF THE UW ALGORITHM FOR THE TEST SITE
In this section, we applied the UW algorithm to evaluate its performance and ability to improve the network capacity for the test site, compared with the Min-airtime algorithm of the traditional LoRaWAN. The PRR values from both algorithms were collected and compared. For the traditional LoRaWAN algorithm, we found that the nodes mainly were assigned with SF7 since most farms are located nearby the gateway and the traditional algorithm assigns SFs based on RSSI, which leads to assigning most of the nodes with SF7. On the other hand, the UW algorithm is designed to distribute SF7-SF12 nodes to achieve equal utilization of all virtual channels. The examples of SF distributions for 1,200 nodes are shown in Figs. 4 and 5 for the traditional LoRaWAN and UW algorithms, respectively.
In terms of PRR, Fig. 6 indicates that the PRRs of both algorithms decreased when the number of nodes increased. The PRR of UW algorithm notably increased compared to the PRR of the traditional LoRaWAN algorithm. The greatest improvement was 43.90%. For the traditional LoRaWAN technique, most nodes were configured with SF7, which means that the SF7 virtual channel had more traffics than others, resulting in overburdening the SF7 virtual channel. On the other hand, the UW algorithm was able to equalize the utilization on each virtual channel by decreasing the use of SF7 and increasing the resource utilization of the other SFs. Since the virtual channels are orthogonal, distributing the nodes from the SF7 group to others leads to lower collision events, eventuating in the significant improvement of PRR.  Concerning the energy consumption, the total energy consumption per day increased when the number of nodes increased for both algorithms, as shown in Fig. 7. However, the total energy per node per day did not significantly change. From the result, each node consistently consumed about 113 J per day. Therefore, the UW algorithm-based LoRaWAN still exhibited a low power characteristic similar to the traditional LoRaWAN.

V. CONCLUSIONS
This paper applied the UW algorithm to improve LoRaWAN network scalability for smart dairy farm management at Photharam district in Ratchaburi province of Thailand. The path loss model for the area was obtained by tuning the Hata path loss model with the PA-based method since the RMSEs of PA were lower than the RMSE-based 9 method for all paths. As a result, within the coverage of 2 km, the UW algorithm improved PRR of 43.90% compared to the traditional LoRaWAN. The significant increase in PRR was owed to equalizing packet transmissions on each virtual channel (SF7-SF12), which resulted in lower packet collision. Likewise, the UW algorithm also maintained the comparable energy consumption to the traditional LoRaWAN method, at around 113 J per day per node. Future works include consideration of the presence of downlink and other parameter adjustments such as transmission power. Her current research interests include internet of things (IoT) solutions for smart farming and asset tracking, low power wide area network, radio propagation, and antenna design for 5G.
Dr. Rardchawadee is a member of IEEE and Innovative Electromagnetics Academy of Thailand (iEMAT). She founded the innovation experience program (IX program) in 2019 with an aim to build IoT products and services for Thailand through workforce development. Since the beginning of her career, she has received several research grants from government funding agencies and private sectors.