Keywords

1 Introduction

Nowadays, the agriculture industry is facing several challenges, including demographics, food waste, and scarcity of natural resources. According to [5], roughly 800 million people worldwide suffer from hunger, and 650 million will still be undernourished by 2030. The publication reports that by 2050 humanity will have to produce 70% more food. To solve the scarcity problem, many complementary actions must be taken. Among them, traditional farm and agricultural methods must be replaced and supported by new advancements in technology, including sensors, devices, robots, and information technology.

Internet of things (IoT), already mature and effective technology, seems to be one of the remedies for low efficiency and productivity in agriculture and livestock. In [8], the following areas of IoT application in agriculture are listed: agricultural field monitoring, greenhouse monitoring, agricultural drones, livestock monitoring, smart irrigation control, agriculture warehouse monitoring, and soil monitoring. The objective of this paper is to present a new IoT-based livestock monitoring system dedicated to the automated measurement of dairy cow health state in a conventional loose-housing cowshed.

2 Related Works

The most common form of cow behavior assessment is a visual observation, but intensive and sustainable detection is limited due to time constraints and lack of human resources [10]. Introducing precision dairy-monitoring (PDM) technology for monitoring dairy cattle allows to avoid disturbing natural behavioral expression [9], to reduce human resources needs, and overall costs [1].

The IoT technology has already been shown to feature potential benefits in dairy cattle farming. In [3] commercially marketed IoT technologies were compared with traditional, visual observation. The tested devices were attached to the animal’s legs and ears. Some of the tested PDM sensors had a high correlation between direct observations of feeding, rumination, and lying behaviours In turn, Wang et al. [19] examined the accuracy of a 3-axial accelerometer attached to the legs of a cow in classifying animal behavior.

Making use of the IoT enables to monitor of udder health, estrus events, feet, and leg health, and metabolic health [7, 16, 17]. The solutions proposed in the literature use PDM devices such as collars, ear tags, and leg bands for behavior monitoring [3, 4].

Detection of cows ready for insemination is still considered to be a significant problem in dairy farming [15]. There are many changes in cow behavior indicating estrus, like standing to be mounted by fellows, restlessness, sniffing the vulva of another cow, flehmen, licking, or resting with the chin on the back of another cow [13, 18]. Estrus is accompanied by alterations in feeding and rumination [12]. Early estrus detection can be supported by an IoT-based monitoring system [14].

The main objective of the proposed cow health monitoring system is to classify dairy cow behavior with particular emphasis on estrus. The monitoring device for in situ data collection is located in a neck collar with a counterweight.

3 Architecture of Cow Health Monitoring System

The dairy cow monitoring system (called the CowMonitor system) is composed of hardware components, the cloud system, and the end-user application (Fig. 1). Hardware components include the monitoring device (called the CowDevice) and the infrastructure devices: the Hub, WiFi access points, and routers. The cloud system is composed of the Server hosting database and application server.

Fig. 1.
figure 1

Architecture of IoT-based cow health monitoring system. Different arrow colors denote different wireless communication technologies: BLE (blue), WiFi/Ethernet (red), GSM/Internet (black). (Color figure online)

3.1 CowDevice

Every animal wears a CowDevice attached to the collar. The device is a dedicated, battery-powered microcontroller device equipped with low-power inertial sensors (accelerometer and magnetometer) and wireless communication. The device is based on nRF 52832 system on chip—an integrated ARM Cortex 4F processor and a Bluetooth Low Energy (BLE) v.5 compatible radio transceiver. The device performs regular accelerometer and magnetometer measurements at the frequency of 20 Hz. The set of measured parameters was chosen experimentally to ensure it will be possible to infer individual animal activity based on the sensor readings. Initially, raw measurements were stored on an SD card. They were downloaded every week, analysed offline, and used to design preliminary algorithms. This enabled to design a proprietary data aggregation algorithms that process raw measurements from sensors in non-overlapping time windows of 10 s. Aggregation enables us to extract only the vital information and lowers the amount of data that needs to be transmitted from the CowDevice down to below 20 bytes every 10 s. This amount is small enough to use BLE communication while the aggregated values still allow classifying animal activity (e.g., rumination, feeding, walking, etc.) and decide estrus.

