Design and implementation of a low-cost IoT-based agroclimatic monitoring system for greenhouses

: Climate change is one of the main factors causing environmental variations that affect the crops in agriculture worldwide. These variations are expected to not only continue, but also to increase, putting future agricultural production and food security at risk. In this work, an agroclimatic monitoring system for greenhouses composed of three main parts: monitoring stations, a wireless communication network, and a data processing and visualization platform is proposed. The aim of this work is to provide a technological solution based on the Internet of Things (IoT) that helps the agricultural sector to avoid crop losses due to climate change. The proposed system consists of several monitoring stations inside and outside the greenhouse, with multiple sensors to measure temperature, relative humidity, soil humidity, wind speed, wind direction, precipitation, radiation, pH, and electroconductivity. The information generated by the sensors is pre-processed and temporarily stored in the LinkIt Smart 7688 Duo microcontroller. Then, this information is sent via wireless through the inbuilt Wi-Fi module of the stations to the Thinger.io platform, where the data is processed, analyzed, and presented in real time in graphical form. Authorized users have access to this platform and can visualize the collected data from any electronic device with Internet access, following


Introduction
The climate change is causing worldwide concern among scientists since unexpected variations on climatic variables are affecting the economic sector [1,2]. Agriculture is one of the most affected sectors since the growth of crops depends mainly on variables such as temperature, relative humidity, soil humidity, solar radiation, and characteristics of wind and precipitation [3]. As a result, the three main areas of food security (access, stability, and nutrition) could be affected by the impact on food production, food prices, and food purchasing capacity of the most vulnerable population. Furthermore, in the long term, climate change could also affect economic investments and the location of crops and production activities, on which many people depend [4,5].
The consequences on crop production caused by climate change vary widely from one region to another, however, developing countries in the tropical region are expected to be the most affected [6][7][8]. In Central America, for example, a very important reduction in the productivity of corn, beans, and rice is expected, which are crops that cover 90% of the production destined for domestic consumption [9]. In the Caribbean, in the case of Cuba, there would be effects on the production of rice, potatoes, tobacco, and some other crops due to the lack of suitable areas for production caused by the negative influence of saline, the increase in mean daily temperature, the impact of pests and diseases, especially fungal diseases, and the negative effects of drought [9].
Panama has also suffered various climatic events that have affected the agricultural sector and the food security of its population. For example, some of the most relevant problems observed are the variations in precipitation that modify production periods, and the variations in temperature and relative humidity that promote the spread of pests and diseases in crops. This situation has affected the food security of 52% of the rural population of the country, which depends mainly on crops such as rice, corn, and beans [10,11].
This leads us to one of the biggest challenges we face in our generation today, which is "How do we provide more sustainably grown food while increasing our crop production? A greenhouse structure is one promising solution. It provides a controlled environment customized to the vegetation needs cultivated inside. However, traditionally, agroclimatic parameters have been recorded in a rather manual and inconsistent manner. Farming practices are executed on a pre-defined speculation-based schedule, thus wasting water, energy, and using too many pesticides. Thus, based on these concerns, the ability to monitor environmental conditions of greenhouses is crucial to research since it provides valuable information to the farmers to better understand how each factor affects growth and how to maximize crop productiveness.
Motivated by this, we proposed an IoT-based environment monitoring system, which is capable of measuring temperature, relative humidity, soil humidity, pH, and electroconductivity inside a greenhouse as well as wind speed, wind direction, precipitation, and solar radiation outside of it. The

Related work
The situation mentioned above has motivated countries worldwide to focus their research projects on the development of solutions to achieve an adequate adaptation to climate change in the agricultural sector [13,14]. Due to the rapid growth of technology, there are some interesting technological solutions based on wireless communication technologies to help the crop production to avoid losses due to the unstable situation of climate change by monitoring agroclimatic variables [15,16]. In [17], the authors propose a system based on Global System for Mobile (GSM) communications and Radiofrequency (RF) technologies to remotely monitor environmental variables in small and medium-sized greenhouse. Their results show that the system is stable, reliable, and it can achieve real-time monitoring of a greenhouse environment. Another greenhouse remote monitoring system based on GSM was introduced in [18]. This system measures the levels of temperature, humidity, and CO2 inside the greenhouse in real time. The information obtained by the sensors is shown in an online platform where users can monitor the environment and control the system. Authors in [19] presented an environmental monitoring system based on ZigBee. This work presented both the hardware and software architectures, showing advantages such as low-cost, low power consumption, and self-forming. In [20], the authors designed and implemented a sugarcane growth monitoring system based on Radio Frequency Identification (RFID) and ZigBee, which effectively monitors, in real time, variables such as temperature, humidity, and crop plant height. In [21], an interesting system based on Wireless Sensor Networks (WSN) and ZigBee is proposed to remotely control variables in greenhouses. Results showed that this system is capable of monitoring parameters such as temperature, humidity, and total power consumption of the system, in real time. The authors in [22] and [23] proposed a system for agricultural monitoring based on WSN, where both terrestrial and underground networks were considered. In the terrestrial network, the system employs a Time Division Multiple Access (TDMA) technique to reduce interference and packet collisions, while improving energy efficiency. In the second network, a Carrier Sense Multiple Access (CSMA) technique was used by the system to send data from underground sensors to the data acquisition devices. In both scenarios, the system appropriately uses communication channels to avoid harmful interference during data transmission. Simulation results show that the proposed system provides satisfactory performance with respect to data transmission and power consumption, while reducing packet loss and interference.
In Latin America, interesting research projects have been also considered to help the agricultural sector. For example, the authors in [24] proposed an innovative model that improves the quality and quantity of hydroponic crops in Mexico, while facing the challenge of sustainability. This idea is based on sustainable development considering a design that integrates reliable, simple, efficient, ecological, and low-cost systems to achieve automation and control of the microenvironment in support of the daily tasks of the farmers. The application of fuzzy logic control techniques helps the greenhouse to regulate environmental variables to generate a microclimate that guarantees optimal crop development. In [25], a predictive remote-control system was presented for a greenhouse crop production in Ecuador using cloud technology. The results showed that the proposed system stabilizes the appropriate parameters for the crops, generating better conditions that were not available, while avoiding crop losses and diseases caused by high temperatures and humidity. The authors in [26] presented a review to evaluate the current situation of the agriculture in Panama and the opportunities and challenges in the study, development, and implementation of smart farming as a technological solution in the agricultural sector in this country. This work shows the importance of using solutions based on Information and Communication Technologies (ICT) to monitor and control climate variables that affect the sector.
One of the most promising solutions based on ICT is the Internet of Things (IoT), which refers to a system of interrelated, internet-connected objects that can collect and transfer data over a wireless network without human intervention [27]. The rapid development of the IoT in recent years has led to the implementation of monitoring systems based on network sensors that not only monitor the variables in real time, but also allow the processing of the data obtained in the system to provide automatic solutions to users [28]. The integration of systems based on ICT in the agricultural sector is what is known as smart farming [26,29]. The authors in [30] designed and implemented a greenhouse environment monitoring system based on a sensor network and control nodes. The environment data generated by the sensors is collected, processed, and transmitted to computer where users can view, analyze, and store the information provided by the system. In [31], a simple, low cost, Arduino-based system to monitor and control environmental parameters inside greenhouses is proposed. The idea was to implement IoT technologies to continuously monitor, update, and control agroclimatic variables, such as temperature, humidity, soil moisture, light intensity, and soil The information generated by the sensors is collected periodically by a microcontroller that sends, via wireless, the stored information to a central device, where the data is further processed and visualized through a platform with the aim to be analyzed in real time by the operator. This platform can be accessed from the central device and from any device connected to the Internet. It also allows the configuration of a series of notification services, such as emails, messages, and/or phone calls, which provide a better reaction to control any variable.

