Skip to main page content
U.S. flag

An official website of the United States government

Dot gov

The .gov means it’s official.
Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.

Https

The site is secure.
The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.

Access keys NCBI Homepage MyNCBI Homepage Main Content Main Navigation
. 2025 Nov 25;25(23):7186.
doi: 10.3390/s25237186.

MQTT-Based Architecture for Real-Time Data Collection and Anomaly Detection in Smart Livestock Housing

Affiliations

MQTT-Based Architecture for Real-Time Data Collection and Anomaly Detection in Smart Livestock Housing

Kyeong Il Ko et al. Sensors (Basel). .

Abstract

This study designed a message queuing telemetry transport (MQTT)-based communication framework to acquire environmental data with stable, low-latency response (soft real-time capability) and detect anomalies in smart livestock housing. We validated the performance of the proposed framework using actual sensor data. It comprises environmental sensor nodes, a Mosquitto MQTT broker, and a GRU-based anomaly detection model, with data transmission via a WiFi-based network. Comparing quality of service (QoS) levels, the QoS 1 configuration demonstrated the most stable performance, with an average latency of ~150 ms, a data collection rate ≥ 99%, and a packet loss rate ≤ 0.5%. In the sensor node expansion experiment, responsiveness (≤200 ms) persisted for 10-15 nodes, whereas latency increased to 238.7 ms for 20 or more nodes. The GRU model proved suitable for low-latency analysis, achieving 97.5% accuracy, an F1-score of 0.972, and 18.5 ms/sample inference latency. In the integrated experiment, we recorded an average end-to-end latency of 185.4 ms, a data retention rate of 98.9%, processing throughput of 5.39 samples/s, and system uptime of 99.6%. These findings demonstrate that combining QoS 1-based lightweight MQTT communication with the GRU model ensures stable system response and low-latency operation (soft real-time capability) in monitoring livestock housing environments, achieving an average end-to-end latency of 185.4 ms.

Keywords: GRU; MQTT; QoS; anomaly detection; low-latency monitoring; smart livestock housing.

PubMed Disclaimer

Conflict of interest statement

The authors declare no conflicts of interest.

Figures

Figure 1
Figure 1
System Overview (Adapted from [22]).
Figure 2
Figure 2
MQTT message transmission and processing flow. Solid arrows indicate actual message transmission paths, while dashed arrows represent internal processing flows.
Figure 3
Figure 3
QoS-Level Comparison of MQTT Communication Performance.
Figure 4
Figure 4
Performance Comparison of Anomaly Detection Models.

References

    1. FAO . The Future of Livestock in Sustainable Food Systems. Food and Agriculture Organization of the United Nations; Rome, Italy: 2021. [(accessed on 11 August 2025)]. Available online: https://www.fao.org/documents/card/en/c/cb7004en.
    1. European Commission . Safeguarding Food Security and Reinforcing the Resilience of Food Systems; COM(2022) 133 final. European Commission; Brussels, Belgium: 2022. [(accessed on 18 August 2025)]. Available online: https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=celex:52022DC0133.
    1. United States Department of Agriculture (USDA) Precision Agriculture. USDA National Institute of Food and Agriculture; Washington, DC, USA: 2025. [(accessed on 18 August 2025)]. Available online: https://www.nifa.usda.gov/grants/programs/precision-geospatial-sensor-te....
    1. St-Pierre N.R., Cobanov B., Schnitkey G. Economic Losses from Heat Stress by US Livestock Industries. J. Dairy Sci. 2003;86:E52–E77. doi: 10.3168/jds.S0022-0302(03)74040-5. - DOI
    1. Huynh T.T.T., Aarnink A.J.A., Gerrits W.J.J., Heetkamp M.J.H., Canh T.T., Spoolder H.A.M., Kemp B., Verstegen M.W.A. Thermal behaviour of growing pigs in response to high temperature and humidity. Appl. Anim. Behav. Sci. 2005;91:1–16. doi: 10.1016/j.applanim.2004.10.020. - DOI

LinkOut - more resources