# Real-Time Extensive Livestock Monitoring Using LPWAN Smart Wearable and Infrastructure
## 2 Materials and Methods
### Logic and Communications
\(\bigcirc\) 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_{\text{NO-MOVE}}\). This threshold is configurable to adjust sensitivity of the device. \(\bullet\) 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 T\({}_{\text{CONFIG}}\). 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 LoRaWAN, 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 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  
Figure 5: Firmware’s flow diagram. with commercial LoRaWAN gateways. Additionally, no network layer is provided so routing is up to the software implementation.