Internet of Things-Based Smart Farming Monitoring System for Bolting Reduction in Onion Farms

Network Systems & Security Research Group (NSSRG), Department of Computer Science & Information Technology, University of Malakand, Chakdara 18800, Dir (L), Khyber Pakhtunkhwa, Pakistan Department of Computer Science and Technology, China University of Petroleum-Beijing, Beijing 102249, China Beijing Key Lab of Petroleum Data Mining, China University of Petroleum-Beijing, Beijing 102249, China Department of Computer Science, Faculty of Science and Arts at Belgarn, University of Bisha, Sabt Al-Alaya 61985, Saudi Arabia Department of Biology, 6e University of Haripur, Haripur, Khyber Pakhtunkhwa, Pakistan Department of Information Technology, Hazara University Mansehra, Mansehra, Khyber Pakhtunkhwa, Pakistan


Introduction
e concept of the Internet of things (IoT), introduced by Kevin Ashton as a British technologist in 1999, has been proved to be one of the emerging technologies of recent times that have a slated effect on every industry and sector including the agriculture industry and farming [1]. Technically, IoT is the idea of interacting with generic objects agriculture and farming have no exception. IoT-oriented farming or smart farming is now the future with promising applications and solutions which may include farm vehicle tracking, livestock monitoring, storage monitoring, crops/ plants monitoring, and more. Smart farming promises greater efficiency, resources, and stock reduction, less human intervention, automation, data-driven processes, increased production, water conservation, real-time data and production insights and accurate farm and field evaluation, and many more.

High-Level Description.
IoT-based smart farming/agriculture is highly effective compared to traditional approaches. IoT-based smart farming is a network typically designed with sensors (light, humidity, temperature, soil moisture, etc.) to monitor the crop field and automate farming activities. e farmers are able to track the conditions in the field from anywhere. e standard IoT technology architecture has three (03) layers, i.e., perception layer, transportation layer, and application layer, as indicated in Figure 1. e perception layer is the bottom layer of IoT, consisting of RFID tags, wireless sensor network (WSN) technology, and GPS technology, which collects information/data from objects/things. e transportation layer or network layer is responsible for communicating over the Internet or other network devices and servers. Finally, the application layer acts as an interface to provide different end-user services, such as data storage, data visualization, and analysis.

Onion
Farming. Onion (Allium cepa L.) is a bulbous vegetable and a popular plant grown for its aromatic bulbs and leaves. It is one of the most valuable commodities widely used all over the world daily. Onion is native to Asia, and being a biennial vegetable, approximately 1.6 million tons of onions are produced annually in Pakistan, accounting for 2.5 percent of the global yield. Pakistan is ranked among the world's top 8th onion-producing countries [3]. Other districts of the Khyber Pakhtunkhwa province of Pakistan are also producing onion, while the Malakand division contributes 60% of the total onion production. Similarly, in Malakand Division, Swat and Dir districts are amongst the top ten onion-producing districts all over Pakistan [4]. However, the farmers of these regions are less aware of the modern techniques (e.g., monitoring and tweaking of important environmental factors such as weather, humidity, temperature, soil moisture, and CO 2 ) of farming, which greatly affect onion crop farming and production.

Onion Bolting.
e main problem associated with onion is the bolting phenomenon, which occurs due to fluctuation in temperature, humidity, and photoperiod. Onion bolting is an environmental problem associated with the formation of the flower stalk in an onion crop as shown in Figure 2. Bolting is induced by plant hormones, and due to external environmental factors, the onion plant suffers stress; hence, bolting is a survival response. e plants under stress may respond by bolting so that they can produce seeds before they die. e optimal temperature for the occurrence of onion bolting ranges from 4°C to 10°C in winter or above 30°C in summer [5]. During the starting few months of the growth of onion crops in winter, a high percentage of humidity can cause onions to bolt. While in the summer season, low humidity causes onions to bolt. Long photoperiod is the third environmental factor that causes the onion to bolt. Abnormal growing conditions make the onion think it is dying, and it sends up a flower so that it can reproduce [6]. In bolted onions, the bulbs stop growing, and onions do not fully grow. Hence, they become unsuitable for consumption and market.

