Real-Time Extensive Livestock Monitoring Using LPWAN Smart Wearable and Infrastructure

Featured Application: The wearable and infrastructure presented in this work has proven to be a valuable and ﬂexible tool for real-time extensive livestock tracking and monitoring with regulatory compliance. Main features are online and ofﬂine monitoring and data logging; adaptative dual radio (FSK and LoRaWAN) for best energy/bandwidth/range balance; adaptative movement data streaming modes with vector quantization compression method; and years of battery life. Abstract: Extensive unsupervised livestock farming is a habitual technique in many places around the globe. Animal release can be done for months, in large areas and with different species packing and behaving very differently. Nevertheless, the farmer’s needs are similar: where livestock is (and where has been) and how healthy they are. The geographical areas involved usually have difﬁcult access with harsh orography and lack of communications infrastructure. This paper presents the design of a solution for extensive livestock monitoring in these areas. Our proposal is based in a wearable equipped with inertial sensors, global positioning system and wireless communications; and a Low-Power Wide Area Network infrastructure that can run with and without internet connection. Using adaptive analysis and data compression, we provide real-time monitoring and logging of cattle’s position and activities. Hardware and ﬁrmware design achieve very low energy consumption allowing months of battery life. We have thoroughly tested the devices in different laboratory setups and evaluated the system performance in real scenarios in the mountains and in the forest.


Introduction
Extensive livestock farming is a typical technique in many places around the world. It occurs on 25% of global land surface and supports around 200 million subsistence pastoral households [1]. In Africa, 40% of the land is dedicated to extensive pastoralism [2]. Many habitats important for biodiversity conservation have been created by and are still inherently linked to extensive livestock production, in particular grazing. For instance, extensive grazing is considered vital for maintaining many biodiversity-rich habitats in Europe. It is suggested as optimum management of de-intensified grassland to enhance biodiversity [3]. Extensive grazing was reported to positively influence sward species composition and structure which, in turn, provided favourable conditions for colonizing fauna.
Furthermore, extensive livestock and the related grazing is also critical for maintaining many of Europe's cultural landscapes and sustaining rural communities. Over the centuries, pastoralism, and transhumance (seasonal movement of livestock between grazing areas) created a wide variety of specific cultural landscapes. The largest remaining extensive pastoral systems on permanent wood pastures in Europe are Dehesa in Spain and Montado in Portugal [4]. Grazing and transhumance are of particular importance for the preservation of open landscapes in the European mountains. In addition, societal concern over the  There are several other alternatives to cellular networks for IoT monitoring. These can be mesh networks, where link quality indicators could be used to locate animals without GNSS [8]. This kind of deployment is heavily dependent of the gateway which usually becomes the bottleneck and, depending on the orography, requires a router infrastructure that needs considerable amount of energy [9]. There are times where the link between the wireless sensor network (WSN) and the internet is a Wi-Fi transceiver, which is meant to increase the range in zones without GPRS coverage [10].  Low-Power Wide Area Networks (LPWAN) are also suitable options, bringing together the low-power qualities of WSN and long-range capacities of cellular networks. There are novel modulations such as LoRa that can be used on mesh topologies to extend range, although it is usually used in star topology. Given the benefits such as long range, low-power and cost savings, LoRa is ideal for cattle monitoring [11][12][13].
Another appealing alternative is the use of UAVs, which is an emerging application in the field of precision agriculture [14][15][16]. Specific usage of UAVs for cattle monitoring is described in [17][18][19][20] which relay on image processing techniques for identify animals and account for them. However, that approach have some limitations when we are concerned about tracking specific individuals (a shepherd would be interested in locating his animals only) and does not allow continuous tracking as GNSS solutions do. Combined usage of UAVs and GNSS is also proposed in [21], which consider drones for easing the retrieve of the tracking information acquired by GPS collars worn by the animals. Nevertheless, a number of technical and administrative issues arise that still possess some difficulties for using UAVs in extensive cattle monitoring, such as the cost or the need of specialist operators (it is required mid/high-size UAVs for covering big extensions), which may also require a flying license and special permission in some countries [22].
Besides localization tracking of the animals using GNSS, registering their status and activities can be of interest to shepherds [23]. Activity detection can be performed with different strategies such as radio frequency identification (RFID) to infer cattle drinking behavior and water intake by detecting proximity to specific places [24]. Using temperature [25] and other biosensors [26] can help to detect a fever state and to assert animal well-being. The most common are inertial sensors based on accelerometers and gyroscopes that are able to identify animal activities such as resting, walking, mating or feeding among others [27,28].
Using inertial data to extract activities is a very powerful, cheap, energy-efficient and, consequently, broadly adopted strategy. Nevertheless, inertial sensors cannot be directly used, due to the high throughput required: a 12-bit 3-axis accelerometer sampling at 10 Hz generates more than 1.25 Mb of data every hour. Sending this amount of data through LPWAN is too costly in both economic and energetic terms, sometimes violates regional restrictions (e.g., LoRaWAN) or it is just technically impossible (e.g., Sigfox). Thus, raw data needs to be processed in order to extract the most important features, which also helps saving and sending way less data than generated.
There are two main strategies that can be applied. Custom data processing techniques to specifically detect the required activities performed by animals [29] and humans [30] is a trending research topic. It is also possible to use data compression strategies to reduce the amount of information to be sent and then decompress and process it in the cloud. Usual techniques for accomplishing data compression are Principal Component Analysis (PCA) [31][32][33][34], Sequential Forward Selection (SFS) [35], Random Subset Feature selection (RSFS) [35], Independent Component Analysis (ICA) [34], I-PCA [34], Vector Quantization (VQ) [36], and Frequency Sensitive Competitive Learning (FSCL) [37,38].
In this context, we aim to monitor animals in extensive farming in the north part of Spain (in the Pyrenees area, near the border with France). We have two main objectives: Firstly, we need to track the movement of the animals to evaluate their impact on the plant biodiversity. This could be done just by using a device fitted with a GNSS receiver that would collect the positions during the time the animals are in the mountain and download them when they are returned to the barns. Secondly, we intend to virtually reduce the distance between the animals and the shepherds. For this reason, it is necessary to relay the positions and statuses of the animals in real time. As the selected area has no guaranteed coverage from any TSP, it has been necessary to focus on a different approach.
Our proposal is a wearable equipped with inertial sensors, GNSS and wireless communications. Including adaptive analysis and VQ compression model in the wearable achieving high compression ratios with good peak signal-to-noise ratios (PSNR) [39] allows for real-time monitoring and logging of cattle's position and activities. We have chosen a transceiver with both FSK and LoRa capabilities. As it has been mentioned before, there is no coverage by TSPs and links based on these modulations have proven its utility in open farming scenarios. We focused our electronic design on achieving very low energy consumption, allowing for several months of battery runtime. We have evaluated both the wearable and the system performance for tracking cows in real scenarios, such as mountains and forest.
The rest of the paper is structured as follows: first, the characteristics of the wearable, its capabilities and the operation modes are defined; then, laboratory experimentation and field tests are presented; and lastly, system characteristics and work results are discussed.

