Next Article in Journal
Virtual World as an Interactive Safety Training Platform
Previous Article in Journal
An Approach for Realizing Hybrid Digital Twins Using Asset Administration Shells and Apache StreamPipes
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

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

College of Electronic Information and Optical Engineering, Nankai University, Tianjin 300350, China
*
Author to whom correspondence should be addressed.
Information 2021, 12(6), 218; https://doi.org/10.3390/info12060218
Submission received: 27 April 2021 / Revised: 17 May 2021 / Accepted: 18 May 2021 / Published: 21 May 2021
(This article belongs to the Section Information Systems)

Abstract

:
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 first, 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 significantly 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 efficiency 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.

1. 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.

2. 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 high-yield [4], high-efficiency, and the sustainable development of agriculture.

2.1. 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.

2.2. 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:
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.

3. 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 CO2 and NH3 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.

3.1. 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, I2C, 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 Bluetooth module
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 industrial-grade 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 Wi-Fi module
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.
  • Hardware Design and Implementation of the Bluetooth Gateway
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.

3.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.

3.2.1. 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 real-time 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.

3.2.2. 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.

3.2.3. 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.
1.
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, NH3 and CO2 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, NH3 and CO2 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, NH3 and CO2, 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. NH3 and CO2 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):
P = (1 − α) × PTP + α × PVP
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 NH3 and CO2 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.
2.
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.
3.
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.

4. 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.

4.1. 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.

4.2. 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.

4.3. 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:
  • 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.
  • There was a wall between the gateway and the sensor node, or the ionization shielding phenomenon caused by a metal barrier weakened the signal.
  • 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.

4.4. 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

4.5. 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.

5. 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.

Author Contributions

For this research, Y.D. and G.S. designed the concept of the research; B.Z. implemented the experimental design; Y.D. and B.Z. conducted the data analysis; Y.D. wrote the draft paper; Y.Q. reviewed and edited the whole paper; and G.S. acquired the funding. All authors have read and agreed to the published version of the manuscript.

Funding

