Design and Implementation of Intelligent Gateway System for Monitoring Livestock and Poultry Feeding Environment Based on Bluetooth Low Energy

: This article proposes a gateway system design method applied to the monitoring of a breeding environment based on Bluetooth low energy consumption. Through the queue mechanism and buffer management method, the key information that has the greatest impact on the monitoring effect is sent ﬁrst, and the feedback mechanism is used to adjust the sampling period of the node in conjunction with the abnormal degree of the monitoring parameter. Experimental results show that the system constructed in this article signiﬁcantly shortens the transmission delay of key information, with an average packet loss rate of 1.09%. Compared with the traditional method, this method is more timely and effective in handling abnormal data. It effectively solves the short distance and low efﬁciency of Bluetooth “point-to-multipoint” communication in the case of high data concurrency, and improves the reliability and stability of communication. In turn, the losses caused by environmental mutations are reduced.


Introduction
In the field of wireless sensor networks, the Bluetooth gateway uses a star structure to network multiple sensor nodes carrying Bluetooth devices [1], which can minimize the power of the data transmission process. When the gateway and the server are far away, Wi-Fi and other long-distance communication protocols are used to realize the transmission between the cached data in the gateway and the server [2,3].
The Bluetooth gateway used in the prior art for breeding environment monitoring has the following technical problems: 1. When the Bluetooth gateway is connected to eight or more devices, it will cause data overflow and data loss in the gateway storage due to high data concurrency issues. It is necessary to design a cache queue to store the data to be forwarded to the server.
2. In the monitoring of a breeding environment, it is difficult for multiple types of sensors to use a unified data sampling frequency for adapting to actual requirements. It is necessary to dynamically adjust the sampling frequency to grasp the monitoring effect in real time.
3. Due to the high complexity of the network, network congestion, and various network failures, the current remote communication mechanism of Bluetooth technology requires the application of a retransmission mechanism to reduce the packet loss rate. This also means that the gateway's cache queue will face data volume due to continuous retransmissions. In the case of a sharp increase, the network overhead caused by retransmission at the same time will increase the delay.
Based on the above analysis, this article proposes a low-power Bluetooth gateway system design method suitable for breeding environment monitoring, integrating Bluetooth and Wi-Fi wireless communication technologies to establish a two-way communication path between the terminal and the server to ensure that data can be transmitted in the most appropriate way and avoid unnecessary power consumption while improving transmission efficiency. The priority queue is used to optimize the processing efficiency of the Bluetooth gateway, which reduces the delay of time-sensitive information while ensuring the reliability of data communication and improves the real-time performance of the Bluetooth data transmission. The gateway establishes a feedback mechanism, and the gateway intelligently adjusts the collection frequency of terminal sensor nodes according to the abnormality of the collected parameters.
The rest of this article is organized as follows: Section 2 introduces the related work on wireless sensor networks and smart Bluetooth gateways applied to monitoring of a breeding environment. The system architecture is described in Section 3. In Section 4, the system is tested and the results are analyzed. Section 5 summarizes the article and makes some suggestions for future work.

Related Work
Information agriculture is one of the distinctive features of modern agriculture. "Smart agriculture" driven by agricultural big data is an inevitable choice for ensuring highyield [4], high-efficiency, and the sustainable development of agriculture.