Materials and equipment
The deployment of the proposed system requires the use of materials and equipment for electrical supply, monitoring and data processing, communication, and visualization, as described in Table 1. The technical characteristics of these materials and equipment are described below.
 A 5 V power adapter to provide the electrical supply to the monitoring stations. This device converts an alternating current (AC) voltage to a constant direct current (DC) voltage by rectifying the AC voltage and then filtering it to obtain a DC level. Regulation is generally achieved with an integrated circuit voltage regulator to guarantee constant voltage level even when the input DC voltage varies, or the output load connected to the voltage varies.  The voltage protector to automatically protect equipment against voltage dips or transient overloads associated with lightning or low voltage problems in the electrical supply network. A practical on/off switch helps to reduce electricity consumption.  The MAX232 is an integrated circuit that converts the signals from an RS-232 serial port to signals compatible with the Transitor-Transistor Logic (TTL) levels of logic circuits. It also serves as a transmitting and receiving interface for receive data (RX), transmit data (TX), ready to send (CTS), and request to send (RTS) signals [33].  The LinkIt Smart 7688 Duo is an open development board compatible with Arduino, based on the OpenWrt Linux distribution, a microprocessor MT7688AN, and a controller ATmega32u4. This board provides chips for IoT applications among other electronic capabilities, such as Internet via WiFi and Ethernet modules. Its platform also offers options for creating applications in the Python, Node.js, and C programming languages [34]. To take advantage of all its functionalities and features (including its internal chips and modules), the LinkIt Smart 7688 Duo is powered with 5 V. However, it has an internal voltage regulator that converts the 5 V power supply to 3.3 V to avoid damage to some components and to guarantee an adequate operating voltage for the GPIO pins of the board.  The Real Time Clock (RTC) synchronization modules are utilized to build a time-synchronized system. In monitoring systems, this device allows the user to keep a detailed record of the time in such a way that the information can be collected knowing the instant at which it was recorded. The RTC module keeps time counting even when the system is not connected to a power source, using an internal battery.  The DHT21 is a precision digital temperature and relative humidity sensor in a robust package, which is ideal for IoT environmental applications. This device integrates a capacitive humidity sensor, a thermistor, and a microcontroller in charge of converting from analog to digital. It is calibrated at the factory to obtain calibration coefficients recorded in its One-Time-Programmable (OTP) memory, ensuring high stability and reliability over time [35].  The Odyssey Soil Moisture Sensor uses the dielectric constant measurement to determine the soil moisture content. This sensor is based on the principle that the dielectric constant of the soil undergoes important changes with the introduction of water into the soil. This is because the relative dielectric constant of dry soil is between 3 and 4, while that of water is between 80 and 85. It uses a cable that connects to a datalogger, which has a circuit with a pair of batteries (7.2 volts), a data storage memory, and an RS-232 (serial) port [36].  The SEN-08942 weather station allows to measure weather conditions such as wind speed, wind direction, and rain, to analyze the weather conditions for growing. This station is made up of a rain gauge, an anemometer, a weathervane, and a communication module. Its sensors do not have active electronic components, instead they use magnetic reed switches and sealed magnets, so they need a voltage to take any measurement [37].  The ML8511 radiation sensor is a transducer that provides a measurable electrical signal in response to optical radiation. This sensor has a photodiode that detects ultraviolet (UV) rays and an internal amplifier that converts the photo current into voltage output depending on the intensity of the UV light. Through the voltage output, it is easy to interact with external microcontrollers and analog-digital converters (ADC) [38].  The A1005 sensor consists of conductive probes that have two electrodes, to which an alternating voltage is applied to generates a current in the product. This sensor provides continuous and simultaneous monitoring of the Electroconductivity (EC) and pH of the water, providing 0 to 5 volts outputs for Arduino microprocessors, PLCs or any ADC that supports 0 to 5 volts analog [39]. To work properly with the Linkit Smart Duo (3.3 V maximum input voltage on ADCs), the sensor is connected to a buffer (single supply op amp LM358) as voltage follower and voltage divider with a pair of resistors (1.7 kΩ and 3.3 kΩ) in series to reduce the amplitude of the voltage from 5 V to 3.3 V, which guarantees an acceptable input voltage on the LinkIt Smart 7688 Duo.  The Huawei E8372 modem connects any device to the Internet, even in remote places. This modem not only works as a 4G modem, but it can also work as a WiFi router when connected to a power source [40].  The TP-LINK TL-MR3020 router expands the coverage that the Huawei modem provides by default and allows the connection of more nearby devices. This device has an USB port for the modem and a fast ethernet port to work as a local area network ( [43]. Representational State Transfer (REST) is an architecture based on web standards which uses HTTP protocol for communication, which enables interoperability among the different machines on the internet by treating each component as a resource.

System development
As aforementioned, the monitoring system proposed in this work consists of multiple internal monitoring stations, an external monitoring station, a portable monitoring station, a wireless network, and a visualization platform. The design of each component is described below. Figure 2 shows the general diagram of the internal monitoring stations, which are composed of two temperature and relative humidity sensors (S1 and S2), a soil humidity sensor (S3), an RTC module (R1), and a central unit (microcontroller). The diagram in Figure 2 shows the connections of the internal monitoring station. The central unit of this station is based on a microcontroller LinkIt Smart 7688 Duo, which collects the data from the sensors and processes it. Each internal monitoring uses DHT21 sensors (S1 and S2) to measure temperature and relative humidity, which are connected to the microcontroller using a single bus protocol, transmitting a digital signal to represent their measurements. In this communication protocol, the microcontroller acts as the master, and is, therefore, responsible for initiating communication (reading data). Each DHT21 sensor always remains as a slave and responds with data when requested by the microcontroller. When the DHT21 sensors send data, the most significant bit (MSB) is sent first. It uses a 40 data bits frame divided into 5 bytes. For the DHT21 sensor, the second, and fourth bytes are always zero. The importance of these bytes is the following:  1st byte: integral relative humidity data in % (integer part).  2nd byte: decimal relative humidity data in % (fractional part) -zero for DHT11.  3rd byte: integral temperature in degrees Celsius (integer part).  4th Byte: temperature in decimal data in % (fractional part) -zero for DHT11.  5th byte: checksum (last 8 bits of {1st byte + 2nd byte + 3rd byte + 4th byte}).

Internal monitoring stations
For the soil humidity measurements, the Odyssey sensor (S3) is considered. This sensor measures the dielectric constant of soil to determine its moisture content and the data logger records this information. This data can then be viewed as either a percentage or volumetric measurement on a graph or spreadsheet giving the user a visual representation. The procedure used for data extraction requires the use of specialized software integrated in the sensor, which allows analyzing the data that passes through the connection ports, the universal serial bus (USB), serial and communication protocol ports. In the proposed monitoring system, the sensor is connected to a microcontroller instead of a computer, therefore, it was not possible to use the software mentioned above. To solve this, an algorithm was proposed to simulate the behavior of the default sensor software and replicate it in the LinkIt 7688 Smart Duo by interrogating the sensor and displaying the data [44].
To transmit data to the microcontroller, sensor S3 uses an RS-232 communication protocol. However, the LinkIt Smart 7688 Duo cannot read the data from sensor directly, so it was necessary to use a signal converter. The station uses a converter from RS-232 signals to TTL logic levels so the data can be stored at the microcontroller and obtain their values correctly. The data generated by S1, S2, and S3 is collected periodically, according to the user's requirements.
Additionally, the internal monitoring station has a clock module R1, whose main function is to establish time records of each value from the sensors, detect power outages and, using a backup battery, immediately stored all the variables in the memory and then automatically proceeds to turn off the system until the power is restored.

External monitoring station
The external monitoring station consists of a weather station with sensors to monitor precipitation (E1), wind direction (E2), and wind speed (E3), a sensor to monitor ultraviolet radiation (US), and an RTC module (R1), that are connected to the microcontroller, as shown in Figure 3. Like the internal monitoring stations, the central unit is based on a microcontroller LinkIt Smart 7688 Duo, which collects and processes the data from the sensors. The precipitation sensor (E1) in the rain gauge is a self-emptying tipping bucket type. Each 0.011" (0.2794 mm) of rain causes one momentary contact closure that can be recorded with a digital counter or microcontroller interrupt input. The gauge's switch is connected to the two center conductors of the attached RJ11-terminated cable. The wind direction sensor (E3) uses a cup-type anemometer that measures wind speed by closing a contact as a magnet moves past a switch. A wind speed of 1.492 MPH (2.4 km/h) causes the switch to close once per second. The weather station captures the measurements from sensors E1 and E3 through interruptions associated with the digital pins on the microcontroller. Those interruptions are signals that respond to events that occur on the physical pins of the microcontroller. Among the interruptions to determine values in sensors E1 and E3, the LinkIt Smart 7688 Duo can detect the following events:  RISING, occurs on the rising edge from LOW to HIGH.
 FALLING, occurs on the falling edge from HIGH to LOW.  CHANGING, occurs when the pin changes state (rising + falling).  LOW, runs continuously while in LOW state. The sensor E2 that is part of the weathervane measures wind direction using a wind vane that has eight switches, each connected to a different resistor. The vane's magnet may close two switches at once, allowing up to 16 different positions to be indicated. Resistance values for all 16 possible positions represent a specific direction in degrees. This sensor requires the use of the 10-bit ADC converter to convert the analog signals to digital to be used by the microcontroller.
The external monitoring station also considers a sensor ML8511 (US), which produces an analog voltage that is linearly related to the UV intensity (mW/cm 2 ). The microcontroller can perform an analog voltage conversion, and therefore the level of ultraviolet light can be detected. Like the internal monitoring stations, this station also has a clock module (R1) to establish time records of the measurements and it also detects power outages and uses a backup battery and memory.

Portable monitoring station
The portable monitoring station consists of an EC sensor (S1), a pH sensor (S2), and an RTC module (R1). The general diagram is shown in Figure 4. The diagram in Figure 4 shows the general connections of the portable monitoring station. The sensor (S1) produces an analog voltage that is linearly related to the electroconductivity mS/cm. The LinkIt Smart 7688 Duo can convert analog data to voltage to determine EC levels using the map function in the microcontroller. The portable station also considers the PH DFrobot sensor to measure levels of pH in the irrigation water. Like the other monitoring stations, a clock module R1 is also used. The information from both sensors is sent to the central device based on a microcontroller LinkIt Smart 7688 Duo.
To protect electronic components that are part of internal, external, and portable monitoring stations under critical environmental scenarios, it was necessary to design Printed Circuit Board (PCB) circuits on Computer Numerical Control (CNC) machines and to print customized cases using 3D printers. Figure 5 shows the diagram of the wireless network proposed to connect the monitoring stations inside and outside the greenhouse to both the Internet and the visualization platform. The design of the wireless network considered the Internet providers, quality of the signal according to the location inside the greenhouse, and amount of data that will be generated (daily, weekly, and/or monthly). As shown in the diagram, the monitoring stations are connected to the Internet through the connection established between the network module integrated in the LinkIt Smart 7688 Duo and the WiFi access point of the local network using the IEEE 802.11b/g/n communication protocol (2.4 GHz frequency band), which provides good radio coverages signals and high data rate in presence of vegetation effects, such as attenuation, diffraction, refraction, and scattering of the signal [45,46]. This is important when a sensor network deployment for greenhouse monitoring precision is required.

Wireless network
The network router was configured in 3G/4G mode so that a local network can be created by connecting the provider's modem to the router's USB port. Also, this mode allows us to use the router's ethernet port as a WAN port. Each monitoring station manages an IP address that was reserved within the router through the MAC address (that is, the unique identifier that each manufacturer assigns to the network card of each device). This ensures that the station maintains the same IP address when attempting to reconnect during a connection loss.
The data generated by the stations is stored on the server that is included in the IoT Thinger.io platform to be subsequently analyzed by the users of the system.

Visualization platform
In recent years, solutions based on IoT have increased the use of cloud services for the collection, management, and analysis of a large amount of data generated by the system, using little computing resources and hardware. As mentioned above, this work uses the Thinger.io platform that allows the integration of Cloud, Big Data, and IoT technologies. This platform can connect and manage thousands of devices, where any manufacturer can be easily integrated with its infrastructure if it has Internet connectivity. Some popular devices compatible with Thinger.io are Arduino, Raspberry Pi, ESP8266, ESP32, LinkitOne, Texas Instruments, Libellium Waspmotes, among others [42,43].
The main characteristic of the Thinger.io platform is its ability to visualize data in real time from any device connected to the Internet. It provides tools to prototype, scale, and manage connected products in a very simple way, using basic programming skills to connect a device and start to retrieve data or control functionalities through the web platform. This platform also includes device registry, bidirectional communication, variable control for system automation, data and configuration storage, and handling of many devices at the same time, web interface to manage all the resources and generate dashboards for remote monitoring, third party webhooks, email, SMS, and push notifications [42,43].
Some interesting features of the platform for its implementation in IoT applications are:  Transmission Efficiency: It uses an optimized encoding scheme that reduces latency while sending information to the Cloud, saves bandwidth, reduces memory footprint, and saves battery by offering efficient protocols and an encoding mechanism.  Real-Time Bidirectional Communication: Thinger.io provides a bidirectional communication channel between the device and the cloud server, so any application can interact with the device in real time, increasing the number of use cases that can be developed with the platform.  Interoperability: One of the key benefits of Thinger.io is the possibility of being interoperable with other platforms and applications. That means that any device is accessible, both for sensing and actuating, from standard REST APIs, hiding the complexity of the underlying protocol optimizations between devices and the server.  Modeling Simplicity: Thinger io has the ability of modeling information in devices in an easy way. It provides client libraries that simplify modeling any kind of device resources, like input resources for actuation over the device; output resources to send information generated in the device; resources that require an input and generate an output; or execution functions that can be triggered remotely. As such, it is possible to cover multiple use cases, in a simple way, requiring just a small coding.  Storage Management: One of the features in this platform is related with the storage management, which is called "Data Buckets". A bucket is a cloud resource for storing time series data. A data bucket is a time series storage where devices can push information when required. Each data point is automatically timestamped in the cloud at reception time, as IoT devices do not handle a real-time clock (RTC) by themselves. This information is stored in the cloud in secure, efficient, and scalable solutions.
In the proposed system, the information generated by the monitoring stations is sent through the wireless network to the Thinger.io platform, where the data is processed, analyzed, and presented in real time in graphical form. Authorized users will have access to this platform and will be able to visualize the collected data from any electronic device with Internet access. This data can be exported to a computer from the database on the server for advance data processing using a data analysis software. The configuration and implementation of the Thinger.io platform in the remote monitoring system is detailed below.
Initially, the LinkIt Smart 7688 Duo microcontroller needs to be configured for Internet connection. Therefore, it is necessary to download and install the packages corresponding to the microcontroller using the preferences menu and placing the selected link for the network. Another important step is to activate the Bridge mode in the microcontroller. This is achieved through SSH (Secure SHell) to access the system console. Bridge is a library that allows the microprocessor and the microcontroller to communicate and transfer information from the microprocessor that runs Linux (OpenWrt) to the microcontroller (ATMega32U4). This Bridge library is used by the LinkIt Smart 7688 Duo to be able to access the Wi-Fi and Ethernet interface, compile console commands, among other features. Information from the microprocessor that handles Linux can also be sent to the microcontroller by accessing the system console (through SSH or the UART2 serial port).
Once the link between the system and the data visualization platform is created, it is necessary to add the devices that will be monitored. This can be done in the platform using the "Devices" menu tab, by simply clicking on the "New device" button and fill in the form with the device ID, description, and preferred credentials. This is done in a similar way for the database and the display boards, which can be customize between texts, graphics, etc., with the only difference being that a credential is not necessary.
After adding the devices on the Thinger.io cloud, they need to be configured in the Hardware (LinkIt Smart 7688 Duo) as well. In the proposed monitoring system, the internal and portable stations use the Arduino Yun libraries, compatible with the LinkIt Smart 7688 Duo microcontroller. In the external station, in the other hand, the processing is carried out in the cloud through a web server mounted on the microcontroller using PHP (a very popular open-source language especially suitable for web development). This is because this station uses a large amount of memory because of the variables it monitors, so the Thinger.io library depletes the flash memory and complicates the execution of the code.
When using a web browser, it sends a request to the server using the Hypertext Transfer Protocol (HTTP). The server receives the request and sends a response back. The browser receives this response and convert it into the results shown to the user in a visual environment. To present these results, client-side programming languages are used, such as HTML, CSS, and JavaScript, among others.

Implementation of the monitoring system
The implementation of the proposed monitoring system is described, which considers the deployment and validation of each of the monitoring stations of the greenhouse, the analysis to determine the performance of the wireless network inside the greenhouse, and the configuration of a virtual private network (VPN) for remote access to the system.

Installation and validation of the monitoring stations
Multiple monitoring stations were placed throughout 50 meters wide and 100 meters long greenhouse (that is, a total area of 5000 square meters). The stations inside the greenhouse were uniformly distributed at measuring points located at 25, 50, and 75 meters from the network equipment. At each measuring point, two internal monitoring stations were placed with a separation of 20 meters between them to measure temperature, relative humidity, and soil humidity. An external monitoring station was also implemented to measure characteristics of the wind, precipitation, and radiation. For the case of radiation, the sensor was placed inside the greenhouse to know the amount of radiation that affects the crops. Finally, a portable station to monitor the EC and pH of the irrigation water was located at the entrance of the greenhouse. This station can be moved to any part of the greenhouse so that samples can be taken and recorded every day.
An illustration of the distribution of the three types of stations is shown in Figure 7, where the internal monitoring stations, the external monitoring station, and the portable monitoring station are deployed. In each internal monitoring station, two temperature and relative humidity sensors were located at 0.5 meters and 2 meters from the ground. The soil moisture sensor was located directly in the soil, where the water from the irrigation system arrived. The central module was placed in the center of these sensors. The information from the temperature, relative humidity and soil humidity sensors was sent to the central module using CAT5 network cables. Figure 8 and Figure 9 show, respectively, the schematic diagram of the internal monitoring stations and their final deployment.  In the external monitoring station, the central module was installed inside the greenhouse to avoid damage to the equipment, while the meteorological station and its wind and rain speed/direction sensors were installed outside the structure. The radiation sensor was placed in the highest possible internal part of the greenhouse, looking for radiation values that affect the crops. The information generated by the sensors was sent to the central module using a wired network. Figure 10 presents the schematic diagram of the external monitoring stations, while Figure 11 shows the installation of the external monitoring station.  Due to the mobility characteristic of the portable monitoring station, it could be located anywhere within the greenhouse where the EC and pH variables needed to be monitored. To perform the measurements, the equipment operator must periodically take samples of the irrigation water and place them in the container where the EC and pH sensors are located. The data generated by the equipment is sent to the platform to be analyzed. Figures 12 and 13 show the schematic diagram of the portable monitoring station and an illustration of it placed at the entrance of the greenhouse, respectively.

Installation and validation of the monitoring stations
The remote monitoring network for agroclimatic variables proposed in this work uses an IoT network with wireless communication equipment for the transmission of data from the measurement stations to the visualization platform. Therefore, it is important to evaluate the performance and status of the wireless communication network of the greenhouse. The performance of the wireless communication network was evaluated inside the 5000 square meter greenhouse with melon crops. These plants were in their optimal state with a height of 2.5 meters and many fruits to harvest.
Before presenting the results from the performance evaluation, it is important to understand the signal levels used to consider a wireless connection as stable. The signal intensity's characteristics for stable and non-stable wireless connection based on the dBm, which are summarized in Table 2. Table 2. Signal levels for stable and non-stable wireless connection.

Intensity (in dBm) Characteristics
40 to -60 Ideal signal with stable transfer rates.
-60 Good signal with 80% stable connection can be achieved.
-70 Low normal link. It is a moderately good sign, although problems can occur. -80 It is the minimum acceptable signal to establish the connection.

Disconnections can occur, which result in a communication
cut-off.
The following steps were performed to evaluate the network: 1. A computer was connected to the wireless network to use the software WiFi Analyzer to perform a network performance analysis. This software allows us to know which channels and networks are being used and helped us to analyze the coverage of this network in the workspace. We also studied the performance of the two frequency bands commonly used in WiFi networks: the 2.4 GHz band and the 5 GHz band. In addition, the software generated a coverage graph to evaluate the performance and range of the different channels and networks. 2. The tests of the wireless network were carried out in a 5000 square meter greenhouse. The Internet access equipment was located inside the greenhouse administration offices, which was approximately 10 meters from the entrance to the structure. For a better analysis of the network, the greenhouse was divided into four zones, which are defined in Table 3. Here, zone A represents the closest zone to all the communication equipment. Based on the areas described above, it was considered to perform signal measurements at five points in the greenhouse: 0, 25, 50, 75 and 100 meters, which represent the limits of each one of the zones. 3. In addition to analyzing the intensity of the network, the connection between the monitoring system and the visualization platform was also verified.
The results of the evaluation of the wireless network in the different zones of the greenhouse are presented in Table 4. These results showed the network performance within each zone in the greenhouse, which improved the network design by allowing us to consider a WiFi network extender in the center of the greenhouse to improve network coverage.

-78
Low intensity levels for data transfer, which can cause transmission problems, even total loss of communication.

-82
Terrible levels of intensity for data transfer, where we can obtain total loss in communication

Configuration of a virtual private network (VPN) for remote access to the system
In addition to the intensity and quality of the wireless network, another important aspect in systems based on IoT is to guarantee remote access to the operator. To establish a remote connection with the monitoring system, we proposed to use the OpenVPN protocol, which allows handling client-server communications. Basically, this protocol helped to establish a secure tunnel between the VPN client and the VPN server.
OpenVPN uses the OpenSSL library for encryption and authentication processes. Also, OpenVPN can use either the User Datagram Protocol (UDP) or the Transmission Control Protocol (TCP) transport protocols to transmit data online. TCP is more stable as it offers error correction functions (when a network packet is sent, TCP waits for confirmation before sending it again or sending a new packet). UDP does not perform error correction, which makes it a little less stable, but it is much faster.
When accessing the local web server from the Internet, it is necessary to maintain the same fixed IP for the connection of the client and VPN server. In this work, a dynamic domain name system (DNS) redirection service known as no-IP was implemented. This service consists of the association of the public IP with a domain that the user chooses. To ensure that this domain is always associated with the public IP that we always have, a client is installed on the server used, which will be communicating the public IP from time to time.
Another step to establish the connection between the client and the VPN server is to select the transport protocol to be used within the router and the port, then proceed to generate the certificate of the service that has the OpenVPN capacity or support.
A secure VPN connection was established through providers with Hybrid Fiber-Coaxial (HFC) technology, performing tests with different remote connections through the Internet.

System operation
The designed system is based on an electronic device (Linkit Smart Duo 7688) that combines a microcontroller (ATmega32U4) and a microprocessor (MT7688). A Linux distribution based on OpenWRT is installed on the microprocessor, which allows, among other things, to connect the Linkit Smart Duo 7688 to the Internet via WIFI (802.11 b/g/n), to use different programming languages (Python, PHP, C ++, NodeJS, etc.), create databases (MySQL, SQLite, etc), store data in a microSD or USB memory, and many other useful options in the development of hardware prototypes. The microprocessor also functions as a web server, allowing data to be sent and received over the Internet through connections to remote devices.
There is a communication link between the microcontroller and the microprocessor that allows data to be transferred and certain functions to be carried out between the two units. This communication is done through the RS-232 protocol and the Bridge library that is native to the programming language used by the microcontroller. On the microprocessor side, the Bridge works by means of a Python script, which receives the information directly from the microcontroller and executes the instructions.
All three types of monitoring stations work in the same way, for which we developed our own algorithm:  There are also analog sensors, which produce a voltage signal proportional to the type of variable they read.  After that, the information generated is stored locally at the station and processed before transmitting to the visualization platform. Once the sensors are read, the sampled data, the date, and sampling time are transferred to the microprocessor, where a payload is built that includes all the information obtained from the sensors. Each station has a RTC (Real Time Clock) module that allows keeping a measuring time count.  Then, after building the payload, the information is sent to the remote server of the visualization platform through the MQTT communication protocol.  Finally, the users have access to the visualization platform to analyze the data in real time from any device connected to Internet.

Measuring agroclimatic variables
This section shows the results obtained when measuring the agroclimatic variables in the greenhouse using the IoT-based environment monitoring system proposed in this work. For simplicity, this study considers the results obtained for one month (December 2019). The data was exported from the Thinger.io platform to a computer for analysis and presentation in Microsoft Excel. Also, it is important to mention that even though a node placement technique to determine the optimal location of the sensor nodes in terms of cost and sustainability is very important, such experiments where not carried out due to time constraints. However, the fuzzy logic-based node placement approach presented in [47] can be considered in future works. Figure 14 shows the behavior of the temperatures corresponding to the selected period, where a total of 18,883 measurements were generated by the temperature sensors. It is important to mention that two measurements were considered for a better analysis, the one collected from the station located at 2 meters from the ground (red color) and the other collected from the sensor at 0.5 meters from ground (yellow color).  The measurements of the relative humidity registered by the sensors in the greenhouse are presented in Figure 15. During the period of study, a total of 18,912 measurements were generated by the inside stations. As in the previous variable, two measurements were performed, at 2 meters from the ground (blue color) and 0.5 meters from ground (orange color). Again, some maximum and minimum points were highlighted to determine the critical levels recorded during this period, where maximum and minimum relative humidity reached 99% and 30%, respectively. Figure 16 illustrates the measurements of soil humidity in the greenhouse. During December 2019, a total of 2,234 samples were collected. Notice that the maximum and minimum points are approximately 76% and 70% of soil humidity, which is acceptable to guarantee adequate conditions for the plants [48].

External monitoring station
The results of monitoring the ultraviolet radiation levels are presented in Figure 17. A total of 50,600 measurements were obtained for the period of study. Notice that the sensor registers maximum values close to 2.6 mW/cm 2 , which is a good condition for the growth of crops [49].  Figure 18 shows the graph of wind speed behavior, where a total of 49,906 measurements were registered during the period of study. These measurements were collected at 2 meters above the ground, as suggested by the farmers. Notice that there is very difficult to recognize a clear behavior, however, some good information about maximum and minimum wind speed values were obtained. This station also measures the rainfall values during the indicated period, as shown in Figure 19. In this case, a total of 65 rainfall measurements were recorded. Due to the randomness in the behavior of the variable, it was also difficult to recognize any pattern. Therefore, some points were selected to illustrate the behavior of the variable and to identify the maximum values recorded.  Table 5).   Figure 21 shows the measurements of pH in the irrigation system solution. During the period of the study, a total of 27,766 values were collected. As in the other variables, some critical points were identified to determine the maximum and minimum pH levels recorded. The maximum and minimum values were close to 7, which was the pH level desired by the farmer in the project. The levels of EC in the irrigation system solution are presented in Figure 22. A total of 28,392 measurements were generated by the station. Notice that maximum and minimum points of EC are between 1.3 and 1.9 mS/cm, which is an acceptable value for electroconductivity in irrigation system solutions [50].  Table 6 shows the performance of the monitoring system in terms of sampling time. As mentioned, the internal, external, and portable stations were configured to send the collected data at specific time intervals required by the users of the system. These data are subsequently sent to the server and viewed on the IoT visualization platform. All this process can add delay when analyzing the behavior of a variable in real time.