Wearable Design
The wearable integrates several sensors for measuring temperature, acceleration, and magnetic fields. It also features a GNSS positioning module and a LoRa transceiver able to transmit using FSK and LoRa modulations for communication purposes. In the processing side there is a 64 Mbit NOR flash for storing tracking data, a 16-bit MCU with low-power features and a power management circuitry that allows being powered with any battery chemistry and recharging it from different power sources like solar panels, induction, thermoelectric and piezoelectric ( Figure 3 [40]).
The wearable integrates several sensors for measuring temperature, acceleration, and magnetic fields. It also features a GNSS positioning module and a LoRa transceiver able to transmit using FSK and LoRa modulations for communication purposes. In the processing side there is a 64 Mbit NOR flash for storing tracking data, a 16-bit MCU with lowpower features and a power management circuitry that allows being powered with any battery chemistry and recharging it from different power sources like solar panels, induction, thermoelectric and piezoelectric ( Figure 3 [40]). The design objectives considered several perspectives, mainly that of the shepherd and that of the animal, as two types of users with different needs. Thus, the design specifications were aimed at ensuring high resistance to shock and water; compatibility with different existing strap attachment methods; ease of attachment and removal; and acceptance of the device by the host. We designed, tested and redesigned various 3D enclosures to verify different formalizations, finishing angles, and manufacturing materials. Finally, we selected a clam design with an o-ring that stays in place with four screws. The enclosure has two slots with different sizes allowing different-sized animals to comfortably wear them (e.g., sheep and cows). We have successfully performed waterproof IP68 testing. Final design can be seen in Figure 4.