Application of WSN in Breeding Environment Monitoring
Early application research on the monitoring results of a breeding environment focused on the automation and mechanization of equipment, such as heating equipment and rolling shutter systems [5]. Recently, researchers have tried to introduce algorithms or models into environmental monitoring and control processes, such as particle swarm optimization algorithms, fuzzy theory, and fluid mechanics [6][7][8].
In recent years, the use of multiple types of sensors to simultaneously measure the relevant parameters of a poultry growth environment in real time has become a new hot spot, and many scholars have conducted a lot of research on this. Blazy V et al. [9] used Internet of Things technology to monitor the gas composition of a pig house and realized the regulation of the smell of the pig house. Tang J et al. [10] developed a remote chicken house intelligent environment monitoring system based on ARM and ZigBee technology, which can remotely monitor the chicken house environment. Guo et al. [11] developed an intelligent goose house environmental monitoring system and used a back propagation (BP) neural network to construct an intelligent control model with historical temperature and relative humidity data to assist in the practice of the out-of-season breeding of geese. Sensor nodes and gateways in wireless sensor networks are severely limited by energy. Ultra-low-power Bluetooth technology as a communication medium can greatly reduce the power consumption of nodes and gateways. Therefore, how to break through the Bluetooth communication distance and the limitation of the number of connected devices has become an urgent problem to be solved.

Smart Gateway
Research on smart gateways can be divided into commercial applications and academic research [12]. The mainstream gateway products in commercial applications mainly include the following types, as shown in Table 1:

SX1301 LoRa Gateway Semtech
Only supports LoRaWAN; has 1 independent transmission channel and 8 independent reception channels.
In terms of academic research, it is mainly dedicated gateways that support a single protocol such as ZigBee gateways, 2.4 G wireless gateways, session initiation protocol (SIP) gateways, etc. These gateways have a single application scenario and do not have universal applicability. At present, the research on gateways supporting multiple protocols is still immature.
In summary, most of the existing gateways on the market have the disadvantage of platform incompatibility, the secondary development being difficult, and the cost being high. In terms of academic research, the gateway only supports a single protocol, which severely limits the scope of application and has limited scalability. In response to the above problems, this article proposes a smart gateway that supports Bluetooth protocol and Wi-Fi protocol, which uses Bluetooth protocol to establish a data transmission path between the sensor node and the gateway. Due to the low power consumption of Bluetooth, the function of the node can be reduced to the greatest extent. This greatly improves the battery life of sensor nodes and gateway devices. At the same time, the Wi-Fi module integrated in the gateway realizes remote data transmission, which makes up for the shortcomings of the Bluetooth communication distance.

System Structure
This article designs a Bluetooth gateway for breeding environment monitoring, which is suitable for livestock and poultry house environment monitoring. Take the Bluetooth gateway of pig house environment monitoring as an example, the pig house environment is a rectangular area with a length and width of 20 m. The system architecture is shown in Figure 1. Temperature and humidity, light intensity, and CO 2 and NH 3 sensors are deployed in the pig house. The sampled data are transmitted to the gateway via Bluetooth. The data are processed and stored in the gateway and transmitted to the server using Wi-Fi. The innovation of the equipment lies in the application of priority queues and feedback mechanisms to the Bluetooth gateway construction process in breeding environment monitoring [13]. The specific contents include: • Data priority queue queuing mechanism. A sorting mechanism that assigns priority according to parameter types and numerical abnormalities is used for the data of multiple types of sensors transmitted to the Bluetooth gateway. The sorting mechanism means that for data frames that require low latency, the gateway assigns high priority to them and stores them in the cache queue, and the gateway forwards information to the server in order of priority from high to low. • Cache queue management method. When the cache queue is full, it deletes the data with low priority and high redundancy, and caches the current data in the queue. The priority is to calculate the priority of the data, compare the priority of the data with the priority of the existing data in the cache queue, and delete the data with the lowest priority in the cache queue. Data with higher redundancy means that the data are the same as the data at the adjacent time, and the more of the same part, the higher the redundancy. • Sampling frequency adaptive mechanism. Performing threshold judgment on the multi-parameter data transmitted by the node to the Bluetooth gateway, determining the sensor sampling frequency according to the abnormality of the parameter, and sending feedback information to the node to realize the adaptive control of the sampling frequency of the node sensor. The feedback information is a data frame containing the node number and the collection period value.