Discussion
With the monitoring system of agroclimatic variables within greenhouse structures, the agricultural producer is offered a new approach for the implementation of technologies in the production of food in greenhouses, to create an efficient and easy-to-use tool to know the environmental behavior within the structures. The main purpose of this system is to minimize the time and the percentage of measurement error when measuring the agroclimatic variables manually. The system proposed in this work provides reliable and real-time measurements, seen from an online platform that can be accessed from any electronic device with an Internet connection. Important results were obtained in the different tests carried out, where it was possible to establish a stable and secure communication between the measurement stations and the monitoring platform. In addition, information was collected on the different variables, allowing the generation of important indicators for food production such as minimum, maximum, average levels, and behavior patterns.
When compared with other low-cost implementations, the proposed IoT-based environment monitoring system for smart greenhouses has several distinctive advantages:  Internet of Things based agroclimatic monitoring system for greenhouses: The proposed system is based on an IoT infrastructure capturing, storing, and processing data from different sensors. The system features key components desirable in a greenhouse monitoring system: (1) a central monitoring server (Thinger.io IoT server) to receive, classify, save, and provide human machine interactions with the real-time data collected by the (2) remote monitoring stations based on agroclimatic sensors, microcontrollers, its peripheral circuits, wireless communication module and serial ports lines between them. The communication channel between the remote monitoring stations and the central device is Wi-Fi which is created using a wireless router.
 Data acquisition, storage, and monitoring: With the proposed system, agroclimatic data in any greenhouse of interest can be acquired for remote monitoring and storage. With the help of inbuilt Wi-Fi module, the data collected can be continuously uploaded to the Thinger.io platform.
