Environmental Monitoring for Cultivated Lands: Designing and Implementing IoT based Complete Prototype Model

: Precision Agriculture is recently being introduced to production as the technique of using the precise amounts of agricultural essentials like water, fertilizers, and pesticides whenever needed without harming the environment, land, and crops by excess application. Various techniques are used for precision agriculture and with the advent of Wireless Sensor Networks, it has been a strong candidate in this field as it can sense the environmental conditions around plants and accordingly help propose suggestions for better results. This study introduces IoT platform basics in the agricultural domain and accordingly proposes an IoT prototype of precision farming systems and analyzes its application to Egyptian agriculture. This prototype enables monitoring environmental parameters, improving the decision-making process for different agricultural aspects, and accordingly improving the overall agricultural process. A wireless sensor network is used as this target’s enabling technology for its advantages especially over the used technologies in this field. This study demonstrates the progressive steps done towards achieving the required objective and describes its developed system.


Introduction
The term Internet of Things (IoT) has been used widely lately in connecting things that have the capability of sensing, actuating, and communicating with each other and with other devices in the environment to share information and meanwhile trigger events, processes, and services without the mandatory intervention of humans. IoT has entered various application domains lately and helped in developing such domains to enter a new era of application and development.
Environmental Monitoring includes the activities that are done to improve the conditions surrounding a certain phenomenon to be able to control it as Environmental Data Collection, Environmental Planning and Management, Environmental Impact Assessment, Environmental Risk Detection and Management, Initial Environmental Examination, Environmental Modeling, and Mapping, Environmental Audit of Industrial Units, and spread over a range of Environmental Monitoring applications such as Environmental Pollution Monitoring, Precision Agriculture, Weather-Forecast Monitoring, etc. Precision agriculture is being widely studied in various aspects as proposed by Cui et al. (2022) and Singh and Sharma (2022).
Previous monitoring processes were run by manually collecting samples from different field points and sending it to the laboratory for further analysis and decision making. Satellite Remote Sensing techniques have been used for monitoring earth's resources, where sensors mounted on satellites that can monitor or map the broader area by utilizing images of the earth's features are used, they rely on measuring the properties of distant objects using reflected, scattered and/or emitted energy using electromagnetic radiation as a medium of interaction. In Remote Sensing techniques, continuous monitoring and mapping, both spatial and temporal, is available but only limited point measurement is possible.
With the advent of Micro-Electro-Mechanical-Systems (MEMS) ground-based monitoring; digital data acquisition systems and digital data loggers were introduced to help improve the spatial and temporal resolution of environmental monitoring. The digital data acquisition system needs to remain connected to a computer to acquire data and have a higher sampling rate than data loggers. While data loggers are tiny devices that can be distributed to collect data periodically in man unattended locations. They are composed of batteries, microcontrollers, memories, and sensing units. Shinghal and Srivastava (2017) state that Precision Agriculture (PA) or Precision Farming (PF) is defined as the technique of applying the right amount of input (water, fertilizer, pesticides, etc.) at the right location at the right time to enhance production and improve quality while protecting the environment.
Globe Newswire (2018) states that the global precision agriculture market, including hardware, software, and technologies segments, is anticipated to reach $10.55 billion by 2025. The revenue of the hardware segment was marked to be USD 2.21 billion in 2016 and thus it was the dominant segment then and is expected to remain like this until 2025 as stated in GVR (2018).
Stratistics MRC (2017) states that precision agriculture became such an important technology due to the growing rate of food consumption to efficiently use all available resources optimally with minimum wastage. Bisht et al. (2016) Farmers are becoming more enthusiastic about precision farming to get optimal usage of resources while increasing the yield dramatically, they are also enabled through PA to monitor their fields and gather information in real-time using their smartphones and computers. Also, the changes in the environmental conditions due to global warming and other effects have highly increased the demand for further advanced technologies for management. Bhutani and Wadhwani (2018) state that the stakeholders thus try to make the best advantage of these technologies to apply them in precision agriculture to be able to predict wisely future outcomes and get accurate perceptions about agricultural conditions.
IoT can use Wireless Sensor Networks (WSN) for building smart networks, a WSN is a group of sensor nodes organized in an ad hoc manner, they cooperate wirelessly to send data to an external point or network. A sensor node consists of one or more microcontrollers, different types of memories, a transceiver, a sensing unit, and a power source (batteries, solar cells, etc.). WSN is used in several applications such as environment monitoring, greenhouses, forest monitoring, and smart home applications as in El-Basioni et al. (2016), Azeem et al. (2019), Salem et al. (2019), Abdel-Hady et al. (2014) and Abd El-Kader and El-Basioni (2013). Such networks can be used in PA for environmental monitoring and controlling as shown in Fig. 1.
A lot of research addressed the use of WSN in PA, also there exists real WSN PA systems deployed all over the world; some of them are limited in their sensing modalities which may be customized only to a certain agricultural practice, and others are limited in scalability and the capability to represent and benefit from the field-collected data in different forms, some do not consider the suitability of the whole design of the sensor node to the field in which it will be deployed or do not consider two-way communications, while others do not exploit harvesting of the natural energy sources, etc. In Egypt, the available WSN PA systems are just research and prototyping efforts and there is no such system commercially available and used in a wide range, any used PA technology is imported from foreign countries.
This study introduces IoT platform basics in the agricultural domain, comparable to that of El-Basioni and Abd El-kader (2020), and accordingly proposes an IoT prototype of precision farming systems and analyzes its application in Egyptian agriculture Analyzes and exploits IoT and WSN technologies of the agricultural domain in designing and developing a PA system for remotely monitoring the environmental conditions that are important to crops, in real-time, displaying it and saving it for historical reference and analysis; through which conclusions can be deduced and automatic alarms can be produced, upon which the agricultural practices can be adjusted.
The proposed system collects several features from existing systems and adds to the new features for agricultural fields' suitability and also tries to be more generic for most agricultural applications and needs, to produce an off-the-shelf Egyptian WSN PA system. Srivastava and Singh (2010) propose an irrigation management system has been proposed for measuring the Soil Water Tension (SWT) using a humidity sensor and a low power transceiver to improve irrigation management. The monitoring device is a computer or a PDA. The collected SWT data helps determine the soil moisture to make decisions about better irrigation practices for a higher yield. The proposed model does not give a detailed design for the final product and protection proposals for sensors deployed. Zhang and Chang (2011) propose an instrument used for monitoring soil temperature and humidity. Two sets of tests were run in a closed and an open room to verify the validity of the sensed information. The proposed system has not been analyzed for actual commercial use and does not give a proposal for sensor protection in real-time application.