Objectives and Contributions.
It is an intriguing area of active research that how smart farming techniques and IoT technology can be used to address the issue of onion bolting. Until recently, to the best of our ability, there were no IoTbased solutions found in the literature to address the issue of onion bolting monitoring and prevention, etc. Hence, there is a need for a technology-based smart farming and efficient  2 Scientific Programming monitoring system to reduce onion bolting. e contributions of this work are summarized as follows: (i) e design and development of a new IoT-based SFMS (smart farming monitoring system) prototype, based on the three-layer architecture of IoT for bolting reduction in onion farms. (ii) e proposed SFMS prototype is an indigenous, low-cost, and easy-to-install solution that is developed with locally available hardware and resources. We believe that it can transform conventional onion farming into more productive and convenient smart farming practices. is new system would help the farmer detect and identify the bolting phenomenon early and take preventive steps to stop bolting. (iii) e real test-bed implementation of SFMS prototype and its installation both in the open and in a greenhouse environment to monitor onion crops. Based on the data received from the sensors, the percentage of onion bolting was recorded 16.7% in the open environment. Similarly, the percentage of onion bolting was recorded as 3% in the closed environment. In the closed environment, optimal temperature, humidity, and photoperiod were provided to the onion crop. For this reason, the percentage of onion bolting was reduced from 16.7% to 3%, and resultantly the overall yield of the onion crop is increased. e rest of the paper is structured as follows: Section 2 consists of an overview of the most related recent work. e design and development of the proposed SFMS are presented in Section 3. Section 4 addresses the implementation of SFMS for experimental tests in actual test-bed situations, while Section 5 presents the conclusion and future work.

Related Work
e most important process of agricultural production is real-time data collection. Real-time data can be temperature, humidity, CO 2 contents, soil temperature, and moisture content. For this purpose, sensors are employed in the field of interest. ese sensors sense the environment and provide data to a remote cloud-based server. e sensed data are sent to the gateway. e gateway carries out TCP/IP packaging of the data. Moreover, this acquired data are sent through the traditional network to a cloud server. In the field of agriculture, the monitoring system receives data, analyzes it, and takes certain actions based on the received data. Using servers or cell phones, the experts in the agriculture center can control the environmental parameters in real-time [7]. Over the years, several designs and solutions have been proposed for smart agriculture based on IoT technology. We briefly review the body of related work that is available. To the best of our knowledge, in related work, there is no solution found which addresses the issue of onion bolting using IoT technology. However, IoT has been used in other related areas such as peach farming, smart irrigation, fungal detection, and apple vineyard monitoring. Each of these solutions has its specific characteristics, objectives, pros, and cons as discussed and analyzed below.

Precision Viticulture for Winegrowers in Europe.
Orozco et al. proposed a system known as "an experimental evaluation of IoT technologies in precision viticulture." ey designed a monitoring system that consists of a wireless sensor network (WSN), UAVs (unmanned aerial vehicles), and a data processing and visualization engine. e goal was to develop a system to allow winegrowers/farmers to gain access to the data being collected, and then provide a userfriendly interface to carry out statistical analysis of the data. In a real environment, based on this data, the winegrower can take corrective actions in a vineyard. However, they do not address the issue that what are the optimal environmental conditions for the better growth of grapes and how to tweak them.

Smart Irrigation Using
IoT. Khelifa et al. proposed a system named "smart irrigation using Internet of thing." In this system, sensors continuously monitor the soil moisture, water tank level, and the water well level and then send these values through a ZigBee mesh network to a smart gateway. ese data are then sent via a mobile data communication 4 G/LTE network to a web service that uses an intelligent software application to automatically analyze the data and act according to the obtained results, by selective activation of controllers as needed. Furthermore, the smart gateway also sends the received values (soil moisture values and water level values) via a mobile communication network (4G LTE) to a farmer. e farmer can check the soil moisture values and also water level in the tank and in the well with a smartphone application that connects directly to the smart gateway using HTTP or constrained application protocol (CoAP). Hence, the activation or deactivation of the electric water pump and opening and closing of solenoid valves can be controlled remotely by the farmer according to the specific needs. Contrary to the traditional irrigation system, this IoT-based system automates the irrigation process, which can save energy, water, and time. However, this system is based on simulation and has not been practically implemented.

