# Real-Time Extensive Livestock Monitoring Using LPWAN Smart Wearable and Infrastructure
## 2 Materials and Methods
### Logic and Communications  
We consider several modes each with different configuration parameters:  
* Beacon: GNSS is sampled at T\({}_{\text{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\({}_{\text{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\({}_{\text{GNSS}}\) periods. Movement condition is asserted by the inertial measurement unit (IMU) itself, as it activates an interrupt when an AT\({}_{\text{THRESHID}}\) is exceeded. If no smart behavior is set, the device sends GNSS regardless of the movement condition. Figure 4: 3D and final prototype. Figure 3: Hardware block diagram. * Movement: on top of the beacon smart mode, the wearable streams IMU data at T\({}_{\text{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: \(\bigcirc\) 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: \[F_{SAMPLE}=\frac{ACC_{PRECISION}\times N_{AXIS}}{DATARATE\times DUTYCYCLE}\times P _{RATIO}=\frac{14\text{ b}\times 3}{50\text{ kb/s}\times 10\%}\times\frac{64\text{ B}+8\text{ B}}{64\text{ B}}=105.82\text{ Hz},\] (1) 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. \[F_{SAMPLE}=\frac{14\text{ b}\times 3}{5.47\text{ kb/s }\times 1\%}\times\frac{358\text{ B}}{24\text{ B}}=1.14\text{ Hz},\] (2) 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. \(\bigcirc\) 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}\)): \[compression\_rate=\frac{M\times sample\_size}{\log 2(N)/8},\] (3) 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. \(\bigcirc\) 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.