Related Work
The previously proposed work by Abd El-Kader and El-Basioni (2013) surveys the use of WSN in precision agriculture for cultivating potato crops in Egypt. An extensive cost analysis has been done for calculating the revenue of using precision agriculture on potatoes to use the optimal amount of essentials for a better cultivation practice to avoid all the problems that result in the loss of size of export to Russia (estimated to be 2 billion pounds annually). After calculating all expenses, it has been concluded that they can be recovered in one year. This study has been exploited in our system proposal for improving the available work in the Egyptian market.
Awasthi and Reddy (2013) proposed a system that consists of a WSN, a base station with GSM module, a device control node, and a mobile phone. The authors work in the sugarcane field. Nodes sense air temperature, soil moisture, and humidity and if any condition appears abnormal an alarm is sent to the base station which once receiving it sends an SMS to the mobile phone of the farmer through the GSM module and GSM network. The proposed model does not give a detailed design for the final product The proposed system by Bakade and Kazi (2015) consists of a sensor node that uses JN5121 module and IEEE802.15.4 zigbee wireless microcontroller. The aggregating sink node is an ARM9 and finally, they use a long-distance GPRS gateway for data transmission to a mobile device that is used for monitoring. The system does not propose a final commercial product. Anusha and Shobha (2015) propose a system for monitoring soil moisture according to a previously set level by the user. The system tries to avoid the dryness of the plant and also its over-draining. The system also monitors the level of water in the irrigating tank. Data is sent wirelessly to the gateway to be uploaded to the web for update every 5 sec. This system is mainly specified for irrigation management.
Pusatkar and Gulhane (2016) study how conventional irrigation practices affect the environment in a sugarcane field. The proposed system is a WSN that collects data and sends it through a microwave link to a backend server for further analysis. This proposal and others have been exploited as previous experiences in our proposal but with adjustments for being suitable in the Egyptian environment and market. It does not propose the end-user application for data monitoring, Syafarinda et al. (2018) test MQTT protocol on a WSN that senses temperature, humidity, and light intensity in a greenhouse using SHT 3x and TSL 2561 sensors. Authors prove that MQTT protocol works with a very small bandwidth. It has been found that it can transmit data using 4G network with a download speed of 0.02 kbps and an upload of 1.625 kbps. MQTT is the protocol used throughout this study.