Hardware Selection and Design
• E73-2G4M08S1C Bluetooth module E73-2G4M08S1C is a Bluetooth module with a small size and ultra-low power consumption developed by Ebyte [14]. The module uses the nRF52840 radio frequency chip that supports BLE4.2 and BLE5.0 protocol produced by Nordic, and the chip uses the ARM CORTEX-M4 processor with high performance and low energy consumption. The module adopts a 32 M industrial-grade crystal oscillator, and has peripheral interfaces such as UART, I 2 C, SPI, ADC, DMA, PWM, etc., which provide better scalability for secondary development. The performance description of E73-2G4M08SIC Bluetooth module is shown in Table 2.
E73-2G4M04S1B is a small-volume SMD Bluetooth module developed based on the nrf52832, produced by Norway Nordic, as the core [15]. It uses a 32 MHz industrialgrade crystal oscillator with stable performance. nrf52832 has a high-performance ARM CORTEX-M4F core, supports BLE4.2 and BLE5.0, and has abundant peripheral resources, which is convenient for secondary development. The performance description of the E73-2G4M04S1B Bluetooth module is shown in Table 3.
E103-W01 is a serial to Wi-Fi module developed by Ebyte based on the ESP8266EX chip produced by Espressif [16]. The module is packaged in a small size with a patch equipped with a PCB antenna and can use the serial port for data transmission and reception. The E103-W01 module supports standard IEEE802.11b/g/n protocol and complete TCP/IP protocol stack, and has a STA/AP/STA+AP working mode. The module uses the AT command set to develop and integrate the transparent transmission function, which can realize the rapid transmission of data. The performance description is shown in Table 4. The Bluetooth gateway constructed in this article integrates an E73-2G4M08SIC Bluetooth module and an E103-W01 Wi-Fi module, and communicates between Bluetooth and Wi-Fi through a serial port. The Bluetooth gateway PCB design and the physical diagram are shown in Figure 2.

Software Design of the Bluetooth Gateway System
The Bluetooth gateway system can build a two-way communication channel between the collection terminal of the information perception layer and the server side of the information processing layer [17], and realize the transmission of multi-parameter feeding environment data from the collection terminal to the server side and the transmission of feedback information from the gateway to the terminal device. The Bluetooth gateway information transmission system function design is shown as in Figure 3. The collection nodes perform Bluetooth pairing with the Bluetooth master module in the Bluetooth gateway and transmit the collected raw data to the gateway through the Bluetooth communication protocol. The Bluetooth master module in the gateway processes the original data and transmits the formatted data packet to the Wi-Fi module through the serial port. The Wi-Fi module and the server form a local area network, which uses the Wi-Fi protocol to remotely transmit data packets, and finally displays real-time information about the breeding environment in front of farmers [18]. According to the degree of abnormality of the monitored parameters, the gateway can issue the current collection interval command in time for each collection terminal, so as to realize the scientific control of the terminal equipment collection plan.

Introduction to BLE
BLE is a short-range, low-cost, interoperable wireless technology [19]. Generally, BR/EDR Bluetooth before Bluetooth 3.0 is called traditional Bluetooth, and LE Bluetooth after Bluetooth 4.0 is called low energy Bluetooth. The Bluetooth 4.0 standard includes a traditional Bluetooth module part and a low-power Bluetooth module part, and is a dual-mode standard. The biggest feature of Bluetooth low energy is the reduction in cost and power consumption, and it could be applied to scenarios that require high realtime transmission. Compared with classic Bluetooth, BLE's operating and standby power consumption is extremely low, which is only 1-50% of classic Bluetooth power consumption. The comparative analysis of BLE and classic Bluetooth is shown in Table 5.