Logic and Communications
We consider several modes each with different configuration parameters: • Beacon: GNSS is sampled at TGNSS and once position is acquired, it is saved in flash memory, sent via LoRaWAN and then the transceiver waits for a configuration The design objectives considered several perspectives, mainly that of the shepherd and that of the animal, as two types of users with different needs. Thus, the design specifications were aimed at ensuring high resistance to shock and water; compatibility with different existing strap attachment methods; ease of attachment and removal; and acceptance of the device by the host. We designed, tested and redesigned various 3D enclosures to verify different formalizations, finishing angles, and manufacturing materials. Finally, we selected a clam design with an o-ring that stays in place with four screws. The enclosure has two slots with different sizes allowing different-sized animals to comfortably wear them (e.g., sheep and cows). We have successfully performed waterproof IP68 testing. Final design can be seen in Figure 4.
The wearable integrates several sensors for measuring temperature, acceleration, and magnetic fields. It also features a GNSS positioning module and a LoRa transceiver able to transmit using FSK and LoRa modulations for communication purposes. In the processing side there is a 64 Mbit NOR flash for storing tracking data, a 16-bit MCU with lowpower features and a power management circuitry that allows being powered with any battery chemistry and recharging it from different power sources like solar panels, induction, thermoelectric and piezoelectric ( Figure 3 [40]). The design objectives considered several perspectives, mainly that of the shepherd and that of the animal, as two types of users with different needs. Thus, the design specifications were aimed at ensuring high resistance to shock and water; compatibility with different existing strap attachment methods; ease of attachment and removal; and acceptance of the device by the host. We designed, tested and redesigned various 3D enclosures to verify different formalizations, finishing angles, and manufacturing materials. Finally, we selected a clam design with an o-ring that stays in place with four screws. The enclosure has two slots with different sizes allowing different-sized animals to comfortably wear them (e.g., sheep and cows). We have successfully performed waterproof IP68 testing. Final design can be seen in Figure 4.

Logic and Communications
We consider several modes each with different configuration parameters: • Beacon: GNSS is sampled at TGNSS and once position is acquired, it is saved in flash memory, sent via LoRaWAN and then the transceiver waits for a configuration