IoT in the Agricultural Domain Using Wireless Sensor Networks
This section describes the architectural basics of IoT environment and WSNs for further usage and application in the agricultural domain.
Agriculture has gone through four eras according to Zhai et al. (2020), in the first era Agriculture 1.0 agriculture mainly relied on man and animal power for daily practices and although using heavy labor did not result in high productivity and the highest profitability. In the nineteenth century Agriculture, 2.0 era started with the advent of agricultural machinery and the discovery of required chemicals which helped in automating a lot of practices and activities and increasing productivity, but this came at the expense of polluting the environment and waste of natural resources. Agriculture 3.0 started in the twentieth century by adding computerization and intelligence to machinery which helped in performing operations fast and intelligent. The agriculture 4.0 era started finally with the introduction of IoT, big data, cloud computing artificial intelligence, etc. This era aims mainly on optimizing the use of natural resources, pesticides, water, and other resources while maximizing the profitability of farmers.
To build up a smart environment the basic component used is the smart objects which are sensors and actuators elements used in display and processing. Gathering a group of smart elements specific environment turns that environment into a smart one. Some definitions specify these smart objects to be sensors.
The main building blocks of IoT technology are shown in Fig. 2: (i) The lowest layer is the layer of the thing or device where sensors, actuators, and processing devices are added with low level embedded software for its management of processes, connections, and events, (ii) the second layer is the network or connectivity layer that manages the networking and communication between devices and the environment with relevant protocols, and (iii) the highest layer is the application layer which manages the high-level applications of IoT as interaction with end-users, a cloud of servers and other systems, it also manages security issues and business models.

Egy Smartfarm System
This section describes the proposed IoT framework for the agricultural domain. The system design considers, concerning its hardware and firmware, saving the nodes' energy for increasing the network operational lifetime; also, solar energy harvesting is exploited to supply the nodes with energy and charge their batteries.
Developing an IoT system is composed of several blocks to facilitate the flow of the design and choice of devices, protocols, and platforms as shown in Fig. 3.

Architecture
The proposed IoT framework for the agricultural domain consists of three tiers (Fig. 4); the field tier with the monitoring devices (sensor nodes) and a mainspowered gateway; all deployed in the monitored field. The monitoring devices sense environmental phenomena (temperature, atmospheric pressure, relative humidity, light intensity, and soil moisture), then communicate wirelessly with the gateway and send the sensed data to it which in turn sends it to the server tier/cloud tier on the Internet where data is displayed to its demanders, stored, and processed. The last tier is the user tier which is the system's user interface that facilitates the access of the end-user to the system functions by accessing a web application through web browsers, where he can display, retrieve, and analyze data, produce reports, make conclusions, and interact with the field tier and the other system users. The required design has been implemented based on the main use cases identified in Fig. 5.

Sensor Node Components
The sensor node, as illustrated in Fig. 6, consists of a wireless transceiver module connected to the microcontroller, and one or more sensors connected to the microcontroller through an on-chip or off-chip ADC. To keep accurate track of the current time, a real-time clock is connected to the microcontroller. The device is powered by an external power supply or through solar battery charging. The charging arrangement contains rechargeable battery/batteries and solar panel/panels connected to a battery charging circuit; the output voltage of the charging circuit is fed as input to a voltage regulator to produce the voltage required by the device components. An on/off switch is used for the device. For battery management, a battery sensing circuit, connected to the microcontroller, is used to determine the current drawn from the battery and its charge level. The specification of the node is shown in Table 1.