This work was supported by the National Natural Science Foundation of China (No. 61771262), Tianjin Science and Technology Major Project and Engineering (No.18ZXRHNC00140) and Tianjin Key Laboratory of Optoelectronic Sensor and Sensor Network Technology.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Data sharing not applicable.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Chen, Q.; Yang, L.; Liu, X.; Guo, J.; Wu, S.; Chen, X. Multiple gateway placement in large-scale constellation networks with inter-satellite links. Int. J. Satell. Commun. Netw. 2021, 39, 47–64. [Google Scholar] [CrossRef]
  2. Tashiro, S.; Yoshihiro, T. Duty-cycle Communication Protocol with Wi-Fi Direct for Wireless Sensor Networks. Sens. Mater. 2021, 33, 127. [Google Scholar] [CrossRef]
  3. Ryu, S.; Park, B.B.; El-Tawab, S. WiFi Sensing System for Monitoring Public Transportation Ridership: A Case Study. KSCE J. Civ. Eng. 2020, 24, 3092–3104. [Google Scholar] [CrossRef]
  4. AlQammaz, A.; Darabkh, K.A.; Sha’ar, B.A.; Ghatasheh, O. A Framework for Artificial Intelligence Assisted Smart Agriculture Utilizing LoRaWAN Wireless Sensor Networks. In International Workshop Soft Computing Applications; Springer: Cham, Switzerland, 2018; pp. 408–421. [Google Scholar]
  5. Li, C.; Adhikari, R.; Yao, Y.; Miller, A.G.; Kalbaugh, K.; Li, D.; Nemali, K. Measuring plant growth characteristics using smartphone based image analysis technique in controlled environment agriculture. Comput. Electron. Agric. 2020, 168, 105123. [Google Scholar] [CrossRef]
  6. Zou, L. Design of reactive power optimization control for electromechanical system based on fuzzy particle swarm optimization algorithm. Microprocess. Microsyst. 2021, 82, 103865. [Google Scholar] [CrossRef]
  7. Ya, W.; Meng-Ran, Z.; Lei, N.; Jia, Z. Trust analysis of WSN nodes based on fuzzy theory. Int. J. Comput. Appl. 2017, 42, 52–56. [Google Scholar] [CrossRef]
  8. Dauxois, T.; Peacock, T.; Bauer, P.; Caulfield, C.P.; Cenedese, C.; Gorlé, C.; Haller, G.; Ivey, G.N.; Linden, P.F.; Meiburg, E.; et al. Confronting Grand Challenges in environmental fluid mechanics. Phys. Rev. Fluids 2021, 6, 020501. [Google Scholar] [CrossRef]
  9. Blazy, V.; de Guardia, A.; Benoist, J.; Daumoin, M.; Guiziou, F.; Lemasle, M.; Wolbert, D.; Barrington, S. Correlation of chemical composition and odor concentration for emissions from pig slaughterhouse sludge composting and storage. Chem. Eng. J. 2015, 276, 398–409. [Google Scholar] [CrossRef]
  10. Tang, J.; Dong, T.; Li, L.; Shao, L. Intelligent Monitoring System Based on Internet of Things. Wirel. Pers. Commun. 2018, 102, 1521–1537. [Google Scholar] [CrossRef]
  11. Guo, B.; Sun, A.; Ding, W.; Shi, Z.; Zhao, S.; Yang, H. Development and experiment of intelligent monitoring system for geese house environment. Trans. Chin. Soc. Agric. Eng. 2017, 33, 180–186. [Google Scholar]
  12. Wang, P.; Ye, F.; Chen, X. A Smart Home Gateway Platform for Data Collection and Awareness. IEEE Commun. Mag. 2018, 56, 87–93. [Google Scholar] [CrossRef] [Green Version]
  13. Chlebus, B.S.; Cholvi, V.; Kowalski, D.R. Stability of adversarial routing with feedback. Networks 2015, 66, 88–97. [Google Scholar] [CrossRef] [Green Version]
  14. Ghosh, S.; De, B.P.; Maji, K.B.; Kar, R.; Mandal, D.; Mal, A.K. Optimal Design of Ultra-Low-Power 2.4 GHz LNA for IEEE 802.15.4/Bluetooth Applications. J. Circuitssyst. Comput. 2020, 29, 2050261. [Google Scholar] [CrossRef]
  15. Guo, Y.; Lin, H.; Gao, Z.; Huang, L. Gesture Recognition System Based on Normalized Neural Network. J. Comput. 2020, 31, 274–281. [Google Scholar]
  16. Ahlawat, H.D.; Chauhan, R.P. Detection and monitoring of forest fire using serial communication and Wi-Fi wireless sensor network. In Handbook of Wireless Sensor Networks: Issues and Challenges in Current Scenario’s; Springer: Cham, Switzerland, 2020; pp. 464–492. [Google Scholar]
  17. Pan, D.; Ng, S.X.; Ruan, D.; Yin, L.; Long, G.; Hanzo, L. Simultaneous two-way classical communication and measurement-device-independent quan-tum key distribution with coherent states. Phys. Rev. A 2020, 101, 012343. [Google Scholar] [CrossRef] [Green Version]
  18. Olatinwo, S.O.; Joubert, T.H. Efficient energy resource utilization in a wireless sensor system for monitoring water quality. Eurasip. J. Wirel. Commun. Netw. 2019, 2019, 1–22. [Google Scholar] [CrossRef] [Green Version]
  19. Huang, C.; Zhuang, Y.; Liu, H.; Li, J.; Wang, W. A Performance Evaluation Framework for Direction Finding Using BLE AoA/AoD Receivers. IEEE Internet Things J. 2020, 8, 3331–3345. [Google Scholar] [CrossRef]
  20. Nomura, R.; Yagi, H. Optimum Overflow Thresholds in Variable-Length Source Coding Allowing Non-Vanishing Error Prob-ability. IEEE Trans. Inf. Theory 2019, 65, 8213–8221. [Google Scholar] [CrossRef]
  21. Spörk, M.; Boano, C.A.; Römer, K. Improving the Timeliness of Bluetooth Low Energy in Dynamic RF Environments. ACM Trans. Internet Things 2020, 1, 1–32. [Google Scholar] [CrossRef]
  22. Macedo, M.N.; Galo, J.J.; Almeida, L.A.; Lima, A.C. Methodology for the calculation of the factor of priority for smart grid im-plantation using fuzzy logic. Int. J. Electr. Power Energy Syst. 2016, 78, 563–568. [Google Scholar] [CrossRef]
  23. Matsypura, D.; Veremyev, A.; Prokopyev, O.A.; Pasiliao, E.L. On exact solution approaches for the longest induced path problem. Eur. J. Oper. Res. 2019, 278, 546–562. [Google Scholar] [CrossRef]
  24. Liu, Y.Y.; Feng, L. Stability Analysis and Stabilization for Sampled-data Systems Based on Adaptive Deadband-triggered Communication Scheme. In Proceedings of the 2019 IEEE 4th Advanced Information Technology, Electronic and Automation Control Conference (IAEAC), Chengdu, China, 20–22 December 2019; pp. 2568–2571. [Google Scholar]
  25. Mohammadzadeh, A.; Tavassoli, B.; Moaveni, B. Simultaneous estimation of state and packet-loss occurrences in networked control systems. ISA Trans. 2020, 107, 307–315. [Google Scholar] [CrossRef] [PubMed]
  26. Kindt, P.H.; Yunge, D.; Diemer, R.; Chakraborty, S. Energy modeling for the Bluetooth Low Energy protocol. ACM Trans. Embed. Comput. Syst. (TECS) 2020, 19, 1–32. [Google Scholar] [CrossRef] [Green Version]
  27. Saban, M.; Medus, L.D.; Casans, S.; Aghzout, O.; Rosado, A. Sensor Node Network for Remote Moisture Measurement in Timber Based on Bluetooth Low Energy and Web-Based Monitoring System. Sensors 2021, 21, 491. [Google Scholar] [CrossRef]