Bluetooth Gateway Function Realization
The nRF52840 Bluetooth module in the Bluetooth gateway is used as the master device in the networking, and the nRF52832 Bluetooth module of the collection terminal is used as the slave device. In the pig breeding application scenario in this article, a network solution in which one master is connected to 10 slaves is used, and 4 Bluetooth master devices are used to realize the connection of 40 slave devices in the application scenario to complete the stable transmission of information from the slave to the gateway.
The Bluetooth module and 10 slave devices in the gateway rely on the BLE5.0 protocol for networking. The connection between the Bluetooth master and the slave device relies on two key processes: slave broadcast and master scan. In the Bluetooth gateway proposed in this article, the scan interval was set to 10 milliseconds, the scan window to 10 milliseconds, and the scan timeout was not set. The minimum connection interval of the Bluetooth master was set to 125 milliseconds, and the maximum connection interval of the Bluetooth master was set to 250 milliseconds. In order to prevent the master device from being interfered with by other Bluetooth devices around, this article selected the filter method as the slave filter strategy. By setting 10 filters, the device name of the slave is filtered so as to ensure that the master can only connect to a group of slaves that meet the filtering conditions. The Bluetooth master and slave connection process flow chart is shown in Figure 4. In addition, since 40 different sensor nodes were placed in the pig house, it was necessary for the gateway to distinguish which node the currently received data came from. When sending data to the gateway, the slave needs to define a set of BLE-based communication protocols for the livestock and poultry breeding environment system. The data packet length of each type of sensor was 6 bytes, and the specific format is shown in Table 6. A description of the specific meaning of each field of the Bluetooth data packet is shown in detail in Table 7.  After the Bluetooth gateway system obtains the multi-parameter feeding environment data collected by the terminal in time through the Bluetooth networking, the gateway uses serial communication to complete the data transmission from the Bluetooth master to the Wi-Fi module, and the Wi-Fi module enables the transparent transmission mode to format the data, using the local area network to transmit to the server.

Bluetooth Gateway Optimization Solution
In actual application scenarios, the Bluetooth gateway needs to process and forward a huge amount of data, and the device has a high degree of concurrency, which leads to continuous updates of the Bluetooth device networking mode. It is prone to problems such as variable overflow and increased delay after the Bluetooth master continues to work for a certain period of time [20,21]. In response to this problem, the system built in this article uses priority queues and feedback mechanisms to optimize Bluetooth gateways.

Design Data Priority Queue Queuing Mechanism
In the environmental monitoring of a pig house, there are five kinds of parameters that need to be collected. Among them, NH 3 and CO 2 concentration in the air, as well as the three parameters of air temperature, humidity, and light intensity in the pig house, change more obviously with the changes of pig activity. Additionally, these two parameters have a greater impact on the health of the pig herd. Therefore, in this article, NH 3 and CO 2 data packets are determined as key information, that is, high priority information. A priority queue mechanism was introduced in the gateway design. When a large number of data packets are buffered in the gateway waiting to be sent, two types of high-priority data packets, NH 3 and CO 2 , are sent first to ensure that key information can arrive at the server in time so that farmers can deal with environmental abnormalities as soon as possible. Manual intervention is required to reduce the economic loss caused by the transmission delay of key information.
After the data frame arrives at the Bluetooth gateway, the Bluetooth module in the gateway analyzes the content of the data frame; analyzes the data parameter type; determines whether the value exceeds the threshold; assigns the data type and the priority of the value, respectively; calculates the priority according to formula (1); and places it in the priority queue. The ordinary queue is a first-in-first-out data structure. Elements are appended at the end of the queue and deleted from the head of the queue. In the priority queue, elements are given priority and have the characteristics of the highest first out. The priority queue has all the characteristics of the queue, including the basic operation of the queue, but an internal sort is added on this basis, which is essentially implemented by using a heap.
Take pig breeding as an example. Temperature, humidity, and light intensity are important parameters for protecting the pig breeding environment. NH 3 and CO 2 are harmful gases produced by pig herd activities, and parameter changes have the greatest impact on pigs. The design divides ammonia and carbon dioxide into the highest priority and assigns the highest priority, the second highest priority parameter is the light intensity and so are assigned the higher priority, and temperature and humidity are the lowest priority and are assigned the lower priority accordingly. The parameter threshold is preset in the gateway, and the part that exceeds the threshold is divided into multiple gears, and the priority is assigned to the parameter value according to the principle that the more the excess, the greater the priority.
The priority calculation method calculates the priority based on the parameter type priority (PTP) and the parameter value priority (PVP) using a weighted average method [22]. Each time the gateway receives a data frame, it first assigns the priority to the data frame information, and then enters the following into the formula to calculate the priority (P): PTP represents the type priority of the parameters contained in the current data frame, and PNP represents the numerical priority of the current data. The value of α is the weight of the priority of the parameter value, generally between 0 and 1. If the value of α is close to 0, it means that the key information of the pig breeding environment monitoring mainly depends on the type of parameter. If it is close to 1, it means that the value of the parameter may change, and has a great influence on the monitoring effect. Considering that the NH 3 and CO 2 concentration in the monitoring of the breeding environment of the pig house have a greater impact on the health of the pigs, this article will use PTP as the main indicator for priority determination. Therefore, the recommended value of α is 0.125. The specific process of the data frame priority queue queuing mechanism is shown in Figure 5. After the node successfully sends a data frame to the Bluetooth gateway, the gateway parses the content of the data frame and determines the PTP and PNP through the parameter type and parameter value. According to the formula (1), it calculates the priority of the data frame and places it in the priority queue. After the gateway establishes a connection with the server, it sends the highest priority data in the priority queue.