Sensor Node Design
The design process of the sensor node passed through different stages and encountered different phases of modifications to mitigate detected weaknesses until the final design was reached as follows.
PCB design stage (Fig. 7): Where the block diagram was converted to a schematic diagram of the sensor node circuit, then the schematic was used to design the PCB layout.      (Fig. 8): The PCB's Gerber files were sent to the PCB manufacturer; after manufacturing, the components were soldered on the PCB, and the node's firmware was the node hardware and software functionality testing; the test resulted in different phases of the design as follows: a) The first design: It was the initial version of the node design and it showed some drawbacks as follows:  The battery level couldn't be measured as there was a standalone circuit responsible for the battery charging and discharging processes  The dimensions of the PCB were considered big (15 × 12 cm) and design space optimization was still needed  The used voltage regulator didn't match the current need of the board b) The Second Design: In this design, all the problems in the first design were resolved as follows:  A new socket to measure the battery level during run-time and send it to the user interface for monitoring was added  The layout of the PCB was redesigned, and its dimensions were optimized such that it became 13 × 5.7 cm  Two Voltage regulators were used instead of one  New issues related to power consumption were faced in this fabrication phase as follows  In the standalone charging circuit, the charging of the Li battery from the solar panel was found to consume around 40% of the total power consumption, for example, during sleeping mode the power consumption was 17 ma after removing the charging circuit and using the battery only, the power consumption was only 10 ma  The second issue was related to the used linear regulator, as mentioned during the sleeping mode, the power consumption was 10 ma which is still high, whereas based on our design it should be about 0.1 ma when the microcontroller and the WiFi module are in deep sleep mode. The problem was in the regulator that was used to drop the voltage from 5 V "output of charger circuit" to 3.3V "operating volt"; it was found to consume alone around 8 ma, therefore it had to be changed and another type switching regulator, nonlinear, should be used  Also, some sensors didn't have a sleep mode option like the soil sensor, so it consumes power during the sleeping mode, so the power of all the sensors had to be controlled by the microcontroller to disable all of them during the sleeping mode c) The Third Design: In this design phase (Fig. 9), we solved all the issues that were found in the previous designs:  Another version of the voltage regulator specific for the battery systems with lower power consumption during idle and normal modes was used  A part was added responsibility for the battery charging in the design instead of using a standalone circuit, which enabled us to control the power consumption in an efficient way Packaging stage (Fig. 10)  In this stage, the real application of the system was considered to support the devices in protective packaging and the accessories needed for the node's coexistence with the natural environment. Also, the packaging was improved in several versions until satisfaction was reached

Sensor Node Final Implementation
The design process of the sensor node passed through different stages and encountered different phases of modifications to mitigate detected weaknesses until the final design was reached as follows.
The sensor node has a housing (Fig. 11) that contains and protects all the components. The housing has a transparent face, slots for external parts of the devices' components -for example, a slot (Fig. 11) for the cables of the soil moisture sensor and solar panel, slots for the external power source (Fig. 11), and an external on/off switch (Fig. 11). The slots are prepared with a cover made of a material that prevents water leakage. The housing is hanged by screws (Fig. 11) in the upper part of a metallic stand (Fig. 11); the stand is used to carry the whole components of the device and keeps them away from the ground and it performs three additional functions: (A) Offers a possibility to adjust the height of the device to different values to encounter barriers to the sensed phenomenon such as the light intensity and barriers to the wireless transmitted signals such as the leaves of the crops; where the vertical column (Fig.  11) is composed of two bars, one of them is hollow and has a diameter greater than the other one, the smaller diameter bar is placed inside the larger diameter bar and moves inside it up and down and it can be fastened to the outer bar at a certain length of its apparent part through a large screw (Fig. 11) with a suitable length rolled into a hole in the outer bar and two aligned holes from a number of aligned holes pairs prepared at different lengths on two opposite sides of the inner bar; (b) has the ability to be fixed on the land where it has a wide metal base (Fig.  11) can be dug into the land; (c) offers a possibility for the manual setting of the optimum tilt of the solar panel , to angle it towards the sun to get the best of the solar harvesting unit, based on the determined best adjustment method for the system deployment location (latitude and longitude) and time (twice a year, four times a year, or monthly), where the solar panel No. 1 is mounted on a metallic frame (Fig. 11) mounted to the upper part of the metallic stand by means of two screws (Fig. 11) that allow the frame to rotate around them clockwise and counter clock wise.