CowDevices use opportunistic data transmission [2, 6] to ensure efficient, energy preserving, and robust transmission of measurements. In this method, the values are transmitted inside a payload of BLE advertisement messages. Advertisements are short messages broadcasted periodically in connectionless communication mode thus ensuring an average power consumption below 300 \(\upmu \)A.‘ However, because advertisements are broadcasted without acknowledgments from the Hubs, they do not ensure reliable data transmission. It is quite likely that a single advertisement is not correctly received. Therefore, the CowDevice transmits advertisements periodically until new aggregate values are available. Every 10 s, the payload is updated with the new aggregate values, and advertisement transmission is restarted. This method improves the overall reliability of the transmission at the costs of increased energy consumption (compared to single transmission), increased congestion in the communication channel (due to a larger amount of communication), and consequently, a higher probability of collision. Despite the disadvantages, the opportunistic data transmission has proved to be an efficient method for information transmission and was shown to apply to dense networks composed of a large number of BLE devices [11] (Fig. 2).

Fig. 2.
figure 2

(On left) CowDevices (gray) attached to the collar of the animal and (on right) its construction

Aggregated measurements are broadcasted periodically every 250 ms inside the payload of the advertisement messages. Except for the measurements, the advertisements also include additional information regarding device status and packet sequence numbers. Every set of the aggregated measurements is transmitted approximately 40 times (every 250 ms for 10 s), ensuring reliable transmission of all the measurements. The CowDevice runs on the battery that enables its operation for up to 5 years without replacement.

3.2 Hub

The Hub is a dedicated gateway device that receives the BLE packets and forwards them to the server located in the cloud. The Hub (Fig. 3) is build using Raspberry Pi Zero W single-board computer that is equipped with built-in BLE and WiFi connectivity. Every Hub picks up advertisements broadcasted by the CowDevices, eliminates duplicate measurements (based on the sequence number included in the payload) and forwards the unique set of aggregated measurements to the server for future processing. The hubs also measure radio signal parameters (e.g., Received Signal Strength Indicator - RSSI), record the MAC address of the transmitters, and calculate the number of advertisements received from each MAC. The MACs are checked against a whitelist so that Hubs only process the BLE advertisements coming from known CowDevices. This allows to reduce the workload of the Hub and improves its performance. The MAC and the number of advertisements is aggregated and forwarded to the Server providing more insight on cow activity, and enabling rough estimation of cow localization on the farm. Additionally, the MAC is used to assign measurements to the particular animal.

The Hubs ensure reliable transmission of the measurements to the Server using the application-level protocol with retransmissions. This feature enables effective data transmission even if serial communication is used (e.g., GSM) or the central Server is down.

Fig. 3.
figure 3

The Hub in IP57 enclosure

3.3 Server

The server performs an essential role in our system. It is located in the cloud and communicates with the Hubs over the Internet (either the GSM connection or a cable). It keeps the information about the databases, manages the upcoming files, runs algorithms to calculate characteristics, raises alarms, and enables REST (REpresentational State Transfer) communication with hubs and end-user applications.

We needed to store information about the whole system. We used databases to keep data about farmers (for example id, name, credentials), cowsheds (for example size, GPS coordinates), cows (for example id, group), CowDevices (for example id, mac, name), hubs (for example id, mac, location in cowshed), data from sensors and finally characteristics and alarms calculated by our algorithms.

The server receives data from CowDevice sensors. Hubs constantly send them via REST communication by using compressed files. The files are stored, unpacked, analyzed, and after all necessary operations, they are archived again. The server analyzes incoming messages; first, it removes duplicates (it can happen when different hubs received information from the same CowDevice), next it checks if message contains correct pieces of information (CowDevice can send frame with device status - for instance, to inform about not working module) and finally it backups old data to an external server.

The server also uses the scheduler, which is responsible for running algorithms a few times in an hour. Each algorithm uses historical data from sensors (usually a few hours back) and previous results of algorithms (usually a few days back). We called the results of the algorithms as characteristics. These characteristics are used to generate graphs and raise alarms. The server controls which data should be analyzed and how to interpret results. Our system will also be allowed to localized animals in cowsheds based on RSSI signal (it is one of an algorithm we work on).

The last significant role of the server is controlling communications with hubs and end-user Android application. Communication is carried out by REST. Endpoints allow reading information (for example, characteristics, alarms, graphs) about farms, a herd of cows, groups, and particular cow and checking status of the system (by administration). They also allow adding new animals to the system or connecting cow devices with a particular cow. They also control communications with hubs by allowing them to send files.

3.4 Android Application