Peach Frost Event Prediction Intelligent System.
Brun-Lagun et al. designed and developed another interesting application based on IoT technology for smart farming. In this system, sensor nodes are deployed in the peach orchard. Sensors monitor the temperature and humidity of the peach orchard. Data from the sensors are sent to the SmartMesh IP manager (gateway). e SmartMesh IP manager is connected with the local computer using USB. Specialized application software known as Sensors Object Library (SOL) manager runs on the local computer. e SOL manager forwards data to the remote SOL server. e SOL server application allows users/farmers to visualize the sensors and measurements. "Sensor Object Library" (SOL) Scientific Programming was developed to use a generic representation for the data produced by the mesh network. As the temperature drops and there is a chance of frost, a command is sent to the actuator to activate the stove. e stoves warm the environment of the peach orchard, and the inside frost is controlled because the frost event in the peach orchard prevents peach plants from producing flowers in large quantities, resulting in reducing the production of the peach fruit.

Fungal Detection
System. Truong et al. designed a fungal disease prediction and management system based on IoT technology, which is capable of sending real-time data to cloud storage. Once the data are received, a machine learning algorithm is used to predict the environment for fungal detection and prevention. Based on the prediction, it can tell that in which condition fungi will attack the crop. Certain preventive measurements can then be taken to prevent the fungal attack on the crop. Fusarium head blight (a disease caused by fungi) and wheat rust are two dangerous plant diseases that affect different crops worldwide. e spores of this kind of fungal disease are greatly influenced by environmental parameters. e environmental data and environmental predictions provided by the IoT system will help the crop field managers and farmers by facilitating better management and prevention of fungal disease spread.
is IoT system allows remote monitoring of the corps. However, they used specialized software and hardware, which may not be easily available.

The Proposed Smart Farming Monitoring System
In this section, we describe the architecture of our proposed IoT-based smart farming monitoring system (SFMS) for bolting reduction in onion farms. With the advancement of mobile and communication technologies, with the concepts of the Internet of things and with the power of cloud computing, it is possible to develop low-cost solutions and applications in smart farming. Our proposed SFMS system's architecture is made up of sensors that collect data such as temperature, air humidity, and light intensity data. e raw data are transmitted through a gateway to a cloud platform for analysis. e farmer is then informed through e-mail or Short Messaging Service (SMS) or Mobile App to take any preventive measures accordingly. Perception, network, and application layers are the three generic architecture layers of IoT, as shown in Figure 3 [8]. Real-world events are collected using various sensors, etc. at the perception layer, also known as the "sensing layer." e network layer routes data over the Internet using Wi-Fi/Bluetooth, gateways, routing and switching operations, etc. e application layer directly interacts with the end-user. Each of these layers performs specific functions and tasks with their identified services [9]. Traditional farming is based on farmers' experience only, and very little or no technology is used in traditional farming. ere are no data analysis, prediction system, and information about the environmental parameters and their effects on the growth, health, and production of the onion crop. Our motivation is to fill the gap of the use of modern technological-based solutions for better cultivation and production of onion crops and onion bolting reduction. In addition, there is no indigenous technological solution for bolting reduction in onion farms. IoT-based farming can eradicate the drawbacks of traditional farming. IoT-based solutions can improve the quantity and quality of the onion crop, reduce onion bolting, and increase production.

System Design Overview of SFMS.
e architecture of the proposed smart farming monitoring system (SFMS) is based on the abovementioned generic three-layer architecture of IoT, i.e., perception, network, and the application layer. Sensors have been deployed in the onion farm at the sensing layer of the architecture to capture various events occurring in the field. e captured data are then forwarded by the network layer to the remote cloud server where data are analyzed for making smart decisions, while data on the server-side are visualized at the application layer using the interface in real-time as illustrated in Figure 4 and explained further.
(i) Tier 1: SFMS's perception layer consists of three different types of sensor nodes to continuously monitor the environment, i.e., temperature, humidity, and light intensity sensors.
(ii) Tier 2: data from the deployed sensors to the remote web-based cloud storage server; i.e., ingSpeak is sent via the network layer of the SMFS. A Wi-Fi module acts as a gateway for sending the data. (iii) Tier 3: in Tier 3, at the application layer, a smartphone or PC/laptop has been used for accessing the stored data in the cloud server. An intelligent software application is used for visualizing the behavior in the observed data. is layer then generates an alarm message in case of any critical change that has such an effect on the environment that may result in the bolting of the crop.

System Model and Specifications of SFMS.
In this section, we explain the system model and specification with the hardware components used to build the SFMS prototype.