Logic and Communications
We consider several modes each with different configuration parameters: • Beacon: GNSS is sampled at T GNSS and once position is acquired, it is saved in flash memory, sent via LoRaWAN and then the transceiver waits for a configuration message from the server before going to sleep. If no GNSS signal is detected for T TIMEOUT , last known coordinates are sent. It can follow a smart behavior if desired. Then, GNSS is acquired only if movement has been detected between two T GNSS periods. Movement condition is asserted by the inertial measurement unit (IMU) itself, as it activates an interrupt when an A TRHESOHLD is exceeded. If no smart behavior is set, the device sends GNSS regardless of the movement condition.
• Movement: on top of the beacon smart mode, the wearable streams IMU data at T SENSOR period. As IMU raw data stream would lead to a duty cycle policy violation, we have implemented four different behaviors to prevent exceeding it: Continuous: The easiest way to get maximum bitrate is to use FSK modulation to achieve 50 Kbps. Considering that the accelerometer has 14 bit precision measurements, at EU868 (869.525 MHz) frequency, the one with the best duty cycle (10%), we can stream at: Unfortunately, this is not LoRaWAN compliant as duty cycle and bitrate are above limits. Thus, assuming duty cycle policies from EU868 region (1%), usual DR5 LoRaWAN modulation, according to Equation (2), we can stream around one sample per second.
If we just send one piece of axis data, the F SAMPLE can reach 3.4 Hz, which could lead to sending more meaningful data.
Coded: this mode behaves similarly to the previous, but it includes an additional step where the data is compressed prior to be sent [30]. VQ compression defines a NxM look-up table (codebook), being N the number of centroids, i.e., the number of different compressed samples that can be chosen for being transmitted, and M the size of the signal that each centroid represents. The compression algorithm accumulates a window of M samples of the signal and picks the centroid that better fits the original signal (minimizing mean squared error). Then, just the index of the centroid is transmitted, and the signal can be reconstructed at the reception by accessing the codebook with the index. The number of centroids N and the size of the window M allows establishing in advance the compression rate to be achieved (and thus increasing effective F SAMPLE ): The codebook has to be generated previously with a machine learning algorithm that is trained with samples of the data to identify the centroids that will lead to better PSNR figures with the desired compression rate, Our major limitation is the memory available in the device. Using this mode, we can go up to 20 Hz sampling at DR5 over LoRaWAN protocol with good performance. Burst: this mode detects movement and then accumulates several seconds of data. Then, in order to comply with LoRaWAN regulation, we split the packet between the available channels using a scheduler that monitors channel usage and prevents messages to be sent when the duty cycle is about to be exceeded. When this happens, new data is discarded until we are ready to send again. Using this mode, we can send 3-s bursts at 10 Hz sampling at DR5 over LoRaWAN protocol. Smart: The smart strategy is like burst mode but before sending data, it analyzes it to check if no movement is detected; in that case, movement data is discarded, and not sent. This condition is determined when the maximum peak to peak value of the last five seconds of data is below a threshold A NO-MOVE . This threshold is configurable to adjust sensitivity of the device.
• Config: this mode sends LoRaWAN beacons every 10 s, allowing downlink messages that configure the wearable. Config mode is automatically entered after a hard reset  To customize the settings for this device, we define a configuration message via Lo-RaWAN, although it is also possible to do so via USB. According to LoRaWAN specification, as a class A device, each time an uplink message is sent, there are two receiving windows when the device can receive downlink messages. This is the reason why in config mode the devices send beacon messages each 10 s during 1 min. value of the last five seconds of data is below a threshold ANO-MOVE. This threshold is configurable to adjust sensitivity of the device.
• Config: this mode sends LoRaWAN beacons every 10 s, allowing downlink messages that configure the wearable. Config mode is automatically entered after a hard reset and lasts TCONFIG. In this mode we can retrieve the GNSS samples stored in flash memory and send them through FSK packets. • Standby: this is the lowest energy consumption mode where the wearable just sleeps. The only way to exit this state is via hard reset. Figure 5 illustrates firmware's flow diagram integrating all modes.
To customize the settings for this device, we define a configuration message via Lo-RaWAN, although it is also possible to do so via USB. According to LoRaWAN specification, as a class A device, each time an uplink message is sent, there are two receiving windows when the device can receive downlink messages. This is the reason why in config mode the devices send beacon messages each 10 s during 1 min. Thus, there is one downlink message used for wearable configuration and two possible payloads to upload: one with GNSS data and the other is the IMU data arrays. Both GNSS data and configuration messages use LoRaWAN infrastructure because they are short messages that are not sent very often and occur at deterministic times. This allows us to meet fair use policies [41] needed to use available LoRaWAN infrastructure in the field, being the best-effort approach, as there are many available gateways that can route the packets to the cloud. Besides features such as security, encryption, retry counter to monitor for unreachable nodes, LoRaWAN allows us to send configuration packets whenever a device becomes available and the network layer allows for acknowledged packets.
Meanwhile, IMU data is heavy, occurs non-deterministically and needs to be time stamped and managed as it occurs. We have considered using two different modulations as we have two use cases: burst and continuous transmission. The first one is used when we might be interested in sporadic data sampled and low frequencies (less than 5 Hz), and it is possible to get benefit from the extra range LoRa provides on noisy environments. This kind of behaviour is acceptable for the deployment in open field areas where there are animals free to move long distances. Firmware needs to check whether the payloads Thus, there is one downlink message used for wearable configuration and two possible payloads to upload: one with GNSS data and the other is the IMU data arrays. Both GNSS data and configuration messages use LoRaWAN infrastructure because they are short messages that are not sent very often and occur at deterministic times. This allows us to meet fair use policies [41] needed to use available LoRaWAN infrastructure in the field, being the best-effort approach, as there are many available gateways that can route the packets to the cloud. Besides features such as security, encryption, retry counter to monitor for unreachable nodes, LoRaWAN allows us to send configuration packets whenever a device becomes available and the network layer allows for acknowledged packets.
Meanwhile, IMU data is heavy, occurs non-deterministically and needs to be time stamped and managed as it occurs. We have considered using two different modulations as we have two use cases: burst and continuous transmission. The first one is used when we might be interested in sporadic data sampled and low frequencies (less than 5 Hz), and it is possible to get benefit from the extra range LoRa provides on noisy environments. This kind of behaviour is acceptable for the deployment in open field areas where there are animals free to move long distances. Firmware needs to check whether the payloads meet the regulation duty cycle; in case we generate more data than the number of bytes we can send, the device will send data until it reaches the maximum airtime allowed and then it will disable the transceiver until it could send data again.
In case that continuous animal monitoring is needed, the fastest bitrate is available through FSK modulation. The only downsides are the short range and the compatibility with commercial LoRaWAN gateways. Additionally, no network layer is provided so routing is up to the software implementation.

Infrastructure and Backend
Wearable devices should work regardless of the infrastructure available and use its energy wisely in any condition. We consider two different scenarios: a completely online infrastructure when both beacon and streaming messages can be received by stationary IP-connected gateways and a portable offline infrastructure when there are no stationary gateways in range and just a shepherd with a gateway that can receive beacons. The system infrastructure and communications flow are shown in Figure 6. meet the regulation duty cycle; in case we generate more data than the number of bytes we can send, the device will send data until it reaches the maximum airtime allowed and then it will disable the transceiver until it could send data again. In case that continuous animal monitoring is needed, the fastest bitrate is available through FSK modulation. The only downsides are the short range and the compatibility with commercial LoRaWAN gateways. Additionally, no network layer is provided so routing is up to the software implementation.

