1. Introduction
With the diffusion of the Internet-of-Things (IoT) paradigm [
1], objects are being connected to the Internet, thus realizing a global network of connected things. This new concept is being used in several scenarios, such as in smart cities [
2,
3], industrial manufacturing [
4,
5], healthcare [
6,
7] and transportation [
8,
9]. Another application scenario is in rural areas [
10,
11], and specifically on smart livestock farming [
12], over which we focus our work.
In rural areas, it is important to have sensor nodes that can operate for long time without human intervention, and capable to transmit data over a wireless communication channel [
12]. Low Power Wide Area Networks (LPWANs) can satisfy the data communication requirements typical of this environment, which are flexibility, resistance to multipath and other types of interference, and wide coverage. ZigBee, SigFox, NB-IoT, and LoRa are among the most frequently used technologies for the implementation of rural LPWANs [
13,
14]. With respect to the other competing technologies in the LPWAN scenario, LoRa does not require a third-party infrastructure for channel access, but it can act in an almost decentralized way [
13,
14]. This means that the LoRa end devices (EDs) do not pay fees for communicating and they must only adhere to regulatory spectrum requirements.
In this work we use LoRa, since it also offers good performance in terms of battery life, at a relatively low cost, and it is resilient to transmission errors while maintaining a wide coverage [
15]. Moreover, the typical coverage range of LoRa varies from 2–5 km in urban areas to 20–25 km in suburban or rural environments [
15], making this technology viable for both small and medium-scale applications. It has also been shown that a single LoRa gateway can manage a large number of EDs with little maintenance and easy deployment [
5].
LoRa is a proprietary wireless communication standard developed by Semtech, based on a chirp spread spectrum (CSS) modulation [
16,
17]. The physical layer (PHY) uses chirp waveforms with different chirp rate, to maintain orthogonality among different classes of users, and with different initial frequency, to convey the actual information message [
15]. Channel coding is also used, with interleaving and Hamming block codes. Although the details of the LoRa PHY are not public, several authors have tried and succeeded to reverse-engineer, almost completely, its PHY communication techniques [
18].
On the other side, LoRaWAN is an open MAC protocol, built on top of the LoRa PHY, that is specifically designed for low-powered devices operating over long-range wireless links. Even though LoRaWAN is commonly used in deploying LoRa networks [
19], in this work we have decided to implement a custom MAC layer in order to have more control over the architectural design and to remove some features of the LoRaWAN layer [
20] that are not used in our application, such as the large header size when short payloads have to be delivered, and the packet acknowledgments managed by a LoRa server. Continuous and near-real-time monitoring of livestock, in particular of dairy cattle, can help to provide information vital to study the animal behavior and to prevent pathological states that have a negative impact on livestock health [
21,
22].
In particular, our proposed architecture aims at analyzing, almost in real-time, the status of dairy cattle in a cowshed or during grazing by means of sensors embedded in smart collars. By the way, this approach may be extended also to other kinds of livestock, such as beef cattle, swine, ovine, and even equine.
In this paper we first describe the overall architecture of the proposed livestock monitoring scheme. With respect to other similar systems described in the literature, our architecture uses a simpler MAC layer to alleviate the need for a central server to manage the acknowledgments, and also comprises the data storage platform through which the clients may perform their data analysis tasks. The main purpose of the proposed architecture is to collect, store, and analyze several parameters typical of the cattle livestock scenario, related to the health of each head of the herd and to the habitat where cattle are kept. Then, we show in detail how we designed and implemented the different objects that implement and overview the sensor network. We give a description in terms of both functional hardware and software and firmware used to control the sensors and the system controllers. We will also describe the implementation of a MAC-level simulator that we have designed to test and optimize some parts of the proposed sensor network. Eventually, we will conclude our paper with the results of several simulations, as well as with some preliminary results on the performance of the real system.
2. Related Works
In the literature there are several studies related to object and environmental monitoring by means of LoRa, concerning agriculture and livestock farming [
19,
21,
23,
24,
25], health [
26], forestry [
12,
27], smart cities [
2,
28], industrial [
4,
5,
29] and maritime [
9] applications.
For what concerns agriculture and livestock farming, in [
23] the authors present the WAZIUP IoT system used, among other things, also for cattle management in rural Africa, which is based on LoRa for long-range connectivity. This research has established some low-cost designs for both the sensor devices and the gateways, which are based on Arduino and Raspberry Pi. The goal is to avoid cattle theft, by monitoring position and speed of the animals, but no information is provided on other biomarkers such as body temperature and motion. Agriculture monitoring is the target of the work described in [
24]. In particular, [
24] focuses on a sensor network devoted to the monitoring of environmental parameters in the field (temperature, humidity), and to a parallel actuator network that is used to remotely operate on vineyards for automated irrigation. The paper [
24] does not provide details of the used hardware, nonetheless [
24] adopts a LoRaWAN network and a commercial service provider for cloud-related tasks. In [
25], vital signs of grazing cattle are collected via a LoRa network. The authors of [
25] design portable nodes built around the STM32 microcontroller, and equip them also with accelerometers and global navigation satellite system (GNSS) positioning. The gateway uses a Raspberry and a dedicated multi-channel LoRa chip. The investigation is mainly focused on the coverage radius and packet loss: Some findings in [
25] show that a maximum distance of 900 m can be covered in an urban scenario with many buildings, which rises to 2 km on open roads. LoRa is also used in [
21] to control environmental parameters such as
concentration and temperature in pig houses. The system in [
21] collects the gaseous concentrations and these data feed a neural network, which helps regulating the ventilation of the hog lots. The authors of [
21] have also verified the coverage radius of their system, in both indoor and outdoor conditions, finding a low packet loss rate even at 4.5 km distance in outdoor scenarios and on five story buildings in indoor scenarios.
There are also a number of commercial solutions proposed for the deployment of livestock monitoring networks. For these solutions, the information is limited to what reported in data sheets and web sites of the related companies. Cattle Watch [
30] uses an undisclosed type of LPWAN for cattle tracking and virtual geo-fencing in unpopulated areas, whereas the gateway relays the data to the data collection system by means of a cellular, satellite, or NB-IoT network. Cattle Traxx operates similarly, although their technological platform is LoRa-based [
19]. Sodaq [
31], instead, proposes a smart cow collar that adopts a full LoRaWAN implementation for cattle tracking and activity detection. Their system is powered by a small solar cell, thus allowing extended deployment periods before servicing; however, they do not offer a proprietary cloud solution but they rely on external service providers. Allflex SenseHub Beef [
32] is another solution for short range (<500 m) cattle monitoring, which is based on IEEE 802.15.4 communication protocols: With this system, however, only a limited amount of information is transmitted from the nodes, to improve battery lifetime. Finally, Moocall [
33] is an animal tracking and estrus detection system which uses GSM networks for information relay from sensors to data centers.
In [
26] a study of LoRa propagation in indoor scenarios has been conducted, for the purpose of human health monitoring. The study in [
26] has found that the packet loss rate can be minimized within a coverage radius of about 200 m, even if the experiment involved only a single node and base station.
Tree plantation monitoring with LoRa is explored in [
27]. In that study, the gateway antenna is located at different heights, and the nodes transmit (with limited power) information such as temperature, humidity, soil moisture, and so on. The experiment covered limited distances (less than 500 m) and was mainly devoted to explore the propagation conditions due to the presence of trees and their foliage. The results in [
27] show that there is some dependence on the antenna elevation when distances are large. LPWANs for tree farming are also used in [
12], where the authors have shown that the height of the receiving antenna has a large impact on the packet loss rate, with the received signal strength indicator (RSSI) depending more on the distance rather than on the adopted spreading factor.
Smart city monitoring is the subject of [
2]. In this work, environmental quality parameters (
concentration, luminance, temperature, etc.) in the city of Bologna are monitored with a LoRa network. The scenario is that of a densely populated urban area, with coverage radius of 1–2 km. The paper [
2] focuses on the modeling of the path loss and on the adaptation of this model to a C++ network simulator, with the purpose to predict the performance of the network when the number of installed nodes scales up. The development of a link-level simulator, conceived for the ns-3 network simulator tool, has been investigated in [
28], where it is found that a single LoRa gateway, obeying to the spectrum usage restrictions, is able to manage up to 15,000 EDs in smart cities, with a small packet loss rate.
In [
5], the authors investigate the use of LoRa for tracking trolleys in an industrial scenario. Trolley positioning may take place either indoor or outdoor, at a maximum distance of about 500 m from the gateway. First, [
5] models the propagation scenario and the LoRa communication performance with real devices. Then, [
5] establishes a Python-based simulation framework to evaluate the maximum load that can be sustained by the network under stressing conditions. The simulations in [
5] show that a single gateway could be engaged up to 6000 nodes, still keeping an acceptable performance in terms of packet loss rate. Another evaluation of the feasibility of LoRa transmission in an industrial scenario has been carried out in [
29], where the authors experimented time-slotted channel-hopping to respect the limitations imposed by spectrum access regulations and to improve the typical node latency down to less than one minute, which is deemed to be acceptable for most industrial control applications. The authors of [
4] also proposed the adoption of an enhanced flexible node to supplement gateway functionalities and to act as a range extender. In [
9], maritime communication with boats is established using LoRa, in particular for lightweight boats navigating near the coastal line. The coverage extended up to 4 km far, with a limited amount of consumed power on the EDs, as low as 140 mA at 5 V.
In the above presented LoRaWAN approaches [
2,
4,
5,
12,
21,
23,
24,
25,
26,
27,
28,
29], the adopted LoRaWAN MAC layer does not include a listen-before-talk (LBT) mechanism that tries to prevent as much as possible packet collisions among nodes [
34]. On the contrary, our paper proposes a custom MAC layer that includes LBT-based carrier-sense multiple access with collision avoidance (CSMA/CA), to be incorporated with the physical layer of LoRa. The proposed CA mechanism is based on a random retransmission time that randomizes the access of the nodes to the wireless medium. As a first consequence, the proposed approach allows to reduce the number of collisions with respect to LoRaWAN. As a second consequence, the use of LBT allows to overcome the limits imposed by regulatory bodies on the effective duty cycle of channel occupation [
35]: Therefore, our approach can transmit more often than a regular LoRaWAN network. Due to the above-mentioned features, our approach allows a reduced packet loss rate (with respect to LoRaWAN) for a fixed number of EDs, or, alternatively, our approach allows an increased number of EDs (with respect to LoRaWAN) for a fixed packet loss rate.
4. PHY/MAC Level Simulator
The performance of the proposed LoRa architecture has also been evaluated by means of a physical and MAC layer system simulator. The simulator, written in C++, implements a time-based event queue and adopts a simple physical layer model where waveforms are associated to data packets, as well as a MAC level that operates on byte packets. The evsObject represents the base class of the objects involved in the time-based event simulation; from this base class, several other classes are created with inheritance. Every object is characterized by an handler method, which is invoked whenever an event occurs for that object. There are three main subclasses, which are used to characterize different actors of the simulation system. They are:
evsChannel: This class represents the communication channels, upon which data delivery may take place as a byte packet exchange;
evsDevice: This class represents the communication devices, characterized as a finite state machine with MAC arbitration policies;
evsInterface: This class acts as a connector between the communication devices and the communication channels. For instance, a device may act as bridge between different communication channels by incorporating multiple interfaces.
From the three main subclasses, several objects are then created:
evsInetChannel: This object represents a generic Internet data channel with reliable packet delivery (e.g., TCP/IP);
evsRadioChannel: This object represents a generic radio communication channel characterized by attenuation and packet losses;
evsLoRaEndDevice: This object represents a LoRa ED;
evsLoRaGateway: This object represents a LoRa gateway;
evsDBServer: This object represents the server hosting the database;
evsInetInterface: This object represents the interface towards an Internet communication channel;
evsLoRaRadioInterface: This object represents the interface towards a radio communication channel.
The data transported during the simulation events are represented by the base class evsPacket, which has the two following subclasses:
evsInetPacket: A data packet delivered through the reliable Internet communication channel;
evsLoRaRadioPacket: A data packet unreliably delivered through the radio communication channel with the LoRa PHY.
Finally, the
evsEvent class is used to denote an object event, which will be handled by the proper handler in the destination object: All the events are queued in a time-sorted list. The simulation engine, then, starts to handle the events in the list, from the first to the last. The simulation is organized as graphically described in
Figure 7: Several LoRa EDs communicate with the LoRa GWs by means of the LoRa radio channel model. The GWs, instead, communicate with the database server by means of the reliable Internet channel. The data are exchanged between the blocks under the form of either LoRa radio packets or Internet packets.
4.1. Physical Layer Model
For the simulation of the physical layer, we have adopted a path loss model characterized by a received power [
52]
where
is the transmitted power (in W),
and
are the transmit and receive antenna gains, respectively,
represents additional losses due to connectors, cabling, antenna misalignment, etc., and
L is the path loss. The path loss depends on
d, the distance between the transmitter and the receiver (in m), on
, which is the path loss at distance
m, and on
, the attenuation exponent of the path loss. If we express (
1) in dB, then the logarithmic path loss is given by
so that the received power (in dBm) can be calculated as
In order to find the channel parameters
and
, we have performed a data transmission experiment using the hardware described in
Section 3.2.1 and
Section 3.3.1. The LoRa GW has been installed in the premises of the Engineering Campus of the University of Perugia, at an height of
m with a dipole antenna with gain
dB. The LoRa ED is equipped with a quarter wave whip antenna, which can be considered omnidirectional (
dB) because the antenna orientation is random. Additional losses (due to antenna misalignment, receiver cable connections, and so on) have been considered for an amount of
dB. The LoRa ED has been configured to transmit at a power
20 dBm on the carrier frequency
MHz, with a spreading factor
, a bandwidth
kHz, and a code rate
. The ED has been carried to a maximum operating distance of 2 km at walking speed, traversing various types of transmission environments, such as urban, suburban, and hilly, both in LOS and NLOS conditions. The ED transmitted its GNSS coordinates every 5 s, and the RSSI at the GW was recorded for every received data packet.
Figure 8 plots the measured path loss
L as a function of the distance
d (in logarithmic scale), as obtained from (
2) and (
3). After least squares (LS) fitting of the path loss as a function of the logarithmic distance, we have found the average attenuation exponent to be
and the reference path loss to be
dB.
From
Figure 8 it appears that some shadowing applies to the total path loss, since the measures are not concentrated along the LS fit line. A better model that also takes into account shadowing [
52] can be obtained as
where
is a Gaussian random variable with zero mean and standard deviation
that models log-normal shadowing: From our measurements, using (
2), the shadowing has a standard deviation
dB.
Figure 8 also shows the curves
due to shadowing. Our experiment shows that the measured path loss is within the range
for 71.7% of the times. As a term of comparison, in [
2] the authors obtain for a dense urban environment a path loss exponent variable between
and
, with a mean square error between the actual loss and the predicted one of
dB and a reference path loss of 31 dB.
4.2. MAC and Transport Layer Model
Differently from the ALOHA access scheme used in LoRaWAN, in our implementation the medium access is performed with a listen-before-talk (LBT) strategy [
53] at the physical layer, so as to avoid unnecessary collisions between radio packets, jointly with an acknowledgment (ACK)-based retransmission policy implemented at the transport layer. CSMA-CA is implemented in an unslotted way: If the channel is sensed to be idle, i.e., no other LoRa ED is transmitting, then the current transmission happens. Otherwise, if the channel is occupied, a random backoff time is calculated before the transmission attempt takes place. This backoff time is randomly chosen within a contention window (CW), beginning right after the transmission decision and with duration
. If the channel is still occupied, then
is doubled, and the transmission attempt delayed again. This procedure is repeated several times, each time with a doubled
, up to a maximum value of
transmission attempts. When the maximum number of attempts is reached and the transmission has not been finalized, the radio interface gives up sending the data packet.
At the transport layer, a further acknowledgment mechanism is also implemented. If enabled, the transmitter considers a successful packet delivery only if an ACK is received: up to retransmission attempts are performed in this layer. This entails an effective number of possible retransmissions for a single packet.
5. Simulation Results
The deployment of a full scale LoRa network takes some time, and the refinement of the transmission parameters to improve the efficiency of the whole network can be cumbersome if done on the actual devices. Thus, our purpose is to determine, by means of simulations, how parameters such as the transmission period, the number of EDs, the use of CSMA/CA and LBT, and the acknowledgments impact on the packet delivery rate and on packet losses. Channel occupation and transmission overhead, as well, may be investigated in depth thanks to the simulation environment. Due to the great number of parameters that can be explored in a simulation, we have chosen to restrict the number of possible scenarios by keeping some of them unchanged in every simulation.
Table 2 lists the parameters that are kept fixed in all simulations, whereas
Table 3 presents the parameters that have been varied in each simulated scenario. The coverage area of size
m × 200 m has been populated with the selected number of EDs, whose location is uniformly and randomly chosen within this area at an average height of
m. The GW has been placed at the center of the coverage area, at an height of
m above the average height of the EDs.
In our simulator implementation, we have considered a packet to be correctly received if (i) the received power is above the receiver sensitivity threshold
and if (ii) there are no collisions with other packets transmitted from other devices. The second condition can be detected in the event-based simulation by letting the receiving device enter an “RX” state upon the reception of any packet. Then, a decision event is issued at the end time of the packet, and a positive decision is taken if no other packet has been detected, in the meanwhile. Moreover, the receiver sensitivity
has been inferred from the values given in (Table 10 of [
16], pp. 20–21), which depend on the frequency, bandwidth, and spreading factor selected in the receiver. The CW duration has been chosen as
ms, which is roughly the duration of a typical LoRa radio packet in our selected configuration (
kHz).
5.1. Global Average Success Rate
In first place we analyze the global average success rate, defined as
where
is defined as the success rate on the
i-th ED, given by
In (
6),
is the number of packets correctly received by the
i-th entity, to which they were addressed: if the acknowledgment protocol is enabled, then the success condition requires that the original transmitter also receives the ACK back. The number of failed packets is
, and it denotes the number of packets that have not been successfully received by the entities to which they were addressed, either with or without acknowledgment:
represents the total number of attempted packet transmissions, and
is the total number of retransmissions of packets due to either collisions or missed ACKs.
Figure 9,
Figure 10 and
Figure 11 show the average success rate for different transmission periods
s of all the simulated combinations: We have chosen
kHz,
, and
, while the simulation results obtained with the other parameter values have not been plotted for sake of clarity, after considering that the results are very close to the presented ones.
The triangle-marked lines represent the absence of the acknowledgment mechanism (
), the square-marked lines represent
, while the circle-marked lines represent
. The line style denotes different LBT strategies: solid lines represent
(i.e., the ALOHA strategy [
54]), dashed lines represent
, and dotted lines represents
. Note that when, due to the CSMA/CA protocol, a packet transmission cannot be performed, the transport layer considers the packet unacknowledged and, if there is an acknowledgment mechanism, further retries can be attempted.
We analyze the simulation results by first considering those shown in
Figure 9. These results represent the worst case scenario, for two reasons: in first place, the small simulated area of size
m × 200 m and the same modulation parameters used by every node (
,
MHz and
kHz) constitute a single collision domain, where each node can receive the messages sent by every other node. In second place, each node generates a data packet every
s, resulting in the highest simulated offered traffic.
The solid line with the triangle marker represents the simplest access technique, characterized by the absence of both LBT and acknowledgment mechanisms; in this case, the success rate deteriorates quickly as the number of EDs increases, considering that for the success rate falls below 80%.
By considering also the two other solid lines (), the choice (circle markers) provides the best performance until where, after that, (square markers) becomes the best choice, replaced by (triangle markers) after .
This can be explained by an increased collision probability, when more traffic is present on the channel: the acknowledgment mechanism contributes to an avalanche effect that causes a quick decrease of .
If we focus our attention to the case (triangle markers), we can appreciate the improvement granted by the introduction of the CSMA/CA mechanism: it can be noticed that a success rate is achieved, at least, up to with , up to with , and up to with . Therefore, our LBT-based approach allows an increased number of EDs with respect to LoRaWAN. Alternatively, if we fix the number of EDs, our LBT-based approach achieves a larger success rate (and hence a reduced packet loss rate) with respect to LoRaWAN.
If we consider the cases (square markers) or (circle markers), it is interesting to note that at some point ( for and for ) the performance with improves upon that with .
Overall, the best performance is achieved with and until . After this point, and give the best results.
Figure 10 and
Figure 11 present the results achieved with longer packet transmission periods of
s and
s, respectively. From these figures we may infer the same characteristics outlined in the previous paragraph for the case
s. The main difference lies in the increase of the number of EDs where parameters configuration switch-over occurs.
5.2. Traffic Composition
In this section, we analyze the composition of the PHY and transport layer traffic, distinguishing among successful transmissions, packet retransmissions, and failed transmissions. It is interesting to investigate channel occupation and transmission overhead caused by the adoption of different techniques.
To this purpose, we define
as the average successful packet rate per hour and per node, as
Similarly, we define
and
as
Eventually, we also define
as the sum of the three rates (
7)–(
9), as
Figure 12,
Figure 13 and
Figure 14 show the traffic composition for different transmission periods
s of all the simulated combinations. The parameters are represented on a stack chart, beginning with
at the bottom, followed by
in the middle, and terminated by
on the top: it is important to note that the top value of the curve also represents
. Whit this type of graphical representation, it is possible to visualize the amount of each traffic component and its proportion with respect to the global traffic.
We want to point out that the small number of packets sent each hour by every node (in the order of ten) in our application is motivated by low power consumption constraints. We analyze the simulation results by first considering those shown in
Figure 12, since this represents the worst case scenario.
Figure 12a presents the configuration without LBT and acknowledgment mechanisms: due to
, there is no
traffic component and
decreases quickly as
grows. In
Figure 12b,c we can appreciate the improvement granted by CSMA/CA, which lets
increase without affecting the overall traffic volume.
Figure 12d,g report the impact generated by the acknowledgment mechanism, which provides an improvement at low
despite an increase of traffic volume due to the retransmission events; this traffic increase, without CSMA/CA, creates an avalanche effect that causes a rapid drop of
. This avalanche effect achieves its maximum in
Figure 12g, where, after
, there is a traffic breakdown that indicates the saturation of the channel.
Considering that, based on
, the best performance is achieved with
and
until
, and, after this point,
and
give the best results, it is interesting to analyze the traffic composition in these scenarios. The first region is shown in
Figure 12i: It can be seen that until
the overhead is acceptable, considering the high
granted. The second region is shown in
Figure 12c, where the overhead for
is absent, differently from
Figure 12i, also guaranteeing a better
.
We can conclude that the best configuration (, until , and after that) resulting by the analysis of also presents a good channel occupation, avoiding an undue overhead.
Figure 13 and
Figure 14 present the results achieved with longer packet transmission periods of
s and
s, respectively. From these figures we may infer the same characteristics outlined in the previous paragraph for the case
s. The main difference lies in the increase of the number of EDs where the described behaviors occur.