The end-user Android application displays information about each individual cow and each group of cows to the farmer (Fig. 4). It is an example of how it can look like in a commercial solution, so its functionality is limited. It allows monitoring the status of a herd of cows by farmers. Thanks to the information presented in graphs and alarms, farmers can better monitor the health of their cows and faster response to any disorders. This is important, especially when there are many animals in the herd, and the farmer cannot monitor each animal every day.

Fig. 4.
figure 4

Screenshots from the application. (On left) List of cows with (marked red) and without (marked green) active alarms. (On right) Plots with characteristics for selected cow. (Color figure online)

The application allows checking the actual state of the herd using a list of all the cows with additional information. It was important that the information is presented in such a way that it is straightforward and easy to understand. This includes color-coding and alarm icons (Fig. 4) that encode different types of alarms including health alarm (usually correlated with problems with feeding), estrus related alarm (usually suggest that a cow is ready for insemination), or the device-related alarm (which informs the farmer about CowDevice malfunction).

The farmers can also check detailed information about the particular cow. This is needed, especially when they would like to get new knowledge of why the system decided to raise the alarm. The application uses graphs to present information about cow status. For example, activity, rumination, heat, or the number of incoming messages (for the system diagnosis purpose).

The application also allows us to add new animals to the system and link it with the CowDevice. It uses the Representational State Transfer (REST) communication with the server and BLE to setup parameters of the CowDevices. The farmer needs to set information about the cow, including its ear tag number and breeding group. The farmer can also edit or remove the cows from the system.

4 Use Case

During the development of the CowMonitor system, over three years (2017–2019), several measurements were carried out at three different dairy farms in Poland. The largest test installation was carried out at the “AgroTak Zagrodno” dairy farm in Lower Silesia in Poland. Most of the illustrations in this section are based on the measurements taken there during the last 6 months of 2019. During this period, depending on the month, from 81 to 119, cows were monitored using CowDevice sensors.

Fig. 5.
figure 5

Results of hand-tagging 12 h from the life of cow number 393. The graph presents the measurements from the X, Y, Z axis of the accelerometer. Periods of rumination are marked with yellow background (Color figure online)

The three-axis accelerometer of the CowDevice is used as the primary data source. For research purposes, all three axes were tested, but later it turned out that the two axes (horizontal X: diametrically along the cow’s body, from head to tail, and vertical Y: top-down) provide enough information to distinguish all basic behaviors of the cow. The Bluetooth channel bandwidth is very limited, so only selected aggregating characteristics can be sent for further analysis. To enable optimal selection of transmitted parameters, first, the reference data was collected for 2 months, in the form of recordings with a video monitoring system. Then all measurement data from accelerometer were hand-tagged using a specially developed application. An example graph from this application is shown in Fig. 5.

The selection of relevant features was done with the use of classification tree analysis. Then, the standard decision tree learning algorithm C4.5 was used to enable the detection of selected basic behaviors of a dairy cow (Fig. 6).

Fig. 6.
figure 6

Characteristic graph shapes related to behaviors detected by classification trees used in the CowMonitor system

Finally, the algorithms processing the measurement data, have been implemented in the form of a three-level architecture, where:

  • Level “0” - calculates statistical characteristics to identify typical short term micro-behaviors (feeding, ruminating, resting, mounting other cows, etc.). Measurement data from 10 s are frequency filtered and aggregated into a selected set of characteristics. This level is processed directly on board of the CowDevice.

  • Level “1” - evaluates the current state of the cow (aggregates data for each clock hour, against the background of the history of the previous few hours). Parametrized decision trees are used on this level, to allow extraction and aggregation of useful cow wellbeing criteria.

  • Level “2” - elaborates a reference model taking into account simple stereotypical characteristics of a particular cow (estimated from the last few days and used by level 1). Level “1” and “2” are processed on the cloud server.

  • Work is also underway to develop a more accurate reference model, calculated on the basis of the data from the previous 2–6 months (individual modelling of each cow, in place of one universal stereotype model).

The main task to achieve, at this stage of the research, was the most reliable and precise diagnosis of current cow state and behavior. Particular emphasis was placed on the estrus time detection and supporting the farmer in taking insemination decisions. This goal has been achieved successfully. Cow state is easily observable through a series of complementary charts which are illustrated in several following figures (Fig. 7, 8, and 9).

Fig. 7.
figure 7

Chart presenting characteristic A03, which generally estimates the level of overall cow’s activity, with a visible increase at the time of estrus. “Heat Alarm” is marked below the chart at October 14.