Design a Cache Queue Management Method
Due to the complex monitoring site environment and various electromagnetic interferences, and when Bluetooth devices are connected in one-to-many, more than eight slave devices will have disconnection problems, resulting in failure to connect between the Bluetooth master device in the gateway and the 10 collection terminals. The Bluetooth gateway designed in this article will continue to scan the surrounding Bluetooth devices that meet the conditions when the number of connected slave devices is less than 10. In other words, when a slave device is disconnected from the Bluetooth module in the gateway, it will automatically reconnect. Once the reconnection is successful, it will send all the data packets collected and stored during the disconnection to the gateway. The Bluetooth module needs to design a buffer queue to store these data packets and then forward them in turn after the Wi-Fi module establishes a connection with the server. At the same time, the pig house environment is relatively closed, the local area network signal is weak, and it is difficult to establish a reliable long-term connection between the Wi-Fi module in the gateway and the server. Therefore, when the gateway is unable to transmit data in real time due to factors such as the instability of the communication link, it needs to buffer the collected data continuously sent from the slave device. In summary, the cache queue management method proposed in this article is necessary for reliable data transmission.
After data transmission fails due to high network complexity or network congestion during data transmission, the Bluetooth gateway activates the automatic retransmission mechanism, and the node continuously transmits new data to the gateway according to the sampling frequency, which will cause the buffer in the queue to be cached for a period of time with more and more data.
This article proposes a cache queue management method. When the queue is full, it chooses to delete the data with the lowest priority and higher redundancy in the queue and save it to the current latest data. While reducing the system packet loss rate, it can also ensure that key information is not lost.

Design Sampling Frequency Adaptive Mechanism
In the monitoring of the pig breeding environment, the initial collection period of temperature, humidity and light intensity was 30 min, and the initial collection period of ammonia and carbon dioxide was 15 min. When the monitored parameter content exceeded the threshold, immediate intervention measures would be taken, and the sampling frequency would be increased at the same time to monitor the changes of abnormal parameters in real time.
The adaptive control sampling frequency mechanism proposed in this article is shown in Figure 6. The threshold value of the multi-parameter data transmitted by the node to the Bluetooth gateway was judged, the sensor sampling frequency was determined according to the abnormality of the parameter, and the feedback information was sent to the specific node. The sampling frequency of the node sensor realized self-adaptive regulation.
The gateway compares the values collected by various types of sensors with the set threshold and different gears after the threshold is exceeded to determine the degree of abnormality of the current parameter. According to the principle that the more the threshold is exceeded, the shorter the sampling period is, the terminal node is assigned a sampling period value, and the sampling period value is stored in the array corresponding to the node. The feedback information includes the "ID" and "collection period", expressed in JSON format. In the JSON string, the slave device establishes a connection with the master through the "ID" value, and the Bluetooth master module searches for the collection period preset by the "ID" and sends it to the corresponding slave preset by the "ID" to complete the communication. After the node and the gateway establish communication, the gateway takes out the latest sampling period value corresponding to the node from the array, packs the node number and the sampling period value suggested by the gateway, and sends it to the corresponding node.