Sensor Node Final Implementation
After the system is powered up the node will initialize all attached sensors, then the wireless transceiver starts scanning the sensors' values. The sensed values are saved in the internal memory then the serialization of data starts which helps minimize the data size that will be transmitted to the gateway device later. It is very important to minimize the data size as it will decrease the transmission time which in return reduces the power consumption. After preparing the data "sensors readings", the transceiver module wakes up and starts communication with the gateway to report the data with the node identification. After confirming the data was successfully delivered to the gateway, the node will check if there are any configuration parameters sent from the user through the gateway, if no configuration is required, the node will go to deep sleep mode and disable all the modules to save the power. If there happens any abnormal scenario like a problem in the attached sensors or the gateway does not respond, the node will make three trials to connect to the gateway; if it failed to connect, for saving power, it will switch to the sleep mode and try again later.

The Gateway/Sink Node Design
The gateway is mains-powered and doesn't contain sensors. It is composed of a CC 3100 Simple Link WiFi Network Processor and a TM4C123MCU, it is programmed through the USB using the Code Composer Studio. CC 3100 minimizes software requirements of the host MCU by integrating all protocols for WiFi and internet. CC 3100 uses built-in security protocols that provide efficient security services. It has an 802.11 b/g/n radio, MAC with a robust engine for a fast connection with 256bit encryption, and finally a baseband. CC3100 can also be run in Station, Access Point, and WiFi Direct modes. The supported TCP/IP stack can host eight simultaneous TCP or UDP sockets and two simultaneous TLS and SSL sockets. CC 3100 also supports WPS 2.0 including embedded TCP/IP and TLS and SSL stacks, HTTP servers, and other internet protocols. It also supports WPA 2 personal and enterprise security. About its TX Power, it provides 18.0 dBm at 1 DSSS, and 14.5 dBm at 54 OFDM. The gateway is also protected by housing that has suitable openings for the power supply cable and the device programming cable. The gateway is an MQTT client that publishes the network's sensed data to the MQTT server and subscribes with it to any command related to the network to direct it to the appropriate node.

The user Interface (user Application)
The user interface is the software that implements the cloud and user tiers where the data is stored, processed, analyzed, displayed, and used for extracting results, producing reports, making conclusions, and producing alerts. It differs according to the user's role whether he is the system administrator or a normal user (e.g., farmer or agronomist).
Three main parts are constructing the user interface to the network: Backend, Database, and Dashboard: a) The backend: The backend contains the Mosca MQTT broker which uses publish/subscribe buffer service and acts as a queue to convey the published information to its subscribers. It also contains the middleware logic that processes the received information messages and stores them in the database b) The database: We used the Google product "Firebase" as the database, it provides a real-time connection between the backend, the dashboard, and charts c) The dashboard: This is the interface designed to interact with the backend. The dashboard provides functionalities based on the privileges of the user. The user can leave comments on the state of a sensor node and even send a command to it. It is implemented by HTML, CSS, Type Script and JavaScript programming languages and using the Angular web application platform

Results and Discussion
In all experiments, nodes were distributed with different schemes, readings collected, notes and observations saved and readings saved for subsequent use. The length of the crop worked on ranged from 0-30 cm in the cucumber crop field and 40-80 cm in the tomato crop field. The readings of all sensors for temperature and light intensity were identical while readings for soil moisture were different from one sensor to another which proves the standard production of sensors in the network. Solar charging in a greenhouse was found not to be not very strong enough to be relied on. Data was gathered by sensors and displayed by the user interface and alerts are shown in Fig. 12 and 13.
The following features have proved novelty for the Egyptian market.