Arduino Nano.
It is a small-sized microcontroller that runs on the ATmega328 (Arduino Nano 3. X) platform, as shown in Figure 5 [10]. It operates similar to Arduino Duemilanove (the Arduino Duemilanove (2009) is a microcontroller board) but has different packages. It uses a Mini B USB cable and has no standard USB port.

DHT11 Humidity
Sensor. DHT11 is a basic, extremely low-cost digital temperature and air moisture sensor [11]. It uses a capacitive humidity sensor and thermistor to measure the temperature.

Light-Dependent Resistor (LDR) Sensor and BMP180
Temperature Sensor. An LDR is a component that has a variable resistor that shows the presence and absence of the light Figure 6 [12]. e BMP180 is a precision sensor that senses barometric pressure and temperature [13]. It can also be used as an altimeter. BMP180 is easy to use, and it simply connects the VIN pin to the 5V voltage pin, GND to ground, SCL to I2C Clock (Analog 5), and SDA to I2C data pin (Analog 4). Table 1 shows the technical specifications of the above sensors.

8266 Wi-Fi Module.
e ESP8266 Wi-Fi Module is a self-contained system on chip (SOC) with an integrated TCP/IP protocol stack that can give any microcontroller access to a Wi-Fi network as given in Figure 7 [14]. ese modules are mostly preprogrammed at the firmware level.

e Arduino IDE, the Sketches, and ingSpeak IoT Analytics Platform.
e Arduino Integrated Development Environment is specifically developed for programming Arduino applications. It was introduced by Arduino CC, primarily used to write, compile, and upload code into an Arduino device [15]. It can be used to program almost all Arduino modules. It is an open-source tool and is readily available to install and upload the code on the go. is environment supports both C and C++ languages, and Arduino and Genuino hardware can be connected to upload programs. According to its developers, " ingSpeak is an open-source IoT application and application programming interface (API) to store and retrieve data from things using the HTTP protocol over the Internet or via a Local Area Network. ingSpeak enables the creation of sensor logging applications, location tracking applications, and a social network of things with status updates," Figure 8.

Creation of a Channel in ingSpeak.
After the upload of the sketch, the last task in the implementation process is the creation of a channel in the ingSpeak platform [16]. Create an account in ingSpeak. After that, log in to ingSpeak using your account. After login by clicking on "My channel," an interface opens. ere is a green button named "New Channel." Upon clicking the "Create channel" button another interface opens which helps in the whole process of the channel creation, as illustrated in Figure 9.

e Final SFMS Prototype.
For the development of the final SFMS prototype, we have used the sensors as discussed above in Figure 10, and DHT11 sensor, BMP180 sensor, and the light-dependent resistor (LDR) sensor are connected with Arduino Nano Board. e ESP8266 Wi-Fi module is also connected with Arduino Nano, on a Printed Circuit Board. e sensors, Arduino Nano, and the ESP8266 are programmed through Arduino Integrated Development Environment (IDE). e Arduino IDE is installed on the computer. e computer is connected with the Arduino Nano board with the help of a USB (Universal Serial Bus) serial port. rough which, the sketch in the IDE is uploaded to the Arduino Nano. As the sketch uploads, the serial USB is removed. e sketch is developed using the Arduino IDE. e important things in the code are the SSID name of the access point, password of the access point, channel ID of ingSpeak, and the IP address of ingSpeak IoT web server. rough the access point, the sensors will communicate with the ingSpeak platform.

Deployment of the SFMS in a Real Test-Bed Environment
For the evaluation, we tested the proposed SFMS prototype in a test-bed environment. An experimental setup has been   [17]. Similarly, the Komarov Botanical Institute's Saint Petersburg Botanical Garden is Russia's oldest botanical garden. e garden was designed during the years 1823-1824 with 28 greenhouses. Every greenhouse is made up of diverse plant species. Such greenhouses aim to increase the production of different species of plants. In fact, Kew Conservatory in England is one of the world's most wellknown greenhouses. Established in 1987 by Princess Diana and housing over 30,000 species of plants, the conservatory is planned to be energy efficient and employs some passive heating and cooling design techniques to balance each climate zone [18]. Several other important benefits of the greenhouse environment are as follows: (i) Greenhouse conditions greatly improve the quality and crop yield; for example, it enables farmers to grow plants over a longer window of time.
(ii) We have the ability to tweak the physical parameters (e.g., temperature and humidity) to the optimum degree in the greenhouse setting. A greenhouse environment allows greater conditions for crop growth.

