Developing a Bluetooth Low Energy Sensor Node for Greenhouse in Precision Agriculture as Internet of Things Application

The Internet of Things (IoT) paradigm is referring to the underlying constituents of the 4th Industrial Revolution that will also affect the use of the internet in industrial production in the future. More than 50 billion smart devices will be able to communicate with each other and internet services over the increasing network capabilities of wireless sensor networks nodes on IoT applications in the next ten years. One of the leading production areas using IoT within wireless sensor networks is precision agricultural practices. In this study, a new sensor node design, which includes ambient light and temperature sensors employing Bluetooth Low Energy (BLE) communication protocol, is used as an IoT application. Subsequent to this, sensor node power consumption and management cost was investigated. The experimental results show that the developed sensor node lifetime is about 8 years and the total cost of nodes and gateway model is under $50 per year per 0.1 hectare.


INTRODUCTION
Since 1960, global grain production has increased 3.5 times, but the total surface area of grain has only increased by 30% [7,8].This increase in the amount of agricultural harvest is based on using of chemical fertilizers, resistance of crop species to diseases and climatic conditions, and machinery [20].Aside these inputs, using evolving information technologies, machinery in agriculture opens a new era in the global food industry.However, negative environmental effects of (such as conventional tillage methods on soil, underground water and genetic quality of crops) have been observed in the all over world in recent years [11].Considering the use of inputs such as fertilizers, pesticides and seeds more effectively according to soil and plant characteristics taking temporal and spatial differences into account without degrading environment is known as precision agriculture (PA) [23].
PA is the key technological concept for indoor, outdoor and greenhouse food production to feed growing human population in the future.At the end of 1990's first PA applications have begun with fertilizing optimizations [11].Before IoT applications became widespread, studies conducted on precision agriculture using remote sensing methods with Geographic Information System (GIS) and Global Positioning System (GPS) technologies in large agricultural fields.In these studies, the effective use of the in-situ nitrogen sensors was investigated according to the analysis of the existing soil feature using time-dependent geostatistics methods [22].In the methods mentioned in these studies which Instead of autonomous decision-making mechanisms, it is decided to fertilize with the help of agronomists [21].These studies on corn production have also been applied to wheat production and have been investigated for efficient use of nitrogen with local and remote sensing networks [12].In the most of precision agriculture practices, zone-based approaches used to determine soil characteristics in the geo-statistical sampling methods where the fields surveyed.In the spatial interpolation methods used to determine soil properties of fields utilized artificial neural networks [9] and site-specific management [16] methods for optimal wireless sensor nodes placement.In addition, new localized algorithms have been developed as an alternative to Kriging or Invert Distance Weighting methods to sampling existing soil characteristics [25].The use of sensor devices' own computing power and internet access has reduced the need for agronomists according to previous methods.By evaluating the obtained data with commonly accepted algorithms, farmers are able to harvest at the appropriate time and make the right decisions about their crops.
However, such as remote sensing tools like Near Infrared (NIR) Sensors which using in PA applications are more expensive for most of the farmers in developing countries.The development of wireless sensor networks and embedded devices are decreasing the economic and technological challenges in PA in recent years.At the same time, because of developing sensor technologies, suitable sensors for PA like soil PH sensors, humidity and solar radiation sensors are becoming more powerful and cheaper.The recent developments in short -range wireless communication protocols such as BLE, ZigBee etc. and evolution of the internet technologies are the fundamental components of Internet of Things paradigm.Most autonomous smart devices such as wearables, sensors, smart phones have considerable advantages such as the ability to incorporate other smart devices and low energy consumption; therefore, low-cost and energy efficient embedded sensor devices may be the key feature of Precision agriculture methods.
Studies on potential use of based on the IoT paradigm in precision agriculture applications are becoming increasingly widespread.In these studies, the energy consumption principles of BLE sensor nodes were not measured, the developed software and tools were compared with each other 's working ability and communication performances [13].Cost and energy consumption in the real world applications left as a definition at the theoretical level [18,26].
In this study, it is aimed to design and implement a system which works +8 years with Bluetooth Low Energy enabled sensor nodes in greenhouses.