We can visualize the data in the form of charts which features real-time visibility, updates, and events reporting.
 User-friendly: The main data server, that is the Thinger.io platform, where data processing and human machine interactions are carried out by the system owner is very simple and user-friendly, meaning that it requires very few customer trainings for continuous use. This is actually very important to the farmers, especially in a developing country like Panama since they are not accustomed to using technology.
 Open source, scalable, and adaptable: In the proposed solution, all the greenhouse monitoring components are manufactured and supplied by multiple vendors and are available under open-source license. The components can easily be interconnected with related components from several vendors. As such, all the system's disadvantages can be effectively addressed. It also enables the opportunity to either scale up by adding more components and adapt to different scenarios.
 Remote access: The architecture used for the development of this project has many advantages, such as the possibility of establishing remote communication with the measurement nodes through SSH, something that is possible thanks to the operating system installed on the microprocessor. This capacity allows to make firmware updates and make corrections to the algorithm of the nodes safely and without the need to go to the place where the equipment is installed. There are also enough tools to add new functionalities to the measurement nodes, such as storing data locally, in such a way that the data recording is independent of the Internet connection. It is also possible to send information via HTTPS to a remote server other than the one used for this application, which is a paid service.
 Low cost: Tables 7, 8, and 9 below show the cost of each of the components and the overall cost of the internal monitoring station, the external monitoring station, and the portable monitoring station, respectively. As can be seen, the overall cost of the designed greenhouse monitoring system with six internal monitoring stations, one external monitoring station, and one portable monitoring station is just US $2,180.00. It is indeed a low-cost greenhouse monitoring system solution compared to the available commercial solutions which are in thousands of dollars. As expected, the overall cost depends on the number of monitoring stations, the agroclimatic variables, and the sensors considered.