e Overall Operation of the SFMS.
e greenhouse and open environment SFMS system is composed of three sensors, namely, DHT11, BMP180, and light-dependent resistor (LDR). e deployed system is schematically shown in Figure 11. e operations of the SFMS system are described step by step as follows: (i) Step 1: sensors forward data to ESP8266, which is a Wi-Fi module. e sensors and the Wi-Fi module are attached to the Arduino Nano microcontroller. (ii) Step 2: the Wi-Fi module interacts wirelessly with the high-speed 4 G-enabled Wi-Fi access point.      Scientific Programming (iii) Step 3: the Wi-Fi access point uses 4 G technology to wirelessly forward data to a remote cloud server. (iv) Step 4: the data from the remote cloud server is accessed through the local access point using local computer/tablet/mobile. en, using the ing-Speak app, the data obtained from the sensors are visualized in real-time.
(v) Step 5: if the temperature is below the threshold value range, a tweet/message is sent to the farmer as an alert and warning that bolting is happening.
at is how SFMS provides a convenient system to monitor the greenhouse 24/7 regularly, and further data can be analyzed and visualized conveniently.

Flowchart for the Operations of SFMS.
e flowchart in Figure 12 specifies the overall operations of SFMS. When the conditions for bolting occur, the server will send a tweet to the farmer as an alert. Furthermore, when the conditions are normal the server will store the environmental parameters, i.e., the temperature, humidity, and light intensity. Similarly, with the storage of data on ingSpeak cloud server, the environmental parameters are shown in real-time for visualization purposes. e real-time data are visualized in the form of graphs. e graphs show the current as well as the previous readings taken by the sensors after every 15 minutes of the time interval. e stored data can be downloaded in CSV format for further analysis using machine learning.
Algorithms identify the favorable conditions for the occurrence of bolting and the favorable conditions for the better growth of the onion crop.
Mathematical representation of the sensor readings on ingSpeak server (T Server ) as presented in the following equation: In (1), n is the nth reading of the sensors, and Limit ⟶ 15 means that the sensors carry the reading up to nth reading after every 15 minutes, where T, H, and L are temperature, humidity, and light intensity, respectively. Likewise, dTi/dt is temperature reading, dHi/dt is humidity, reading and dLi/dt is light intensity calculation after 15 minutes.

Analysis and Discussion
is section includes a discussion about the impact and comparison of environmental parameters such as temperature, humidity, and the presence/absence of light on the planted onions inside and outside the greenhouse. Potential issues with the current system used are also examined. Once the SFMS is in place, it continuously tracks the environmental parameters and submits data to the remote cloud server at 15-minute intervals.

Monitoring Period.
We commence by studying the effect of various environmental parameters over a period of six months continuously using the SFMS for both inside and outside the environment. is period is typically the onion's crop growth time. e installed system keeps track of ambient parameters continuously 27/7. However, data are collected internally after every 15 minutes and send to the remote cloud server. is means four readings will be sent to the server in one hour. e time interval of 15 minutes was chosen on our observations that after each 10-to 20-minute time interval, a noticeable fluctuation in temperature and other parameters is detected. Technically, from the botanical standpoint, onion bolting occurs in the winter season when the temperature ranges from 4°C to 10°C, while onion bolting occurs in the summer season when the temperature increases above 30°C, respectively, as presented in Table 2.