Test Results and Analysis
In order to verify the effectiveness of the Bluetooth gateway design method proposed in this article, the author of this article designed experiments to test the maximum communication distance, communication stability, and packet loss rate of the gateway. The test environment was a large-scale pig farm in Tianjin equipped with a local area network. The test tools were temperature and humidity sensor nodes, Bluetooth gateways, tape measures, and PCs equipped with serial debugging assistants. The test time was from 17 to 28 March 2021. Excluding the time-consuming equipment layout, node installation, and power outage of the pig house, the effective test time was 276 h.

The Longest Communication Distance Test
For selecting the starting point of the test, a 30 m tape measure was used to measure a linear distance of 10 m, 15 m, and 20 m, respectively, placing the markers at the starting point of the test as the benchmark. In the test process, the temperature and humidity sensor node and the Bluetooth gateway were first kept within 10 m, and whether the communication was normal was judged by monitoring the serial port print information of the gateway. The testers moved the temperature and humidity sensor nodes to 10 m, 15 m, and 20 m test points for communication testing. After the distance of 20 m was exceeded, the tester continued to move until it lost communication with the Bluetooth gateway, placing a marker at the current location of the tester and measuring it with a tape measure to obtain the farthest communication distance [23]. The test error of manual measurement was within ±10 cm. The test results are shown in Table 8. The average longest communication distance of the Bluetooth gateway was 20.33 m, which meets the distance requirements for the environmental monitoring of the pig house.

Communication Stability Test
The three sensor nodes were, respectively, deployed in a 20 m × 20 m rectangular test area, and the upper computer and four Bluetooth gateways were deployed in a corner of the test area. At the beginning of the test, the Bluetooth gateway and the server were connected to the router to form a local area network. After the node was powered on, the working status of each node was determined by observing the data received by the server. If the server showed that the device was online and the data upload could be completed regularly, it was determined that the node communication was normal [24]. The test time was 1 h, and the node collection interval during the test was 60 s. After the test, the server backstage exported the communication records of all nodes during the test and compared the actual number of data sent and received by the node to the theoretical value to judge the communication stability.
The test results are shown in Table 9. The three nodes sent a total of 60 pieces of data, and actually received 60 pieces of data, which proved that the communication success rate was 100% and the communication stability reached expectations.

Packet Loss Statistics
After all the tests were completed, the background records were retrieved for statistics on packet loss [25]. Sensor nodes were installed in the breeding room, farrowing room, brooding room, and growth room of the pig house. The test data, such as the effective test time, the number of received data packets, and the number of lost data packets for each type of pig house, are shown in Table 10. According to the statistical results, the average packet loss rate of the pig house environmental monitoring gateway was 1.09%. Analysis showed that the main influencing factors leading to packet loss during the test were: 1.
The communication distance between the gateway and the sensor node being too long or multiple nodes being arranged in a straight line. If the distance was too long (≥20m), the signal would be weak and the data transmission link would be unstable. The arrangement of multiple nodes in a straight line would cause the pairing of distant nodes to be blocked and packet loss would occur.