Infrastructure and Backend
Wearable devices should work regardless of the infrastructure available and use its energy wisely in any condition. We consider two different scenarios: a completely online infrastructure when both beacon and streaming messages can be received by stationary IP-connected gateways and a portable offline infrastructure when there are no stationary gateways in range and just a shepherd with a gateway that can receive beacons. The system infrastructure and communications flow are shown in Figure 6. In the first case scenario, we use a commercial gateway that connects to a TSP and send messages to a LoRaWAN Server. Then, we use MQTT integrations to deliver the data to a self-hosted database, and we provide a user dashboard where data can be visualized. It is the most straightforward way to deploy a LoRaWAN network. We use an additional LoRa gateway to route the FSK traffic that cannot be decoded by commercial gateways directly to our database.
For the second scenario, we developed a gateway using an embedded system (Raspberry Pi) with headless Linux, where we install a custom LoRaWAN server that allows for offline logging and storage of payloads. GNSS payloads are decoded and sent to a web application that runs an offline maps viewer. It consists of a Leaflet map with OSM tiles and Flask server. Users can check the last reports received on interactive browser window in their mobile or tablet devices. A WiFi AP is deployed by the gateway to provide TCP/IP connection with the user mobile device.
Both gateways use an 8-channel concentrator card that demodulates all channels at the same time and provides the encrypted payload to the host system. LoRaWAN payload is end-to-end encrypted with AES cryptographic algorithms [42], based on the AppKey In the first case scenario, we use a commercial gateway that connects to a TSP and send messages to a LoRaWAN Server. Then, we use MQTT integrations to deliver the data to a self-hosted database, and we provide a user dashboard where data can be visualized. It is the most straightforward way to deploy a LoRaWAN network. We use an additional LoRa gateway to route the FSK traffic that cannot be decoded by commercial gateways directly to our database.
For the second scenario, we developed a gateway using an embedded system (Raspberry Pi) with headless Linux, where we install a custom LoRaWAN server that allows for offline logging and storage of payloads. GNSS payloads are decoded and sent to a web application that runs an offline maps viewer. It consists of a Leaflet map with OSM tiles and Flask server. Users can check the last reports received on interactive browser window in their mobile or tablet devices. A WiFi AP is deployed by the gateway to provide TCP/IP connection with the user mobile device.
Both gateways use an 8-channel concentrator card that demodulates all channels at the same time and provides the encrypted payload to the host system. LoRaWAN payload is end-to-end encrypted with AES cryptographic algorithms [42], based on the AppKey parameter, known to node and server. In the online scenario the payload is sent to the server to decode it, but in the offline scenario the host system must use the key to decrypt the payload on the fly. The gateway also run a full featured LoRaWAN server for management of devices, database integration and input/output pipelines.

Results
We chose to split test into two different stages. The first one will include all test to characterize the electronics, such as power consumption, RF performance and digital modulation. After verifying that all hypotheses are correct, we take the sensors to the fields so we can perform real world measurements.

Energy and Timing Analysis
The idea behind the programming done in this device is to fine tune parameters to achieve the better range for each use case while maintaining the lowest power figure.
Previously we stated that we were using both LoRa and FSK modulations. Additionally, LoRa packets are coded into LoRaWAN frames, that allows an easy deployment in most cases. In these tests we will verify the compromise between speed and power consumption in two different data rates (DR1 and DR5) and FSK modulation. Later, we will check what influences does it have in range if any. Laboratory test setup comprise several sensor nodes all programmed to do the following SmartIMU tasks: -First (Figure 7), the sensor samples data from IMU at 12.5 Hz when an event is detected, until desired payload length is achieved. Data are sent through LoRaWAN at DR5, the fastest available at any channel. Then, GNSS receiver is turned on until fix is achieved, and it is sent through LoRaWAN at DR1, the second slowest. We chose DR1 for location data because it let us send data each minute if IMU streaming is turned off, to comply with the duty cycle shows the current while doing a basic SmartIMU task. -Second (Figure 8), we stream accelerometer data at the highest possible resolution with FSK modulation. This mode is used to define activation thresholds and deciding on the filter constants for the embedded IMU unit registers.   Our communication model consist of the modes previously explained and which performance is summarized in Table 1. We can observe that each mode is matched to the best modulation for the use case. The best link budget is allowed in GNSS reports, which requires the best sensitivity. In motion reports we value speed over reception, so we chose a faster data rate. For monitoring purposes when we are close to the animal, we can use FSK for the fastest available data rate.  The device must be usable on animals that usually spend a whole year grazing on the field. According to the previous power consumption requirements we calculated the battery life for each mode as shown in Table 2.   The device must be usable on animals that usually spend a whole year grazing on the field. According to the previous power consumption requirements we calculated the battery life for each mode as shown in Table 2.  1 We assume the animals will not move 6 h per day and a GNSS fix time of 8 s. 2 Li-SOCl 2 primary battery with 8 A·h. Total battery energy 103.7 kJ. 3 3 × AA Alkaline battery with 2.8 A·h. Total battery energy 32.4 kJ. 4 Li-Ion rechargeable battery having 3.6 A·h. Total battery energy 47.9 kJ. 5 We assume a duty cycle of 10 s of movement per minute.