Instances of Data in Open Environment vs. Closed
Environment. e measurements were taken at regular intervals using SFMS as explained above. With respect to temperature, we obtained 2388 total instances of temperature from the temperature sensor in a period of six months.
ese temperature records are those instances that were in the open environment within the range of 4-10°C or above 30°C; however, other insignificant instances were discarded.
is means that the bolting condition occurred 2388 times in the open environment and 83 plants: that is, 16.7 percent were found to be bolted out of 500 plants.
is bolting happened owing to the uncontrollable open environment. Moreover, data were also received after every 15-minute interval in the closed environment. During our experiment, in the greenhouse scenario, we received 200 instances of temperature. ese instances were in the range of 4 to 10°C or above 30°C. As a result, the percentage of the bolting was estimated as 3% in the closed environment (greenhouse) as given in Table 3 and Figure 13.
Similarly, in the early growth period of onion crops, a high percentage of humidity is causing onion to bolt. Furthermore, the low humidity also causes the onion to bolt in the last months of the onion production. e temperature and humidity are inversely proportional to each other, i.e. Scientific Programming lower the temperature higher will be the humidity, and vice versa. In our experiment, the percentage of humidity in the early period of the onion growth was recorded higher whereas recorded lower in the last period in the open environment. erefore, as a result, the onion bolting was recorded 16.7% in the open environment. In the greenhouse when the temperature falls below the threshold value, the stove/heater is turned on consequently, the humidity is reduced, and in the summer season, the sprinklers and exhaust fans are turned on; as a result, the humidity inside the greenhouse is increased.
us, the percentage of the onion bolting is recorded as 3% in the greenhouse showing that in the controlled environment, the bolting phenomenon is prevented and avoided.
In addition, the third environmental parameter is the calculation of photoperiod from the data obtained from the LDR sensor in the SFMS prototype. e LDR sensor indicates the presence of light as 95 k and the absence of light as 94 k from the recorded data. us, when the light falls on the LDR sensor at the beginning of the day, it shows the value of 95 k, and likewise, when the light dims and disappears in the evening, it shows the value 94 k. e time elapsed between sunrise and sunset is defined as photoperiod and is calculated based on data received from the LDR sensor; that is, the elapsed time between 95 k and 94 k is calculated as photoperiod. Various research findings have shown that photoperiod is directly proportional to the bolting of onions as shown in Table 4. is implies that the greater the photoperiod, the greater will be the risk and chance of onion bolting. In our experiment, the percentage of onion bolting is recorded 16.7% in the open environment, which is because the average photoperiod is longer which causes the onion to bolt earlier. In the greenhouse closed environment, the photoperiod in the entire period of growth is kept moderate, i.e., 8-12 hours. As a result, less percentage of onion is bolted in the greenhouse, i.e., 3%. e overall scenario and outcomes are shown.

Rear-Time Visualization of Data.
To achieve the above objectives, two sets of IoT-based SFMS prototypes were deployed, one in the open environment and the other in the greenhouse closed environment. e built-in sensors in the prototype are continuously transmitted (every 15 minutes) to the ingSpeak remote cloud server. On the ingSpeak cloud server, the environmental parameters such as temperature, humidity, and the presence/absence of light, received from the sensors, are displayed in the form of graphs for better analysis and interpretation as seen in Figure 14(a) which depicts the instances of temperature in the form of a graph received from the sensors in real-time.
is graph shows the current and previous temperature values monitored in the greenhouse. Figure 14(b) displays humidity instances in the form of a diagram on the ingSpeak cloud server in real-time. e graph shows the current as well as the previous greenhouse readings. Figure 14(c) shows the presence of light as 95 k and the absence of light as 94 k.
As demonstrated graphically in the above figures, a farmer can monitor and track the temperature and humidity in realtime continuously. When the temperature drops in the range of 4-10°C, a farmer may immediately take proactive prevention measures to increase the internal temperature of the greenhouse (e.g., putting on the stove/heater) to keep it above the threshold values (10°C) so that the chances of onion bolting are avoided. Similarly, when the temperature reaches and rises above the threshold value, i.e., the exhaust fans and sprinklers are switched on to lower the temperature below 30°C. Likewise, humidity is reduced by increasing the inner temperature in winter. Previous research statistics have shown that the chances of onion bolting would be high when the humidity is high within the first two months of onion production. Similarly, low humidity in summer increases the chances of onion bolting. In the first example, for decreasing the percentage of humidity, the temperature is increased, thereby reducing the risk of onion bolting, while in the second case, the sprinklers and exhaust fans are turned on in summer to increase the humidity and consequently reduce the chances of onion bolting.