Fig. 8.
figure 8

Chart presenting characteristic R24 (percentage of rumination time in the last 24 h). Rumination time is a complementary information to confirm the heat. Significant reduction at October 15 is a side effect of increased estrus activity.

These graphs show one of the cows (numbered 140) in October 2019, when:

  • the first signs of estrus were detected by CowMonitor characteristics around 5pm on October 14,

  • later, the system generated “Heat Alarm”, the same evening at 9 pm,

  • finally, the estrus was confirmed by a vet, the next day morning.

Fig. 9.
figure 9

Characteristic HL03 estimating the level of estrus-specific activities over last 3 h (value proportional to the probability of estrus) (Color figure online)

The innovative achievement is the development of a new way to detect the estrus-specific behavior of a cow in the form of characteristic HL03 (Fig. 9). The central concept of this indicator is somehow analogous to multidimensional scanning. It aggregates both short and log-termed features of cow activity to a compound measurement estimating estrus occurrence. It allows distinguishing, with very high efficiency, the rising trend of estrus activity, from the increases in the activity caused by other factors. The current value of this indicator (red color) is displayed against the background of historical values from the previous few 1–4 days (green). This type of visualization allows taking into account the physical characteristics of individual cows. Figure 10 merges the sequence of estrus occurrences successfully detected over the six months.

Fig. 10.
figure 10

Charts illustrating successful estrus detection in subsequent 6 months (August-December 2019). Penultimate estrus (on December 4), was not measured due to a power outage in the farm buildings.

Fig. 11.
figure 11

Large decrease in the rumination characteristic to the mastitis disease

The second important task of the CowMonitor system (in addition to the recognition of estrus) is the early detection and diagnosis of critical diseases. After the measurements were carried out, the breeding and veterinary documentation was reviewed to check whether there is a correlation between the alarms generated by the system and confirmed cases of diseases. Mastitis disease was selected as the main subject of the study. During the 6 months of measurements, 10 subclinical or clinical mastitis cases were recorded in the observed herd. In almost all cases, this disease manifests itself in a very sharp decrease in rumination. Figure 11 presents typical shapes of rumination charts for such a situation. In eight cases, the alarm was generated before the mastitis was diagnosed. In the ninth case, the symptoms are visible in the CowMonitor but were too delicate to cause an alarm. Only in one case, no changes in the rumination were observed at all. These first results, with an average disease detection efficiency of around 90%, are very promising. However, the data about a larger number of cases need to be collected to perform reliable statistical tests.

Fig. 12.
figure 12

First detection of mastitis for cow number 208, on October 29th

Fig. 13.
figure 13

Monitoring mastitis treatment: two sequential relapses on October 31st and November 3rd

The high utility of the CowMonitor system appeared in the difficult case of mastitis in cow number 208. After accurate diagnosis on October 29, appropriate treatment was started (Fig. 12). Unfortunately, the first type of treatment did not end with a full recovery. There were two sequential relapses during the following days (Fig. 13). CowMonitor rumination charts, allow accurate monitoring of treatment progress. The vet or dairy farmer can immediately change the type of treatment, when progress is too slow or when the symptoms of relapse occur. Without the CowMonitor system, precise monitoring of treatment progress is much more difficult.

5 Conclusions

The developed system efficiently and accurately monitors behavior of the dairy cows and allows to detect a particular physiological status like estrus and some health problem (e.g., mastitis). This task is supported by IoT infrastructure consisting of hardware devices, the cloud system, and the end-user application. New innovative techniques of data measurement, including the aggregate behavior indicator, enable us to precisely discriminate cow activities. The prototype devices presented were evaluated in real setup and have been so efficient that are now being transformed to a commercial system.

In the future, the system can be extended with new algorithms that could detect symptoms of other diseases, for example, lameness. In particular, work is underway on the use of a magnetometer for low-energy estimation of cow mobility, and their correlation with the diagnosis of diseases manifested by walking changes. It is worth noting that the location of each CowDevice can be roughly estimated by the measurements collected by every Hub. This can be used to detect cows changing the breeding group, simplify the location of a cow when needed (e.g., for veterinary treatment) or provide more information about the animal activity and movement that may support health diagnostic. The use of BLE v.5.1, which supports Angle-of-Arrival localization, may further improve the location accuracy and provide more benefits to the system. Additionally, one universal behavior stereotype model is planned to be replaced by individual modelling of each cow.