Standardization
A new framework that conforms to the standardized format of IoT layers is being proposed in the Egyptian market which allows scalability, development and update, and compatibility with other products and devices. In the lowest layer of the IoT hierarchy defined in Fig. 2, the things or devices are defined in terms of things hardware, things software, and IoT components as illustrated extensively in the previous sections. The connectivity layer for networking has been defined to connect the IoT nodes wirelessly together in an ad hoc manner and to the gateway which through the internet routes the data to a cloud of servers. In the upper layer of the IoT hierarchy, the IoT application layer lays the decision support system with a graphical user interface that analyzes data and displays it to the user in a realtime friendly manner with the ability to configure and setup hardware specifications and receive predefined alarms for any threshold crossing values.

Cost-Effectiveness
Production of an IoT agricultural platform in the Egyptian market at a handy cost for different users in the market that accommodates the agricultural land and conditions is a novel proposal. According to Abd El-Kader and El-Basioni (2013), the cultivated land with potatoes in Egypt currently reaches about 160,000 feddan yearly. According to the proposed prototype, the cost of one sensor node would approximately be 1255 EGP and its lifetime is three years approximately. The proposed prototype covers a range of 80 to 100 m and thus according to Egyptian calculations of Kirats and feddans.
This cost concerning the yearly benefit from exporting potato crop after recovering the loss from its export preventing, after the expected consequence of increasing the yield size and quality, after the expected savings in the resources used in cultivation such as the fertilizer and irrigation water and after recovering the monetary loss results from the harms caused by excessive use of pesticides, is acceptable; it can be said that this cost can be recovered in one year, with the knowledge that Russia's decision to ban the Egyptian potato exports causes losses estimated of 2 billion pounds which is the value of the potato export to Russia annually.
The authors are working on commercializing this project to start mass production for being available in the coming years in the Egyptian market.

Energy Management
Using solar cells in the design of the charging circuit and switching between its use and battery use according to its charge level and also designing the node circuit according to energy efficiency standards minimizes the energy consumption of the framework which is one of the main challenges in WSNs and IoT.

Real-Time Solution
This framework gives a real-time framework that sends data online to the farmer or end-user through the user application as explained in the previous section. The internet problems that could be faced by systems in rural areas could be overcome by modifying the system to work in a private network without the essentiality of accessing the internet.

Scalability
The proposed framework is open in communication protocols to facilitate scalability as the cultivated land may need.

Conclusion and Future Work
This study introduces an IoT framework for the agricultural domain (Egy Smartfarm system) that seeks for improving agriculture in Egypt, solving the problems faced, and increase its revenues by developing a prototype for a precision agriculture system using wireless sensor networks technology. In the proposed system, the sensor nodes communicate with the network gateway wirelessly, and they can sense temperature, atmospheric pressure, relative humidity, light intensity, and soil moisture. The system design takes into account, respect its hardware and firmware, saving the nodes' energy for increasing the network operational lifetime; also, solar energy harvesting is exploited to supply the nodes with energy and charge their batteries. The nodes are protected with suitable housing and carried on a stand away from the land where they can be susceptible to damage and other dangers. The housing and the carrying stand are designed to be easily deployed and mounted on the land and to be suitable for harsh environments. It can bear immersion in water and overcome obstacles by easily adjusting the stand to different lengths. It can also provide easy adjustment of the solar cell to the optimum tilt to angle it towards the sun to get the best of the solar harvesting unit. The system is an IoT system, therefore its gateway sends the network data through the Internet to a server where the system's user interface resides and where the data is stored, processed, analyzed, displayed, and used for extracting results, producing reports, making conclusions and producing alerts. The interface differs according to the user's role whether he is the system administrator, the farmer or the agronomist, or the lands manager. The intellectual property of the project is saved through a patent application and copyright. Through discussion, the proposed prototype has proved to fulfill several challenges of IoT platforms in the agricultural domain.
The described Egy Smartfarm kit in this study is the version number 1.0.0 of our precision agriculture system, it is intended in the second version of the system to develop an actuator or sensor-actuator nodes to implement remote control and closed-loop control of the agricultural field and accordingly customizing the system for different cultivation types and needs for different agricultural practices.