e SFMS Alarm System.
e key idea in this paper is to use SFMS as a preventive measure to avoid onion bolting. For this purpose, a simple technique was employed. e proposed SFMS has an integrated alarm system to inform the farmer on time, in case he does not view the data in realtime. For example, if the temperature is within 4 to 10°C or above 30°C, our system will send a tweet to warn the farmer about the greenhouse conditions. Due to the regulation and security reasons of the Pakistan Telecommunication Authority (PTA), we were unable to use the GSM module to alarm the farmer via a text message; however, the alert message is sent in the form of a tweet as seen in Figure 15.  From the values obtained, SVM divided the data set into two classes (i.e., the "normal data" and "chance of bolt-in"), and the regression techniques are applied to analyze the data set as illustrated in Figure 16. e graph between time and temperature is visualized, in which the red dots show the bolt and the blue dots show normal circumstances. It is therefore   Scientific Programming concluded that the temperature has a direct relationship with the occurrence of onion bolting, and if we can regulate and control the temperature, then we can avoid and prevent onion bolting using the proposed SFMS. e major advantage of a machine learning algorithm in our experiments was to analyze the data set for monitored parameters, i.e., temperature, humidity, and light intensity. e analysis will help the farmers identify at which specific time of the season the temperature for onions remains normal and abnormal. For example, the instances of the temperature in blue color show normal conditions, i.e., the temperature lies in the range of 11-30 0 C. Similarly, the instances of temperatures in red color show abnormal conditions; that is, the temperature is more favorable for the occurrence of onion bolting. e accuracy of the data set in our experiment over the six months is 95%. In addition, the graph has the advantage of identifying which time period is best suited for bolts to carry out preventive measures to prevent bolting conditions. From the machine learning analysis, it is concluded that at midnight, it is more likely to occur bolting in onion crops.
To simplify the scenario further, we took the fluctuation of the temperature for analysis within 24 hours starting from midnight. e graph in Figure 17 shows that the temperature below the red line (i.e., 10°C) is the favorable temperature for bolting occurrence, whereas the temperature above the red line is a normal condition and the chances of bolting are very low. e graph below shows that the favorable time for the occurrence of the bolting is midnight. is graph stipulates that the farmer should take preventive measures before midnight to avoid the possibility of bolting.
Similarly, the graph between time vs. humidity was drawn using the support vector machine (SVM), a machine learning algorithm as illustrated in Figure 18. In this figure, red dots show a percentage of humidity higher than 50 percent, which is a favorable level of humidity for the occurrence of bolting, while green dots show the percentage of humidity below 50 percent, which means that bolting rarely  occurs. e use of the machine learning algorithm has the advantage of finding a correlation between time and humidity. e humidity is time-dependent, and the percentage of humidity at midday is high, which shows that in most cases, favorable humidity initiates the bolting phenomenon that occurs at midday. In addition, based on the study of the average humidity in the future, we can take preventive steps to minimize humidity and, as a result, reduce bolting graphically shown in Figure 18.
e phenomenon is further observed as illustrated in the graph in Figure 19 which shows the humidity level of the onion farm in 24 hours. e red line is at 50%, which means that this is the average percentage of humidity in the air.
Finally, the graph between temperatures with respect to time is shown in Figure 20. In the graph, the number of red points is less, which concludes that there is less chance of bolting occurrence in the greenhouse compared to the open environment. e benefit of using the machine learning algorithm is to compare the data of two environments and to analyze the instances of temperature in both environments. As the temperature instances are less than the open environment, it indicates that bolting in the closed environment  e analysis of the two environments supports our claim that bolting is reduced from 16.7% to 3% overall.

Conclusion and Future Work
e use of IoT technology in farming is commonly known as smart farming or smart agriculture. In smart farming automation, IoT collects data using sensors/RFIDs and processes the data using controllers, and completes the process of automation through actuators [3]. Due to the conventional ways of farming and the lack of use of modern technology, Pakistan is not benefiting from the agriculture sector, the way it should be. Moreover, in recent years, due to the high demand and price hikes, essential food staples such as potatoes, onions, chilies, and tomatoes have gained economic importance. Due to these reasons, Pakistan imports agricultural products from other countries [19,20]. In the Malakand Division area of Khyber Pakhtunkhwa Province of Pakistan, Swat and Dir districts are among the top ten onion-producing districts all over Pakistan [21].
However, due to fluctuations in environmental conditions in the onion field, farmers face a problem known as onion bolting or flowering. Low temperature and long photoperiod promote the initiation of flowers or bolting in onion crops. To address the above problem in onion farming, there is a need for technology-based smart farming and an efficient monitoring system to reduce onion bolting. e system should assist the farmer to early detect the bolting phenomenon and take preventive measures to avoid bolting, and consequently, onion production is increased. erefore, the SFMS was developed to reduce the onion bolting and increase the production of the onion crop. is research work can be further extended to add a prediction module to the SFMS, the second module will be used for tweaking and adjusting the greenhouse, and lastly, the SFMS will be used in poultry farms. Data Availability e data collected during the data collection phase are available from the corresponding authors upon request.

Conflicts of Interest
e authors declare that they have no conflicts of interest.