Bluetooth Low Energy
As its name suggests, BLE refers to a technology designed for less energy consumption than conventional Bluetooth technology.BLE protocol stack is shown in Fig. 1.The reduction in energy consumption naturally affects the use of Bluetooth devices and their use.The BLE technology is based on the development of an adaptation under the Bluetooth Low End Extension by Nokia in 2004 [15].Then, in 2006, a low power consumption system was designed as an alternative to the Wibree protocol Bluetooth.Later, this technology joined the Bluetooth Special Interest Group (SIG) and received the name Bluetooth Low Energy [1].BLE technology is officially called Bluetooth Smart.Devices with BLE technology, in principle, are expected to work for a very long time with the batteries in the coin size.With the latest v4.2 version, Bluetooth have become even more preferred by further enhancing its Internet Protocol version 6 (IPv6) capabilities.Currently scatter-net network topology supported in BLE.By supporting the mesh network structure in the future BLE will become much more common protocol for IoT platforms [19].
Just as in conventional Bluetooth technology, the BLE radio works in the standard 2.4 GHz ISM(Industrial-Scientific-Medical) band.Similarly, in the BLE, frequency hopping methods are used to prevent interference with other devices in this frequency range.Unlike Bluetooth, the frequency band in BLE is divided into 40 channels at 2 MHz intervals.These channels range from classic Bluetooth BR / EDR (Basic Rate / Enhanced Data Rate) to 79 and 1 MHz.Communication channels in the BLE frequency band start at a frequency of 2402 MHz and numbered between 0-39 digits.Frequency values for different channels calculated according to the following formula.

𝑓𝑓(𝑘𝑘) = 2402 + 𝑘𝑘 * 2𝑀𝑀𝑀𝑀𝑀𝑀, 𝑘𝑘 = 0, … ,39
The transmit power used in the BLE is between 0.01 mW (-20 dBm) and 10 mW (10 dBm).The device to reduce power consumption and to prevent interference with other devices can change this power.BLE devices have a range of between 30 and 100 meters between these specified power values.As in Bluetooth versions prior to 4.0, BLE uses GFSK (Gaussian Filtered Frequency Shift Keying) modulation.Here, the GFSK modulation rate is fixed at 1 Mbit / s [24].The radio frequency channels used by the BLE are divided into two main physical channels called Advertising and Data physical channels.For advertisement, channels 0,12 and 39 are used.Channels are shown in Fig. 2.

Bluetooth Low Energy data packet structure
Unlike data packets (ID, NULL, POLL, FHS, DM, DV) used in Bluetooth BR / EDR technology, there is only one type of data packet in BLE.Even though the advertisement and data packets have small differences, the general structure of these packages are the same.Packet structure is shown Fig. 3.
Advertisement packets used by devices are to locate, connect, and publish other information, while data packets to carry information on an established connection.Master and slave devices use advertisements packets and data packets.Difference with advertisement and data packet is depend on which communication channels are in used.Advertisement packets serve two purposes: to publish application information to the outside world without the need for any connection, and to discover and then connect the slave devices.Each advertisement packet useful total length is 39 bytes, which includes the payload and the header field.An advertiser device, without regard to a particular target device, broadcasts this type of packets.Advertiser devices are in three advertisement channels in turn, since they do not know what frequency range the scanner devices are listening to.Advertiser devices check whether there is a device in the peripheral role in the state of a scan or initiating before each new data packet it sends.The device that made the advertisement ends this activity as soon as it sends after the advertisement packet.There are four types of advertisement packets in BLE as shown in Table 1.
The advertisement event repeats after a period defined as T_advEvent or start over a new advertisement event.Events that contain all connectable and undirected advertisement packets will trigger their activities after a specified period with the T_advEvent variable.
T_advEvent = advInterval + advDelay This variable, defined as T_advEvent, has the advInterval component between 20 ms. and 10.24 seconds that is a multiple of 0.625 μs.AdvDelay is a randomly generated value between 0 and 10 ms by the link layer.In this case, the shortest time between two advertisement events can be regarded as an average value of 30 ms [14].