Data Reconstruction Analysis
In order to generate the codebook, VQ compression requires data to train the algorithm. As we have not yet collected enough motion data from the wearable in its intended operation scenario, we have accomplished the data reconstruction analysis with motion data from the Heterogeneity Activity Recognition Dataset [43], which provides a rich collection of inertial sensor data recorded in smartphones and smartwatches in different activities. Detailed analysis can be found in [39]. For example, considering sampling frequencies of 10 and 20 Hz, window sizes of 1, 5 and 10 s, we can achieve different compression ratios and codebook sizes as shown in Table 3. Shorter number of centroids with larger window sizes led to higher compression ratios which turns into lower required data rates, but they will also reduce PSNR as signal loss is greater. PSNR is computed as: where MAX is the maximum value for the signal and MSE is the maximum squared error. For example, we can see the efect of varing the number of centroids of the codebook in a sample dataset of 1,500,000 training samples and 600,000 test samples at a sampling frequency of 100 Hz and window size of 1 s in Figure 9. Increasing the number of centroids for a given window size improves PSNR figures, as the reconstructed signal is closer to the original signal, although using too many centroids will produce overfitting and may lead to badly generalizable codebooks.

Field Tests
For the field test, we deployed two LoRaWAN gateways in Laspuña, north of Spain in the Pyrenees area. They feature the same receiver, but they were fitted with different antennas to prove that gain was not the most important factor with moving targets. The antennas have 4 and 6 dBi gain. Five sensor nodes were set with a movement burst streaming config, reporting position each minute and sampling IMU data at 12.5 Hz. With several devices, we could sample more data and spot any outliers. Sensors were fitted on a 1.8 m person's back using straps as in a cow's neck. The route chosen was a typical cattle path and a nearby ravine where cows usually get lost in.

Communications Performance
In Figure 10, we have a close-up vision of how the position reports were received and the strength of the signal. In most cases the reports were under the 120 dBm mark, except for some good line of sight reports. The gateways were located on the south side of the mountains, 12 km from the furthest point.

Field Tests
For the field test, we deployed two LoRaWAN gateways in Laspuña, north of Spain in the Pyrenees area. They feature the same receiver, but they were fitted with different antennas to prove that gain was not the most important factor with moving targets. The antennas have 4 and 6 dBi gain. Five sensor nodes were set with a movement burst streaming config, reporting position each minute and sampling IMU data at 12.5 Hz. With several devices, we could sample more data and spot any outliers. Sensors were fitted on a 1.8 m person's back using straps as in a cow's neck. The route chosen was a typical cattle path and a nearby ravine where cows usually get lost in.

Communications Performance
In Figure 10, we have a close-up vision of how the position reports were received and the strength of the signal. In most cases the reports were under the 120 dBm mark, except for some good line of sight reports. The gateways were located on the south side of the mountains, 12 km from the furthest point.
The distances achieved ranged from 10 to 12 km to both gateways with almost no difference in signal strength between them. The elevation profile (Figure 11) depicts the position of the gateway and the range of altitude covered with the tracker. It also shows some obstacle at 8.6 and 3 km. Depending on the distance and height the contribution to path loss is variable. RSSI in the tracking area goes from −115 to −135 dBm. Appl. Sci. 2021, 11, x FOR PEER REVIEW 13 of 19 Figure 10. Data reports received. Distance from gateway to farthest point is 12 km.
The distances achieved ranged from 10 to 12 km to both gateways with almost no difference in signal strength between them. The elevation profile (Figure 11) depicts the position of the gateway and the range of altitude covered with the tracker. It also shows some obstacle at 8.6 and 3 km. Depending on the distance and height the contribution to path loss is variable. RSSI in the tracking area goes from −115 to −135 dBm.

Movement Data Analysis
The streaming data from the person walking through the path is shown in Figure 12. Samples are stitched together to make picturing the activity easier. Same activity is repeated over the span of several hours. In Figure 13, we can see the result of some burstreports that were interpolated to avoid idle periods between bursts but clearly reflects that the same activity is taking place continuously. The distances achieved ranged from 10 to 12 km to both gateways with almost no difference in signal strength between them. The elevation profile ( Figure 11) depicts the position of the gateway and the range of altitude covered with the tracker. It also shows some obstacle at 8.6 and 3 km. Depending on the distance and height the contribution to path loss is variable. RSSI in the tracking area goes from −115 to −135 dBm.