Figure 1. The overall architecture of the Bluetooth gateway system.
Figure 1. The overall architecture of the Bluetooth gateway system.
Information 12 00218 g001
Figure 2. The Bluetooth gateway PCB design and the physical diagram: (a) Bluetooth gateway PCB design drawing; (b) Bluetooth gateway physical prototype diagram.
Figure 2. The Bluetooth gateway PCB design and the physical diagram: (a) Bluetooth gateway PCB design drawing; (b) Bluetooth gateway physical prototype diagram.
Information 12 00218 g002
Figure 3. The Bluetooth gateway information transmission system function design.
Figure 3. The Bluetooth gateway information transmission system function design.
Information 12 00218 g003
Figure 4. Bluetooth master and slave connection process flow chart.
Figure 4. Bluetooth master and slave connection process flow chart.
Information 12 00218 g004
Figure 5. Data frame priority queue queuing mechanism.
Figure 5. Data frame priority queue queuing mechanism.
Information 12 00218 g005
Figure 6. Sampling frequency adaptive regulation mechanism.
Figure 6. Sampling frequency adaptive regulation mechanism.
Information 12 00218 g006
Table 1. Commercial Application Gateway Product Performance Description.
Table 1. Commercial Application Gateway Product Performance Description.
Product NameProducerFeature
Amazon Echo PlusAmazonSupports ZigBee and Wi-Fi; not compatible with Z-wave equipment, high cost.
SmartThings HubSAMSUNGSupports Wi-Fi and Z-Wave; secondary development is difficult, security loopholes.
Mijia Multifunctional GatewayXiaomiSupports Wi-Fi and ZigBee; smart accessories can still work normally when Wi-Fi is unstable or even interrupted.
SX1301 LoRa GatewaySemtechOnly supports LoRaWAN; has 1 independent transmission channel and 8 independent reception channels.
Table 2. E73-2G4M08S1C Bluetooth module performance description.
Table 2. E73-2G4M08S1C Bluetooth module performance description.
ParameterTechnical Index
Operating Voltage1.7~5.5 V
Transmit power≤6 mW (Multi-level adjustable)
Working frequency2.4 GHz
RAM256 KB
FLASH1024 KB
Communication distance(In ideal conditions) 120 m
Volume13 × 18 mm
Range of working temperature−40 °C~+85 °C
Table 3. E73-2G4M04S1B Bluetooth module performance description.
Table 3. E73-2G4M04S1B Bluetooth module performance description.
ParameterTechnical Index
Operating Voltage1.8~3.6 V
Transmit power3.8~4.3 dBm
Working frequency2.4 GHz
RAM64 KB
FLASH512 KB
Communication distance(In ideal conditions) 100 m
Volume17.5 × 28.7 mm
Range of working temperature−40 °C~+85 °C
Table 4. E103-W01 Wi-Fi module performance description.
Table 4. E103-W01 Wi-Fi module performance description.
ParameterTechnical Index
Operating Voltage3.0~3.6 V
Transmit power≤100 mW (Multi-level adjustable)
Working frequency2.4 GHz
Communication distance(In ideal conditions) 100 m
Volume13 × 18 mm
Range of working temperature-40 °C~+85 °C
Table 5. The comparative analysis of BLE and classic Bluetooth.
Table 5. The comparative analysis of BLE and classic Bluetooth.
SpecificationsBLEClassic Bluetooth
Radio frequency2.4 GHz2.4 GHz
Distance≤100 m10 m
Time required to send data<3 ms100 ms
Response delay6 msAbout 100 ms
Safety128-bit AES and user-defined application layer64/128-bit and user-defined application layer
Energy consumption0.01~0.5 W1 W
Air transmission data rate2 Mb/s1–3 Mb/s
Table 6. Packet format.
Table 6. Packet format.
Byte 0Byte 1Byte 2–3Byte 4–5
TypeIDValid dataCheck digit
Table 7. The specific meaning of each field of the Bluetooth data packet.
Table 7. The specific meaning of each field of the Bluetooth data packet.
Attribute NameAttribute Description
TypeData types are used to distinguish differentiate different sensor data
IDThe node number is used to distinguish different nodes
Valid dataThe available data collected by the sensors
Check DigitUsed to check the correctness of the packet data
Table 8. The longest communication distance test.
Table 8. The longest communication distance test.
Test GroupTest
Distance/m
Whether SucceededThe Longest Communication Distance/m
110Yes21
15Yes
20Yes
21Yes
22No
210Yes20
15Yes
20Yes
21No
22Yes
310Yes20
15Yes
20Yes
21No
22Yes
Average value 20.33
Table 9. Communication stability test.
Table 9. Communication stability test.
Test
Distance/m
Sending
Cycle/s
Test Start
Time
Test End
Time
Receivable
Data/Piece
Actual
Data/Piece
Communication
Success Rate
102015:0715:276060100%
152015:0715:276060100%
202015:0715:276060100%
Table 10. Gateway packet loss statistics.
Table 10. Gateway packet loss statistics.
IndexBreeding RoomDelivery RoomBrooding RoomGrowth Chamber
Effective time/h62886561
Receivable data packet/piece3726528011,7245856
Actually received data packet/a3681522311,5965799
Number of lost packets/piece455712857
Packet loss rate/%1.2081.0801.0920.973
Table 11. Latency test.
Table 11. Latency test.
Number of Connected SlavesPeak Latency/ms
The System Proposed in This ArticleOrdinary Bluetooth Gateway
42222
82937
104659
126995
1491118
16109145
18113153
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

Du, Y.; Sun, G.; Zheng, B.; Qu, Y. Design and Implementation of Intelligent Gateway System for Monitoring Livestock and Poultry Feeding Environment Based on Bluetooth Low Energy. Information 2021, 12, 218. https://doi.org/10.3390/info12060218

AMA Style

Du Y, Sun G, Zheng B, Qu Y. Design and Implementation of Intelligent Gateway System for Monitoring Livestock and Poultry Feeding Environment Based on Bluetooth Low Energy. Information. 2021; 12(6):218. https://doi.org/10.3390/info12060218

Chicago/Turabian Style

Du, Yawen, Guiling Sun, Bowen Zheng, and Yunlong Qu. 2021. "Design and Implementation of Intelligent Gateway System for Monitoring Livestock and Poultry Feeding Environment Based on Bluetooth Low Energy" Information 12, no. 6: 218. https://doi.org/10.3390/info12060218

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop