## 1 Introduction  
Over 50% of the global agricultural gross domestic product comprises the livestock sector [1], the food demand is expected to increase by 70%, and corresponding meat production will increase by 50% by the year 2050, thus making the agri-food and livestock key industries for future [2]. This demand will be met through intensification in livestock farming by increasing densities and production units, using concentrated feed, and improving infrastructure and feed efficiencies [3]. For instance, the commercial swine confinement building, which usually tears a high density of pigs in relatively small areas, is the most common and widespread means of pig production. The Food and Agriculture Organization (FAO) reported that about 1.5 billion pigs were reared to produce meat in 2016 and its total weight of meat production exceeded 120 million tons in 2018 [4]. Nevertheless, such challenges can be attained [5] by implementing autonomous monitoring and intelligent management decisions based on precision livestock farming (PLF). According to [PERSON] [6, 7] the application of PLF could be a good approach to optimize the care and attention that farmed animals receive by monitoring animals at the smallest unit that can be managed in real-time since it allows to have control on animal health and welfare and the microclimate of the barn. Precision livestock management can be achieved through PLF systems that typically consist of three separate functions [8]: sensing and monitoring, analysis and decision making, and intervention, which will allow producers to manage extensive animals, while still providing the level of care similar to what can only be done with fewer animals [9]. The application of wireless sensor networks (WSN) in improving the traditional methods of farming has received long-term focus from researchers in precision agriculture [10; 11; 12] due to its salient features including but not limited to dynamic topology configuration [13], node heterogeneity [14], scalability and tolerance against communication failures in harsh environmental conditions [15]. Among numerous wireless communication technologies, ZigBee [16; 17] which defines the network and application layer protocols based on the IEEE 802.15.4 standard [18] is preferred over other technologies like Bluetooth, Wi-Fi [11] for the development of WSN, due to its reliability, low cost, and low power consumption property. ZigBee based network architecture for animal health monitoring has been proposed [19]. The real-time monitoring of physiological health parameters of animals has been attained by a ZigBee based system [20]. For optimal health and production, the air surrounding the pig should fulfill certain requirements which are often not met partly because of the influences of outdoor climate condition and because of the effects of the pigs on the housing environment. The main factors constituting the microclimate inside a swine building include air temperature, relative humidity and airspeed, as well as the concentration of harmful gases and other pollutants [21]. Temperature and humidity are the main environmental factors that are influenced by pigs in facilities, although CO2 and even NH3 concentrations also are strongly affected by the pigs' activity [22]. For example, pigs are especially susceptible to exposure to heat stress which can trigger behavioral and physiological responses and thus negatively affect productivity during the summer. Carbon dioxide has been widely used as a tracer gas [23] to quantify ventilation in livestock buildings and exposure to high concentrations of this gas has also been associated with impaired health of both humans and animals [24]. Ammonia is one of the most critical pollutants for pig production because of its direct threat to animal and workers' welfare and health [25; 26]. Therefore, it is critical to monitor and intervene in the microclimate in time so that alternative management practices can be developed and implemented to improve overall animal health and well-being.