2.
There was a wall between the gateway and the sensor node, or the ionization shielding phenomenon caused by a metal barrier weakened the signal. 3.
The poor LAN signal in the test pig house caused occasional packet loss in the Wi-Fi-based gateway remote transmission module.
From the perspective of the general requirements of the monitoring system and the integrity analysis of the test data, the packet loss rate of the gateway system met the requirements.

Power Consumption Test
Considering that the monitoring system will be applied to the monitoring of livestock and poultry breeding environments, in order to further reduce the cost of deployment and maintenance, this article designed a Bluetooth gateway monitoring system based on BLE. Using Bluetooth as a wireless transmission technology provides the collection terminal with ultra-low power consumption characteristics [26]. A cycle of the collection terminal's work includes the collection phase and the low power consumption phase. The low-power consumption phase of the collection terminal means that all peripherals of the module stop working, but the module still maintains a connection with the Bluetooth master. Through the power consumption analysis experiment on the collection terminal, it is known that the average time period of the collection phase was 0-12 s, the time period of the low power consumption phase was 12 s-30 min, and the next time period was entered after the end of the sleep. When testing the average power of the terminal node, a DC voltage source was used to supply the node with a voltage of 3.7 V, a five-and-a-half-digit high-precision ammeter was used to test the operating current of the node, and the average power of the node was calculated. The test showed that the current during the collection phase was less than 10 mA, and the current during the low power consumption phase was less than 0.9 mA. When the voltage supply was 3.7 V, it can be derived from the following: 3.7 V × [10 mA × 12 s + 0.9 mA × (30 × 60 s − 12 s)]/30 × 60 s ≈ 3.55 mW (2)

Latency
This article proposed and designed a Bluetooth gateway system based on BLE, which constructs a small networking between the terminal node and the gateway Bluetooth master module. [27] Since the slave cannot obtain the network time and is not consistent with the server-side timestamp, the latency cannot be calculated by directly printing the timestamp. In this article, after receiving the data packet, the server immediately sends a receiving success message to the slave through the Bluetooth gateway. After receiving the message, the slave immediately sends a reply message. The server calculates the time difference between the arrival of the data packet and the reply message, and divides the time difference by 2 to obtain the latency. Under the influence of the same number of slaves connected to the gateway and the amount of transmitted data on the network, with a period of 10 s, the latency when the system proposed in this article was connected to the traditional Bluetooth gateway with different numbers of slave devices was tested. The test data are as follows in Table 11: The test results show that when the master was connected to four slave devices, the latency of the gateway designed in this article was almost the same as that of the ordinary Bluetooth gateway. As the number of slave devices increased and the scale of the Bluetooth network increased, the latency of the two gateways also increased. Compared with ordinary Bluetooth gateways, the system proposed in this article had lower latency and more timely and effective data transmission.

Conclusions
This article proposes a gateway design method applied to the monitoring of a breeding environment based on low-power Bluetooth technology. In the gateway design, the priority queue and feedback mechanism are innovatively introduced, which effectively solve the problems of a short communication distance and the low efficiency of "one master, multiple slaves" for Bluetooth devices. The gateway applies a queue mechanism to give priority to the key factors that have a greater impact on the health of the breeding pigs. At the same time, the feedback mechanism is used to speed up the collection frequency of abnormal parameters, which can respond to sudden changes in the environment and promptly remind the breeders to take effective measures.
The test results show that when the system is applied to the monitoring of a breeding environment such as a pig house, it greatly reduces the packet loss rate of the gateway forwarding process, can achieve stable communication within 20 m, and can improve the real-time performance of data transmission and reliability, while reducing the overall power consumption of the system. Compared with the traditional gateway design method, the system proposed in this article is more timely and effective in high-concurrency data processing and response to abnormal environmental changes. It is more suitable for the field of livestock and poultry breeding environment monitoring, which requires various types of sensing parameters and complex environmental changes, improving the monitoring effect, reducing livestock and poultry diseases caused by environmental mutations, and thereby reducing the economic losses of farmers.