It is important to mention that the cost for using the Thinger.io platform depends on the number of devices connected to it and varies from US $ 0 to US $ 600 per month.   Energy efficiency: The proposed monitoring system was implemented in a greenhouse with a dedicated electrical network for its energy supply. However, on many occasions these food production structures are in remote places that do not have electrical service. Therefore, it is important to consider energy efficiency strategies that guarantee better autonomy to the system to operate properly in any type of scenario. To obtain this energy efficiency, the stations of the system were designed with low energy consumption components such as sensors, microcontrollers, LEDs, switches, communication modules, among others. In addition, the stations inside the greenhouse were located considering the coverage of the sensors, characteristics of the communication network, and requirements of the producers. This allowed not only to adequately cover the entire study area, but also to reduce the number of stations and the energy consumption of the system. The data generated by the stations was periodically sent to the data visualization and analysis platform to obtain significant information on the behavior of agri-environmental variables and reduce energy consumption. The data transfer from the sensors to the Linkit Smart Duo 7680 of the stations was carried out using the I2C protocol of wired communication, which consumes less energy compared to other wireless and wired communication alternatives.  Performance in terms of sampling time: Our analysis shows that the average, minimum, and maximum sampling times for the three stations of the proposed system present values very close to those required by the users, which is a satisfactory result for an IoT-based monitoring system.  Low power: Low energy consumption is one of the main characteristics of monitoring systems since they normally work uninterruptedly over long periods of time. For this reason, low energy consumption components were selected for the design of the low-cost IoT-based agroclimatic monitoring system, always ensuring proper operation. The energy consumption of each monitoring station (internal, external, and portable) is approximately 2W, which corresponds to 400 mA and 5 V. The components of the wireless communication network consume about 4W. The total energy consumption of the designed system with six internal monitoring stations, one external monitoring station, and one portable monitoring station, connected to a wireless communication network, is approximately 20W. As expected, this energy consumption depends on the number of monitoring stations, the wireless network, and the size of the greenhouse.
The proposed system also provides remarkable results regarding the monitoring of agroclimatic variables and their behavior. For the internal monitoring stations, the results showed that the highest temperatures were reached between 11:40 am to 1:00 pm (period of maximum radiation incidence), reaching approximate values of 50°C at 2 meters from the ground and 47 °C at 0.5 meters from the ground. On the other hand, the lowest temperatures were recorded between 5:00 am to 6:00 am, reaching 20 °C in the station located at 2 meters from the ground and 21°C in the one located at 0.5 meters from the ground. Regarding relative humidity, maximum points close to 99% were reached in the station located at 2 meters from the ground and 90% in the lower station, between 7:00 pm to 6:00 am. The lowest relative humidity values reached an approximate value of 24% in the upper station and 31% in the lower one between 11:00 am and 2:00 pm. As could be observed in the results, the behavior pattern is maintained throughout the month, which could be repeated in the other months of the year with small variations depending on the season. It can be observed that the soil moisture values recorded are from 69 to 76.8%, providing an average value of the soil moisture of 73% during the month of study. To improve these measurements, it is necessary to perform more readings and establish a relationship with the monthly irrigation schedules in the greenhouse to define a mathematical relationship that goes according to the behavior of the variable.
In the external monitoring station, the maximum UV radiation values are from 2.5 to 2.75 mW/cm 2 , which occurs between 12:00 pm to 1:30 pm. This behavior is expected because the study was carried out in a country that is close to the terrestrial equator, and therefore its highest incidence of radiation occurs around noon. On the other hand, the minimum UV radiation value registered was 0.0027 mW/cm 2 , which commonly occurs between 5:30 pm to 7:00 am. These results provide an average UV radiation value of 0.3732 mW/cm 2 during the month of study. This station also monitors characteristics of wind, specifically speed and direction. The highest values of wind speed range from 140 to 185 km/h, normally between 12:00 pm to 5:00 pm. Most of these values were detected when the wind direction went towards the north and northwest. This information is very helpful to implement protection mechanisms against affections caused by undesired wind behaviors that affect the crops and greenhouse structures. Regarding the lowest speeds, during the night the values range from 0.21 to 1 km/h.
Wind direction results were more difficult to analyze due to its randomness. The wind directions with the highest records went towards the north with 21.40% of occasions and to the northwest with 21.22% of occasions. Another variable measured in this station is the precipitation. Its average value was 0.88524 mm/h during the period of study, which corresponds to a weak intensity. This is an expected result since the study was carried out during the dry season.
For the portable monitoring station, an average pH value of 6.65 was obtained in the irrigation system solution during the study. The optimal values of pH depend on the crop that is being produced in the greenhouse. In this work, the greenhouse was being used to produce melons, which require a pH value between 5.5 to 7 [50,51]. Note that the desired ones are very close to the values obtained by our system. Regarding the electroconductivity values, the station obtained an average value of 1.61 mS/cm, which is also within the optimal ranges for adequate melon growth [50]. It is important to monitor pH and electroconductivity periodically before nutritional problems appear.
Compared to other commercial monitoring alternatives, the proposed monitoring system has a much lower development and implementation cost. Nowadays, the average cost of these commercial systems is between US $ 800 and US $ 2000 that varies according to the monitored variables, and often includes only one station to perform the measurements at a fixed point. This not only increases the cost of the system, but also reduces the monitoring coverage area, thus avoiding studying the behavior of the variables throughout the whole structure. Another difference from these commercial systems is the number of sensors and variables that can be monitored. Most of this commercial equipment have sensors to measure some common variables of interest, however, if the users need to add new variables to their study, they need to purchase additional components from specific companies that are compatible with proprietary hardware and software. As mentioned, the system proposed in this work is open source, scalable, and adaptable, which allows the acquisition and interconnection of components from multiple commercial and open-source licensed vendors.
Another advantage this open-source system is that it allows the user to create their own monitoring strategies to reduce the consumption of available resources. Commercial equipment usually has defined monitoring tasks that cannot be modified by the operator if need it, which makes it a not very flexible system for all possible existing scenarios. Finally, it is important to note that most commercial IoT monitoring systems have their own data visualization platform, which not only restricts the specific use of this platform, but also adds an additional monthly cost for the users since they need to pay if you want to make your measurements with this equipment. The agroclimatic monitoring system that we propose performs the tasks of data storage, processing, analysis, and visualization on the Thinger.io IoT platform, which is a very low-cost tool capable of connecting and managing thousands of devices very quickly. This platform is compatible with a wide variety of devices from various manufacturers, which provides the necessary flexibility for projects where there are numerous variables that are analyzed by different components. On the other hand, being an open-source system, it is possible to use other IoT platforms available on the market or develop your own IoT platform, thus allowing users to select the tool that best suits the needs of their project.