Movement Data Analysis
The streaming data from the person walking through the path is shown in Figure 12. Samples are stitched together to make picturing the activity easier. Same activity is repeated over the span of several hours. In Figure 13, we can see the result of some burstreports that were interpolated to avoid idle periods between bursts but clearly reflects that the same activity is taking place continuously.

Movement Data Analysis
The streaming data from the person walking through the path is shown in Figure 12. Samples are stitched together to make picturing the activity easier. Same activity is repeated over the span of several hours. In Figure 13, we can see the result of some burst-reports that were interpolated to avoid idle periods between bursts but clearly reflects that the same activity is taking place continuously.

Discussion
The wearable and infrastructure introduced in this work has proved to be a valuable and flexible tool, as it allows for both field deployment and laboratory research.
The main purpose in these field application scenarios is providing animals GNSS localization for both audit tracking and finding the cattle. Field tests shows communication links ranging up to 12 km with direct line of sight, allowing coverage of large areas with minimal infrastructure. Theoretically, a single receiver would serve an area of 452 km². This allows for LoRaWAN setups that are both cheaper and more convenient than deploying cellular repeaters for low data rate needs such as position reports. Even if the requirements include motion reports with accelerometer data, the system proves reliable and still achieves long range, at the expense of extra battery life and bandwidth usage. This motion data could be used for health monitoring and developing future activity recognition algorithms.
If any of the animals become lost outside the infrastructure's line of sight, the system may operate without infrastructure, with just an offline gateway and a mobile device. The

Discussion
The wearable and infrastructure introduced in this work has proved to be a valuable and flexible tool, as it allows for both field deployment and laboratory research.
The main purpose in these field application scenarios is providing animals GNSS localization for both audit tracking and finding the cattle. Field tests shows communication links ranging up to 12 km with direct line of sight, allowing coverage of large areas with minimal infrastructure. Theoretically, a single receiver would serve an area of 452 km². This allows for LoRaWAN setups that are both cheaper and more convenient than deploying cellular repeaters for low data rate needs such as position reports. Even if the requirements include motion reports with accelerometer data, the system proves reliable and still achieves long range, at the expense of extra battery life and bandwidth usage. This motion data could be used for health monitoring and developing future activity recognition algorithms.
If any of the animals become lost outside the infrastructure's line of sight, the system may operate without infrastructure, with just an offline gateway and a mobile device. The