Equipment
The core part of this work is the Texas Instruments (TI) CC2541 (System on Chip)SoC BLE platform where the light and temperature sensor are connected.This platform includes a 2.4-GHz RF transceiver, a built-in 8051 microcontroller, up to 256KB of in-system programmable memory, 8KB of RAM, and a full range of peripherals.TI CC2541 is one of the main products with low power consumption in the market.
The TI CC2541 platform supports two different stacks.These are Single-Device and Network Processor modes.In the Single-Device mode the controller, host, profiles, and application implemented on the TI CC2541 as a true single-chip solution.This configuration is the simplest and most common when using the TI CC2541 devices.In the other hand on Network-Processor mode GAP and GATT profiles and applications, communicate via Universal Serial Bus (USB) or Universal Asynchronous Receiver-Transmitter (UART), preferably via TI CC2541 device.This configuration is mostly suitable for use as an external microcontroller.
In this paper, Ambient Light and Temperature Sensor devices were used for light and temperature measurements.The other component that creates the device-gateway step in IoT applications is the gateway device.In general, IoT platforms are preferred with devices that have internet connection and can communicate with BLE devices.In this study, GL.iNet MT200N mini router was used as a gateway.The greatest feature of the GL.iNet mini router is its support for OpenWrt.Apart from the standard operating system components running on the device, the OpenWrt distribution can recompiled with the additional components and loaded into GL.iNet.It also has the possibility to use it as a mini computer in many ways with the Atheros processor, 64 MB RAM, USB and wireless support.When OpenWrt distribution is compiled with BlueZ (Linux Bluetooth protocol stack) [2] and PyBluez (Bluetooth Python extension module) [6], Bluetooth USB dongle devices become available on GL.iNet.With  this configuration, GL.iNet mini router becomes a Linux-based gateway device that can directly communicate with BLE sensor devices (Fig. 4).
With the Python application running on GL.iNet, the data from the BLE 4.0 dongle can sent asynchronously to the ASP.NET Web Application Program Interface (API) application via the Hypertext Transfer Protocol (HTTP), so that the data from the sensor devices can saved in a central database or in a cloud service.Average load time between web API and gateway device is 100 ms.
In this study, a sample node design consists of light and temperature sensors connected to a TI CC2541 Bluetooth SoC and a Panasonic cr2032 battery.The software configured on the TI CC2541 platform operates at the OSAL (Operating System Abstraction Layer) provided by the manufacturer.OSAL is not exactly an operating system, but it controls cycles to run tasks that are triggered in a certain order.The tasks to be executed in each cycle are grouped into HAL (Hardware Abstraction Level), HCI (Human -Computer Interaction), GAP (Generic Access Profile) and application.The GAP task use to prepare the advertisement data, the role of the BLE device, the advertisement range and the type.In this work, the GAP profile is set as the non-connectable broadcaster of the sensor node.HAL on the TI CC2451 platform provides an abstraction interface between hardware and software [3].This layer is similar to the Linux kernel driver.
According to the circuit connection details shown in Fig. 5, SoC and sensor connected to each other using (Inter-Integrated Circuit) I 2 C protocol.
The data from the sensor has been added into the advertisement packet.The 12-bit sen-sor values converted into 4-byte float values in the SoC to store decimal point values more precisely.The payload field of advertisement packets sent by the prepared sensor node is 15 bytes long.The structure of the advertisement packet is shown in Fig. 6.
An application written in python on GL.iNet that is used as a gateway, the BLE listener application instantly transmits the data coming from the sensor nodes in range to Web (Application Program Interface) API service running on the Windows 2012 server over the (Wide Area Network) WAN.The packets that arrive at the gateway from the BLE nodes are parsed according to the software revision field in the advertisement packet differ from other devices advertisement packets.The conceptual scheme of the installed system and prototype node shown in Fig. 7.

RESULTS AND CONCLUSION
In 2013, a private company by Intel Turkey office, 70% of the farmers in Turkey found that their computers are expensive and 45% of them use mobile internet frequently [10].This means that precise agriculture applications of internetbased solutions will be quite popular.
According to the TI CC2541 technical documents, SoC module consumes approximately 9500 hours of 230 mAh battery power when exchanging data with one second intervals and running continuously [17].The light and temperature sensors completes the 12-bit Light and Temperature measurement in 160 ms and consumes 0.39 mA during this process [4,5].In this study, the system was used to measure the actual power consumption values of the TI CC251 chip and the sensors depicted Fig. 8.
When sensor node device is in action, it will be in several states, such as sleeping, waking-up, sending, receiving and sleeping again.The power consumed by a sensor node during these states cannot measured by directly an ampere meter.An oscilloscope and a 10 Ω resistor has been used to measure the power consumption.During the test, the power consumption of the sensor node calculated by dividing the voltage value at the oscilloscope by 10.For instance, the current value that the sensor node during the wake-up state calculated as 200 mV / 10 Ω= 20 mA for 400 μs.The time scale of the oscilloscope used for measurement is 500 μs.Table 2 shows the measured  ering the environmental and other unexpected effects.
Another consequence is to evaluate the system in terms of cost.TI CC2541 SoC wholesale prices are currently around $3.In addition, the price of the sensor used in the study is about $19.The total price of GL.iNet and BLE dongle used as BLE gateway is around $25.The maximum communication range of BLE protocol is theoretically 100 meters.In this study one gateway and 10 sensor nodes are used in the 0.5-hectare greenhouse.Hence, cost of sensor $35.5/year per 0.1 hectare according to the formula below.IoT paradigm, as well as Big Data and Cloud computing, provide numerous benefits for the closure of agricultural information.With precision agricultural applications, the fields are rapidly transforming into intelligent and interactive areas.Today, with the sensors that place fields and greenhouses, information on fertilizer level and productivity in the soil can be obtained easily.Strategies that are generated in the light of this information are shaped in accordance with the minimum loss and maximum benefit target.Recent incentives in agriculture planned in Turkey can be considered as a good opportunity to spread precision agricultural practices.When using this study's approach, the cost of this device is below $50/year per 0.1 hectare.With such a low cost, it is a fact that precision agriculture practices will become more attractive.

Table 1 .
BLE advertisement packet types

Table 2 .
Time and current measurements of different states