Conclusions
The proposed system provides the agricultural sector with an efficient and easy-to-use technological solution that aims to reduce crop losses due to the impact of climatic changes by applying an ICT-based system to remotely monitor agroclimatic variables that affect food production. Specifically, this work proposes a low-cost IoT-based agroclimatic monitoring system that consists of several stations located inside and outside the greenhouse, connected to an IoT platform through a wireless communication network. Each station has multiple sensors to measure temperature, relative humidity, soil humidity, wind speed, wind direction, precipitation, radiation, pH, and electroconductivity. The measurements obtained from the sensors are sent to a server through a wireless network. Finally, the information in the server is analyzed by the farmer on a visualization platform that present results in real time. With this system, any authorized user can access to the platform from any electronic device capable of connecting to the Internet.
For the development of the system, it was necessary the use of materials, equipment, and low-power consumption electronic devices for electrical supply, monitoring and data processing, communication, and visualization. For each monitoring station, it was necessary to design PCB circuits on CNC machines and print cases on 3D printers. In addition, some electronic support and dedicated interconnections were implemented according to the electronic design of the system. The overall cost in the design of the stations was low compared to some commercial monitoring systems, which allows small and medium-scale producers to implement this system. In addition, the design of these stations guarantees low energy consumption that allows their implementation in remote locations. It was also required the design of algorithms for the monitoring stations, the wireless communication modules, and the IoT platform. The implementation of the proposed system required the installation of each of the monitoring stations, the validation of the measurements obtained by the monitoring stations, the analysis to determine the performance of wireless network inside the greenhouse at different distances from the network device, and the configuration of a virtual private network (VPN) for remote access to the system. Multiple experiments were carried out by the researchers to determine the performance of the monitoring system, which provided satisfactory results.
It was observed in the results that the monitoring system was able to efficiently measure agroclimatic variables in real time, providing valuable information about the parameters that affect the crops production in greenhouses. This information not only allows the farmer to understand the agroclimatic variables inside and outside the greenhouse structures to improve the production and quality of the crops, but also allows researchers to generate indicators that could help to mitigate the impact of climate change on the agricultural sector.
The results show that most of the agroclimatic variables studied in this work have a clear behavior pattern, which contributes to detect critical situations to prevent undesired climatic variations in advance, thus guaranteeing adequate conditions and reducing losses in production.
The implementation of remote monitoring solution based on ICT in the agricultural sector minimizes the measurement time and reduces the percentage of error when measuring the agroclimatic variables in the greenhouse manually. It is also intended to benefit public and private research institutions in conducting research on the behavior and performance of greenhouses under specific weather conditions. A future extension of this work is to add an expert system that uses artificial intelligence (AI) technologies to interpret the data collected, to detect any problem, and to suggest possible solutions to the farmers. Another interesting extension would be the implementation of a control system to adequate the agroclimatic variables in greenhouses using the information obtained from the IoT-based environment monitoring system proposed in this work.
Sistema Nacional de Investigación (SNI) of Panama, for providing partial financing for the publication of this manuscript. The authors also thank the students and researchers of the research group Telecommunications Engineering and Intelligent Systems Applied to Society (ITSIAS) of the Universidad Tecnológica de Panamá for the support in the development of the project.