Discussion
The wearable and infrastructure introduced in this work has proved to be a valuable and flexible tool, as it allows for both field deployment and laboratory research.
The main purpose in these field application scenarios is providing animals GNSS localization for both audit tracking and finding the cattle. Field tests shows communication links ranging up to 12 km with direct line of sight, allowing coverage of large areas with minimal infrastructure. Theoretically, a single receiver would serve an area of 452 km 2 . This allows for LoRaWAN setups that are both cheaper and more convenient than deploying cellular repeaters for low data rate needs such as position reports. Even if the requirements include motion reports with accelerometer data, the system proves reliable and still achieves long range, at the expense of extra battery life and bandwidth usage. This motion data could be used for health monitoring and developing future activity recognition algorithms.
If any of the animals become lost outside the infrastructure's line of sight, the system may operate without infrastructure, with just an offline gateway and a mobile device. The system is capable of indicating the location of the animals in a self-hosted application that may operate in environments without internet access. This makes tracking the animal possible where a fixed infrastructure or the nonexistent cellular coverage would fail to locate it.
In addition, our system allows registering periodic bursts of raw movement data without affecting normal operation nor violating LoRaWAN regulatory constraints. Registering complete motion data is possible in controlled environments (such as indoor barns) where we use a faster data rate along with FSK modulation, so duty cycles are not compromised. It should be noted that full motion data streaming is applicable only for monitoring a reduced number of devices, as the band may be saturated despite complying with the use restrictions. Animals belonging to the same group are expected to behave similarly so this should not pose a problem.
Using the proposed VQ compression model, motion data can be sampled at high frequency and we can adjust compressor parameters to fit the required data rate within the limits imposed by LoRaWAN. Larger window sizes with shorter number of centroids will lead to lowest data rates, but PSNR figures will be affected also, thus configurations that use most of the available data rate and maximize the number of centroids without overfitting should be preferred. Considering size of compression model, its implementation is highly dependent on both static and dynamic memory available in the embedded device. We can use internal memory for small codebooks (e.g., three axes at 10 Hz with 1 s window needs 15.36 KB for a 256 centroid codebook) or use the external FLASH memory to store the larger codebooks.
All these features are fulfilled with low energy consumption figures that ensure operation of the wearable throughout the whole season (even years if no raw movement data is required) when animals are outdoors. Even in the most demanding scenario with GNSS sampling and raw data sending over LoRaWAN (4 months) or FSK (8 months) the system serves as valuable cattle monitoring infrastructure. Together with regulatory compliance, this enables utilization of the system in real applications.
We can extract conclusions at different levels comparing our system with other approaches in the literature. - Communications: Use of LoRa allows long range point to point communications with reduced energy consumption and medium data bandwidth (up to 5.5 kbps). We have achieved a maximum of 12 km in mountain environment with enough link budget. Systems based in communications provided by TSPs (GPRS [6], satellite [44], NBioT [45], SigFox [7]) do not require deployment of any additional communication infrastructure, but they will not work where there is no coverage. Furthermore, cellular links use much more energy for communication than LoRa; 2 W [46] against 25 mW. This has a remarkable impact in battery life but also in reduced radiofrequency radiation to the animals, which means less heating due to SAR (specific absorption rate). Such power is completely safe as shown in [47][48][49][50][51]. Other LPWAN technologies such as SigFox use similar amount of energy but the duty policies allow just 144 messages per day [52] and it is not enough to send movement data. Satellite communications main drawback is the associated cost, which is quite high if we are sending movement data. Finally, systems based in medium-range sensor networks such as Zigbee [8][9][10] require higher density of routers making the required infrastructure much larger. -Infrastructure: Our system can work in three different scenarios: using a LoRaWAN telecom infrastructure (e.g., Everynet [53]), deploying ad hoc LoRaWAN gateways connected to Internet or, as we also propose to find cattle, carrying (on a person or a drone [54]) a mobile offline gateway. We have not found any other approach that gives such flexibility. -Data: Derived from the challenging communications and long battery life requirements, most systems having wide coverage only send so much data; mainly GPS. Fewer systems have onboard non-volatile memory that provides larger data recording. Those systems using wireless sensor networks and even WiFi [55] are not limited in terms of data throughput and can monitor large number of parameters (but they require a dense infrastructure). Our system does not require such bulky infrastructure, but still thanks to choosing the right coding technique, it can send movement data in real time.

Conclusions
Information and Communication Technologies (ICT-based) solutions are improving the productivity of all industrial sectors, even agriculture and livestock. They should also improve the well-living of the people across the World. Nevertheless, in many cases, the success of one of these solutions is linked to the availability of communication infrastructures that could provide support for the "C" of ICT. In developed countries, where we could assume that communication infrastructures should have a high degree of deployment, agriculture and livestock are usually related with rural areas where these infrastructures begin to loss their capacities. Unfortunately, in the rest of the World, this lack of communications capacities begins even in the big cities.
If we put the focus on extensive livestock, we can find that, in Europe, it is usually restricted to remote areas, where the communications infrastructures are not capable to provide any kind of services for deploying ICT solutions. In other countries, we can find extensive livestock also near the big cities, but this does not guarantee the availability of communications services (or they are but a high price). This paper has presented a solution for dealing with this problem of lack of stablished communication infrastructures for controlling the movements of animals from extensive livestock farms. It is based on the development of an animal wearable that is equipped with inertial sensors, GNSS and wireless communications. It also includes enough computation capacity for making adaptive analysis and VQ compression that provides high compression ratios with good peak signal-to-noise ratios, and allows for real-time monitoring and logging of cattle's position and activities. This wearable has been evaluated in real scenarios, such as mountains and forest, in the context of a project that aims to monitor animals in extensive farming in the north part of Spain (in the Pyrenees area, near the border with France). This project includes the necessity to track the movement of the animals to evaluate their impact on the plant biodiversity, as well as the intention to virtually reduce the distance between the animals and the shepherds. Funding: This work has been partially supported by the Aragon regional Government thought the program for R&D groups (T27_20R and T59_20R) and by the Rural Development Program in conjunction with FEADER from EC (GCP2019004100). The work of Alvaro Marco and Teresa Blanco has been partially supported by the Spanish Government, program Torres Quevedo (PTQ2017-09481 and PTQ2018-010045, respectively).

Institutional Review Board Statement:
Ethical review and approval were waived for this study, due to it was accomplished within the context of the works related to the Rural Development Program, where shepherds agreed with these trials. Only a limited number of animals were involved in the study, and they were not exposed to harmful levels of radiation, as discussed in the text.